Browse Source

添加创建直播间时长选择逻辑

Pq 3 years ago
parent
commit
73518e74c2

BIN
BaseLibrary/src/main/res/drawable-xhdpi/icon_arrow_down.png


BIN
BaseLibrary/src/main/res/drawable-xxhdpi/icon_arrow_down.png


+ 1 - 1
teacher/src/main/java/com/cooleshow/teacher/contract/CreateLiveContract.java

@@ -14,6 +14,6 @@ public interface CreateLiveContract {
 
 
     }
     }
     interface Presenter {
     interface Presenter {
-        void createTempLive(String liveRemark,String roomTitle);
+        void createTempLive(String liveRemark,String roomTitle,String liveDuration);
     }
     }
 }
 }

+ 2 - 1
teacher/src/main/java/com/cooleshow/teacher/presenter/live/CreateLivePresenter.java

@@ -27,12 +27,13 @@ public class CreateLivePresenter extends BasePresenter<CreateLiveContract.Create
      * @param roomTitle
      * @param roomTitle
      */
      */
     @Override
     @Override
-    public void createTempLive(String liveRemark, String roomTitle) {
+    public void createTempLive(String liveRemark, String roomTitle,String liveDuration) {
         getView().showLoading();
         getView().showLoading();
         JSONObject jsonObject = new JSONObject();
         JSONObject jsonObject = new JSONObject();
         try {
         try {
             jsonObject.putOpt("liveRemark", liveRemark);
             jsonObject.putOpt("liveRemark", liveRemark);
             jsonObject.putOpt("roomTitle", roomTitle);
             jsonObject.putOpt("roomTitle", roomTitle);
+            jsonObject.putOpt("liveTime", liveDuration);
         } catch (JSONException e) {
         } catch (JSONException e) {
             e.printStackTrace();
             e.printStackTrace();
         }
         }

+ 50 - 1
teacher/src/main/java/com/cooleshow/teacher/ui/live/CreateLiveActivity.java

@@ -3,8 +3,11 @@ package com.cooleshow.teacher.ui.live;
 import android.os.Bundle;
 import android.os.Bundle;
 import android.text.TextUtils;
 import android.text.TextUtils;
 import android.view.View;
 import android.view.View;
+import android.widget.TextView;
 
 
 import com.alibaba.android.arouter.facade.annotation.Route;
 import com.alibaba.android.arouter.facade.annotation.Route;
+import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
+import com.bigkoo.pickerview.view.OptionsPickerView;
 import com.cooleshow.base.router.RouterPath;
 import com.cooleshow.base.router.RouterPath;
 import com.cooleshow.base.ui.activity.BaseMVPActivity;
 import com.cooleshow.base.ui.activity.BaseMVPActivity;
 import com.cooleshow.base.utils.ToastUtils;
 import com.cooleshow.base.utils.ToastUtils;
@@ -14,6 +17,10 @@ import com.cooleshow.teacher.contract.CreateLiveContract;
 import com.cooleshow.teacher.databinding.ActivityCreateLiveBinding;
 import com.cooleshow.teacher.databinding.ActivityCreateLiveBinding;
 import com.cooleshow.teacher.presenter.live.CreateLivePresenter;
 import com.cooleshow.teacher.presenter.live.CreateLivePresenter;
 
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 import androidx.annotation.Nullable;
 import androidx.annotation.Nullable;
 
 
 /**
 /**
@@ -24,6 +31,10 @@ import androidx.annotation.Nullable;
  */
  */
 @Route(path = RouterPath.LiveCenter.TEACHER_MINE_CREATE_COURSE)
 @Route(path = RouterPath.LiveCenter.TEACHER_MINE_CREATE_COURSE)
 public class CreateLiveActivity extends BaseMVPActivity<ActivityCreateLiveBinding, CreateLivePresenter> implements CreateLiveContract.CreateLiveView, View.OnClickListener {
 public class CreateLiveActivity extends BaseMVPActivity<ActivityCreateLiveBinding, CreateLivePresenter> implements CreateLiveContract.CreateLiveView, View.OnClickListener {
+    public static final String[] LIVE_TIMES_LIMIT = new String[]{"30", "45", "60", "90"};
+    private OptionsPickerView pvOptions;
+    private List<String> mTimes;
+    private String currentLimitTime = LIVE_TIMES_LIMIT[0];
 
 
     @Override
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
     protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -35,6 +46,14 @@ public class CreateLiveActivity extends BaseMVPActivity<ActivityCreateLiveBindin
     protected void initView() {
     protected void initView() {
         initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "创建直播");
         initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "创建直播");
         viewBinding.tvConfirm.setOnClickListener(this);
         viewBinding.tvConfirm.setOnClickListener(this);
+        viewBinding.csLiveDuration.setOnClickListener(this);
+    }
+
+    @Override
+    public void initData() {
+        super.initData();
+        mTimes = Arrays.asList(LIVE_TIMES_LIMIT);
+
     }
     }
 
 
     @Override
     @Override
@@ -61,10 +80,40 @@ public class CreateLiveActivity extends BaseMVPActivity<ActivityCreateLiveBindin
                 ToastUtils.showShort("请输入直播间内容");
                 ToastUtils.showShort("请输入直播间内容");
                 return;
                 return;
             }
             }
-            presenter.createTempLive(liveContent, liveTitle);
+            presenter.createTempLive(liveContent, liveTitle,currentLimitTime);
+            return;
+        }
+
+        if (view.getId() == R.id.cs_live_duration) {
+            showTimeSelect();
+            return;
         }
         }
     }
     }
 
 
+
+    private void showTimeSelect() {
+        if (pvOptions == null) {
+            pvOptions = new OptionsPickerBuilder(this, (options1, options2, options3, v) -> {
+                currentLimitTime = mTimes.get(options1);
+                viewBinding.tvLiveTime.setText(currentLimitTime + "分钟");
+                viewBinding.tvLiveTime.setTextColor(getResources().getColor(com.cooleshow.base.R.color.color_333333));
+            }).setLayoutRes(R.layout.pickerview_live_time_layout, v -> {
+                //自定义布局中的控件初始化及事件处理
+                final TextView tvSubmit = (TextView) v.findViewById(com.cooleshow.base.R.id.tv_finish);
+                TextView ivCancel = (TextView) v.findViewById(com.cooleshow.base.R.id.tv_cancel);
+                tvSubmit.setOnClickListener(v12 -> {
+                    pvOptions.returnData();
+                    pvOptions.dismiss();
+                });
+                ivCancel.setOnClickListener(v1 -> pvOptions.dismiss());
+
+            }).isDialog(false).build();
+        }
+        pvOptions.setPicker(mTimes);
+        pvOptions.show();
+
+    }
+
     /**
     /**
      * 创建直播间成功,返回直播间id
      * 创建直播间成功,返回直播间id
      *
      *

+ 64 - 2
teacher/src/main/res/layout/activity_create_live.xml

@@ -64,14 +64,15 @@
     </androidx.constraintlayout.widget.ConstraintLayout>
     </androidx.constraintlayout.widget.ConstraintLayout>
 
 
     <androidx.constraintlayout.widget.ConstraintLayout
     <androidx.constraintlayout.widget.ConstraintLayout
+        android:id="@+id/cs_content"
         android:layout_width="match_parent"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_height="wrap_content"
         android:layout_below="@+id/cl_title"
         android:layout_below="@+id/cl_title"
         android:layout_marginStart="14dp"
         android:layout_marginStart="14dp"
         android:layout_marginTop="15dp"
         android:layout_marginTop="15dp"
         android:layout_marginEnd="14dp"
         android:layout_marginEnd="14dp"
-        android:paddingBottom="10dp"
-        android:background="@drawable/bg_white_10dp">
+        android:background="@drawable/bg_white_10dp"
+        android:paddingBottom="10dp">
 
 
 
 
         <TextView
         <TextView
@@ -117,6 +118,67 @@
 
 
     </androidx.constraintlayout.widget.ConstraintLayout>
     </androidx.constraintlayout.widget.ConstraintLayout>
 
 
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:id="@+id/cs_live_duration"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_below="@+id/cs_content"
+        android:layout_marginStart="14dp"
+        android:layout_marginTop="15dp"
+        android:layout_marginEnd="14dp"
+        android:background="@drawable/bg_white_10dp"
+        android:paddingBottom="16dp">
+
+
+        <TextView
+            android:id="@+id/tv_star_title3"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="21dp"
+            android:layout_marginTop="20dp"
+            android:text="*"
+            android:textColor="@color/color_ff4e19"
+            android:textSize="@dimen/sp_17"
+            app:layout_constraintLeft_toLeftOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="直播时长"
+            android:textColor="@color/black"
+            android:textSize="@dimen/sp_17"
+            android:textStyle="bold"
+            app:layout_constraintBottom_toBottomOf="@+id/tv_star_title3"
+            app:layout_constraintLeft_toRightOf="@+id/tv_star_title3"
+            app:layout_constraintTop_toTopOf="@+id/tv_star_title3" />
+
+        <TextView
+            android:id="@+id/tv_live_time"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="21dp"
+            android:layout_marginTop="8dp"
+            android:gravity="left"
+            android:text="请选择直播时长"
+            android:textColor="@color/color_ffc1c1c1"
+            android:textSize="16sp"
+            app:layout_constraintLeft_toLeftOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/tv_star_title3" />
+
+
+        <ImageView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="7dp"
+            android:src="@drawable/icon_arrow_down"
+            app:layout_constraintBottom_toBottomOf="@+id/tv_live_time"
+            app:layout_constraintLeft_toRightOf="@+id/tv_live_time"
+            app:layout_constraintTop_toTopOf="@+id/tv_live_time" />
+
+    </androidx.constraintlayout.widget.ConstraintLayout>
+
+
     <TextView
     <TextView
         android:id="@+id/tv_confirm"
         android:id="@+id/tv_confirm"
         android:layout_width="match_parent"
         android:layout_width="match_parent"

+ 76 - 0
teacher/src/main/res/layout/pickerview_live_time_layout.xml

@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:background="@drawable/bg_white_top_10dp"
+    android:orientation="vertical">
+
+    <RelativeLayout
+        android:layout_width="match_parent"
+        android:layout_height="50dp">
+
+
+        <TextView
+            android:id="@+id/tv_cancel"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerVertical="true"
+            android:layout_marginLeft="17dp"
+            android:text="取消"
+            android:textColor="@color/color_999999"
+            android:textSize="@dimen/dp_16" />
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerInParent="true"
+            android:text=""
+            android:textColor="@color/color_1a1a1a"
+            android:textSize="18dp" />
+
+        <TextView
+            android:id="@+id/tv_finish"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignParentRight="true"
+            android:layout_centerVertical="true"
+            android:layout_marginRight="17dp"
+            android:padding="8dp"
+            android:text="确定"
+            android:textColor="@color/colorPrimary"
+            android:textSize="@dimen/dp_16" />
+
+    </RelativeLayout>
+
+    <View style="@style/line_style" />
+    <!--此部分需要完整复制过去,删减或者更改ID会导致初始化找不到内容而报空-->
+    <LinearLayout
+        android:id="@+id/optionspicker"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/dp_200"
+        android:background="#ffffff"
+        android:gravity="center"
+        android:minHeight="150dp"
+        android:orientation="horizontal">
+
+        <com.contrarywind.view.WheelView
+            android:id="@+id/options1"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1" />
+
+        <com.contrarywind.view.WheelView
+            android:id="@+id/options2"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1" />
+
+        <com.contrarywind.view.WheelView
+            android:id="@+id/options3"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1" />
+    </LinearLayout>
+
+
+</LinearLayout>