Sfoglia il codice sorgente

增加老师端上传个人风采视频时候上传封面逻辑

Pq 3 anni fa
parent
commit
d8fc4302a3

+ 27 - 5
teacher/src/main/java/com/cooleshow/teacher/adapter/MineStyleVideoAdapter.java

@@ -3,6 +3,8 @@ package com.cooleshow.teacher.adapter;
 import android.text.TextUtils;
 import android.view.View;
 import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
 import android.widget.TextView;
 
 import androidx.annotation.NonNull;
@@ -38,11 +40,31 @@ public class MineStyleVideoAdapter extends BaseMultiItemQuickAdapter<TeacherSelf
             case 0:
                 //加载视频缩略图
                 ImageView iv_video_bg = holder.getView(R.id.iv_video_bg);
-                if(TextUtils.isEmpty(styleVideoBean.cover)){
+                LinearLayout ll_upload_cover=holder.getView(R.id.ll_upload_cover);
+                TextView tv_upload_cover=holder.getView(R.id.tv_upload_cover);
+                ImageView iv_upload_video_cover=holder.getView(R.id.iv_upload_video_cover);
+                if (TextUtils.isEmpty(styleVideoBean.cover)) {
                     GlideUtils.INSTANCE.loadVideoThumbnail(getContext(), styleVideoBean.videoUrl, iv_video_bg);
-                }else{
-                    GlideUtils.INSTANCE.loadImage(getContext(),styleVideoBean.cover,iv_video_bg, com.cooleshow.base.R.drawable.bg_video_placeholder);
+                    tv_upload_cover.setText("请上传视频封面");
+                    tv_upload_cover.setTextColor(getContext().getResources().getColor(R.color.white));
+                    ll_upload_cover.setBackgroundResource(R.drawable.shape_2dc7aa_14dp);
+                    iv_upload_video_cover.setImageResource(R.drawable.icon_upload_video_cover);
+                } else {
+                    GlideUtils.INSTANCE.loadImage(getContext(), styleVideoBean.cover, iv_video_bg, com.cooleshow.base.R.drawable.bg_video_placeholder);
+                    tv_upload_cover.setText("更换视频封面");
+                    tv_upload_cover.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_2dc7aa));
+                    ll_upload_cover.setBackgroundResource(R.drawable.bg_select_2dc7aa_radius_14dp);
+                    iv_upload_video_cover.setImageResource(R.drawable.icon_replace_video_cover);
                 }
+                ll_upload_cover.setOnClickListener(new View.OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        if (null != itemAddClickAction) {
+                            itemAddClickAction.onUploadCover(holder.getLayoutPosition());
+                        }
+                    }
+                });
+
                 ImageView im_delete = holder.getView(R.id.im_delete);
                 im_delete.setOnClickListener(view -> {
                     if (null != itemAddClickAction) {
@@ -92,7 +114,7 @@ public class MineStyleVideoAdapter extends BaseMultiItemQuickAdapter<TeacherSelf
         void play(String videoUrl);
 
         void delete(String url);
-    }
-
 
+        void onUploadCover(int position);
+    }
 }

+ 3 - 0
teacher/src/main/java/com/cooleshow/teacher/contract/MineStylePageContract.java

@@ -15,6 +15,9 @@ public interface MineStylePageContract {
         void saveTeacherStyleSuccess(TeacherSelfStyleInfoBean styleInfoBean);
         void upLoadVideoSuccess(TeacherSelfStyleInfoBean.StyleVideoBean styleVideoBean);
         void upLoadVideoFailure();
+
+        void upLoadVideoCoverSuccess(String coverUrl);
+        void upLoadVideoCoverFail();
     }
 
     interface Presenter {

+ 51 - 0
teacher/src/main/java/com/cooleshow/teacher/presenter/minestyle/MineStylePagePresenter.java

@@ -130,6 +130,57 @@ public class MineStylePagePresenter extends BasePresenter<MineStylePageContract.
         });
     }
 
+    /**
+     * 上传视频
+     *
+     * @param activity
+     * @param videoFilePath
+     */
+    public void uploadVideo(Activity activity, String videoFilePath) {
+        TeacherSelfStyleInfoBean.StyleVideoBean styleVideoBean = new TeacherSelfStyleInfoBean.StyleVideoBean();
+        UploadHelper uploadHelper = new UploadHelper(activity, UploadConstants.UPLOAD_TYPE_OTHER);
+        uploadHelper.uploadFile(new File(videoFilePath));
+        uploadHelper.setLoadingTip("视频上传中");
+        uploadHelper.setUpLoadCallBack(new UploadHelper.UpLoadCallBack() {
+            @Override
+            public void onSuccess(String url) {
+                if (getView() != null) {
+                    styleVideoBean.videoUrl = url;
+                    styleVideoBean.type = 0;
+                    getView().upLoadVideoSuccess(styleVideoBean);
+                }
+            }
+
+            @Override
+            public void onFailure() {
+                if (getView() != null) {
+                    getView().upLoadVideoFailure();
+                }
+            }
+        });
+    }
+
+    public void uploadCover(Activity activity, String coverFilePath) {
+        UploadHelper uploadHelper = new UploadHelper(activity, UploadConstants.UPLOAD_TYPE_OTHER);
+        uploadHelper.uploadFile(new File(coverFilePath));
+        uploadHelper.setLoadingTip("封面上传中");
+        uploadHelper.setUpLoadCallBack(new UploadHelper.UpLoadCallBack() {
+            @Override
+            public void onSuccess(String url) {
+                if (getView() != null) {
+                    getView().upLoadVideoCoverSuccess(url);
+                }
+            }
+
+            @Override
+            public void onFailure() {
+                if (getView() != null) {
+                    getView().upLoadVideoCoverFail();
+                }
+            }
+        });
+    }
+
 
     public void getUploadVideoCover(Activity activity, String videoFilePath) {
         Observable.create(new ObservableOnSubscribe<String>() {

+ 111 - 24
teacher/src/main/java/com/cooleshow/teacher/ui/minestyle/MineStylePageActivity.java

@@ -23,6 +23,8 @@ import com.cooleshow.base.ui.activity.BaseMVPActivity;
 import com.cooleshow.base.ui.video.VideoPlayActivity;
 import com.cooleshow.base.utils.ActivityUtils;
 import com.cooleshow.base.utils.FileUtils;
+import com.cooleshow.base.utils.MyFileUtils;
+import com.cooleshow.base.utils.SizeUtils;
 import com.cooleshow.base.utils.ToastUtil;
 import com.cooleshow.base.utils.ToastUtils;
 import com.cooleshow.teacher.R;
@@ -33,12 +35,18 @@ import com.cooleshow.teacher.bean.TeacherSelfStyleInfoBean;
 import com.cooleshow.teacher.contract.MineStylePageContract;
 import com.cooleshow.teacher.databinding.ActivityMineStylePageBinding;
 import com.cooleshow.teacher.presenter.minestyle.MineStylePagePresenter;
+import com.cooleshow.teacher.ui.mine.PersonalSettingActivity;
+import com.daya.live_teaching.utils.GlideEngine;
 import com.google.android.flexbox.AlignItems;
 import com.google.android.flexbox.FlexDirection;
 import com.google.android.flexbox.FlexWrap;
 import com.google.android.flexbox.FlexboxLayoutManager;
 import com.google.android.flexbox.JustifyContent;
 import com.google.gson.Gson;
+import com.luck.picture.lib.PictureSelector;
+import com.luck.picture.lib.config.PictureConfig;
+import com.luck.picture.lib.config.PictureMimeType;
+import com.luck.picture.lib.entity.LocalMedia;
 import com.tbruyelle.rxpermissions3.RxPermissions;
 
 import java.io.Serializable;
@@ -57,6 +65,7 @@ import io.rong.imkit.utils.StatusBarUtil;
 public class MineStylePageActivity extends BaseMVPActivity<ActivityMineStylePageBinding, MineStylePagePresenter> implements MineStylePageContract.MineStylePageView, View.OnClickListener {
     private final int SELECT_RESULT = 1001;
     private final int CHOOSE_VIDEO = 1002;
+    public final int REQUEST_CODE_LOCAL = 0x19;
     private EditText etSelfIntroduction;
     private RecyclerView videoList;
     private MineStyleVideoAdapter mMineStyleVideoListAdapter;
@@ -64,40 +73,42 @@ public class MineStylePageActivity extends BaseMVPActivity<ActivityMineStylePage
     private TeachableSelectAdapter teachableSelectAdapter;
     private TeacherSelfStyleInfoBean myStyleInfoBean = null;
     private List<TeachableInstrumentBean> selectTeachableInstrument = new ArrayList<>();
+    private int currentUploadCoverPosition = -1;
+
 
     @Override
     public void onClick(View view) {
         switch (view.getId()) {
             case R.id.tv_select_fans:
-                Bundle bundle=new Bundle();
+                Bundle bundle = new Bundle();
                 bundle.putSerializable("selectTeachableInstrument", (Serializable) selectTeachableInstrument);
                 ARouter.getInstance().build(RouterPath.MineCenter.MINE_TEACHABLE_INSTRUMENT)
-                        .withBundle("bundle",bundle)
+                        .withBundle("bundle", bundle)
                         .navigation(this, SELECT_RESULT);
                 break;
             case R.id.tv_save:
                 Gson gson = new Gson();
                 myStyleInfoBean.styleVideo.clear();
                 for (TeacherSelfStyleInfoBean.StyleVideoBean styleVideoBean : videoBeanList) {
-                    if (styleVideoBean.type!=1){
+                    if (styleVideoBean.type != 1) {
                         myStyleInfoBean.styleVideo.add(styleVideoBean);
                     }
                 }
-                myStyleInfoBean.introduction=etSelfIntroduction.getText().toString().trim();
-                String subjectIdStr="";
-                String subjectNameStr="";
+                myStyleInfoBean.introduction = etSelfIntroduction.getText().toString().trim();
+                String subjectIdStr = "";
+                String subjectNameStr = "";
                 for (TeachableInstrumentBean teachableInstrumentBean : selectTeachableInstrument) {
-                    subjectIdStr+=","+teachableInstrumentBean.id;
-                    subjectNameStr+=","+teachableInstrumentBean.name;
+                    subjectIdStr += "," + teachableInstrumentBean.id;
+                    subjectNameStr += "," + teachableInstrumentBean.name;
                 }
-                if (subjectIdStr.startsWith(",")){
-                    subjectIdStr=   subjectIdStr.replaceFirst(",","");
+                if (subjectIdStr.startsWith(",")) {
+                    subjectIdStr = subjectIdStr.replaceFirst(",", "");
                 }
-                if (subjectNameStr.startsWith(",")){
-                    subjectNameStr=   subjectNameStr.replaceFirst(",","");
+                if (subjectNameStr.startsWith(",")) {
+                    subjectNameStr = subjectNameStr.replaceFirst(",", "");
                 }
-                myStyleInfoBean.subjectId=subjectIdStr;
-                myStyleInfoBean.subjectName=subjectNameStr;
+                myStyleInfoBean.subjectId = subjectIdStr;
+                myStyleInfoBean.subjectName = subjectNameStr;
                 presenter.saveTeacherStyle(gson.toJson(myStyleInfoBean));
                 break;
         }
@@ -154,6 +165,12 @@ public class MineStylePageActivity extends BaseMVPActivity<ActivityMineStylePage
                 }
                 mMineStyleVideoListAdapter.notifyDataSetChanged();
             }
+
+            @Override
+            public void onUploadCover(int position) {
+                currentUploadCoverPosition = position;
+                toAlbum();
+            }
         });
         rvTopSelect = viewBinding.rvTopSelect;
         //设置LayoutManager
@@ -176,6 +193,35 @@ public class MineStylePageActivity extends BaseMVPActivity<ActivityMineStylePage
         addETListener();
     }
 
+
+    private void toAlbum() {
+        new RxPermissions(this)
+                .request(Manifest.permission.CAMERA,
+                        Manifest.permission.READ_EXTERNAL_STORAGE,
+                        Manifest.permission.WRITE_EXTERNAL_STORAGE)
+                .subscribe(granted -> {
+                    if (granted) {
+                        goAlbum();
+                    } else {
+                        ToastUtil.getInstance().show(this, "请选择存储和相机权限!");
+                    }
+                });
+    }
+
+    private void goAlbum() {
+        PictureSelector.create(this)
+                .openGallery(PictureMimeType.ofImage())//全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
+                .loadImageEngine(GlideEngine.createGlideEngine())
+                .theme(com.cooleshow.base.R.style.picture_daya_style)// 主题样式设置 具体参考 values/styles   用法:R .style.picture.white.style
+                .selectionMode(PictureConfig.SINGLE)// 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE
+                .enableCrop(true)// 是否裁剪 true or false
+                .cropImageWideHigh(SizeUtils.dp2px(157),SizeUtils.dp2px(106))
+                .showCropGrid(false)// 是否显示裁剪矩形网格 圆形裁剪时建议设为false    true or false
+                .compress(true)// 是否压缩 true or false
+                .circleDimmedLayer(false)// 是否圆形裁剪 true or false
+                .forResult(REQUEST_CODE_LOCAL);
+    }
+
     private void addETListener() {
         etSelfIntroduction.addTextChangedListener(new TextWatcher() {
             @Override
@@ -218,20 +264,20 @@ public class MineStylePageActivity extends BaseMVPActivity<ActivityMineStylePage
             addEmptyVideoBean();
             mMineStyleVideoListAdapter.notifyDataSetChanged();
         }
-        if (!TextUtils.isEmpty(styleInfoBean.subjectId)){
-            if (styleInfoBean.subjectId.contains(",")){
+        if (!TextUtils.isEmpty(styleInfoBean.subjectId)) {
+            if (styleInfoBean.subjectId.contains(",")) {
                 String[] splitId = styleInfoBean.subjectId.split(",");
                 String[] splitName = styleInfoBean.subjectName.split(",");
                 for (int i = 0; i < splitId.length; i++) {
-                    TeachableInstrumentBean instrumentBean=new TeachableInstrumentBean();
-                    instrumentBean.id=Integer.parseInt(splitId[i]);
-                    instrumentBean.name=splitName[i];
+                    TeachableInstrumentBean instrumentBean = new TeachableInstrumentBean();
+                    instrumentBean.id = Integer.parseInt(splitId[i]);
+                    instrumentBean.name = splitName[i];
                     selectTeachableInstrument.add(instrumentBean);
                 }
-            }else{
-                TeachableInstrumentBean instrumentBean=new TeachableInstrumentBean();
-                instrumentBean.id=Integer.parseInt(styleInfoBean.subjectId);
-                instrumentBean.name=styleInfoBean.subjectName;
+            } else {
+                TeachableInstrumentBean instrumentBean = new TeachableInstrumentBean();
+                instrumentBean.id = Integer.parseInt(styleInfoBean.subjectId);
+                instrumentBean.name = styleInfoBean.subjectName;
                 selectTeachableInstrument.add(instrumentBean);
             }
             teachableSelectAdapter.notifyDataSetChanged();
@@ -257,6 +303,28 @@ public class MineStylePageActivity extends BaseMVPActivity<ActivityMineStylePage
     public void upLoadVideoFailure() {
     }
 
+    @Override
+    public void upLoadVideoCoverSuccess(String coverUrl) {
+        if (isFinishing() || isDestroyed()) {
+            return;
+        }
+        if (mMineStyleVideoListAdapter == null) {
+            return;
+        }
+        if (currentUploadCoverPosition != -1 && currentUploadCoverPosition < videoBeanList.size()) {
+            videoBeanList.get(currentUploadCoverPosition).cover = coverUrl;
+            mMineStyleVideoListAdapter.notifyItemChanged(currentUploadCoverPosition);
+        }
+    }
+
+    @Override
+    public void upLoadVideoCoverFail() {
+        if (isFinishing() || isDestroyed()) {
+            return;
+        }
+
+    }
+
     private void addEmptyVideoBean() {
         TeacherSelfStyleInfoBean.StyleVideoBean styleVideoBean = new TeacherSelfStyleInfoBean.StyleVideoBean();
         styleVideoBean.type = 1;
@@ -276,7 +344,26 @@ public class MineStylePageActivity extends BaseMVPActivity<ActivityMineStylePage
             } else if (requestCode == CHOOSE_VIDEO) {
                 Uri uri = data.getData();
                 String v_path = FileUtils.getFilePathForN(uri, MineStylePageActivity.this);
-                presenter.getUploadVideoCover(MineStylePageActivity.this, v_path);
+                presenter.uploadVideo(MineStylePageActivity.this, v_path);
+            } else if (requestCode == REQUEST_CODE_LOCAL) {
+                if (data != null) {
+                    // 图片、视频、音频选择结果回调
+                    List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
+                    String v_path = null;
+                    if (selectList != null && selectList.size() > 0) {
+                        v_path = selectList.get(0).getCompressPath();
+                    }
+                    if (!TextUtils.isEmpty(v_path)) {
+                        boolean isImg = MyFileUtils.isImg(v_path);
+                        if (isImg) {
+                            if (presenter != null) {
+                                presenter.uploadCover(MineStylePageActivity.this, v_path);
+                            }
+                        } else {
+                            ToastUtil.getInstance().showShort("请选择图片类型文件");
+                        }
+                    }
+                }
             }
         }
     }

BIN
teacher/src/main/res/drawable-xhdpi/icon_replace_video_cover.png


BIN
teacher/src/main/res/drawable-xhdpi/icon_upload_cover.png


BIN
teacher/src/main/res/drawable-xhdpi/icon_upload_video_cover.png


BIN
teacher/src/main/res/drawable-xxhdpi/icon_replace_video_cover.png


BIN
teacher/src/main/res/drawable-xxhdpi/icon_upload_cover.png


BIN
teacher/src/main/res/drawable-xxhdpi/icon_upload_video_cover.png


+ 9 - 0
teacher/src/main/res/drawable/bg_select_2dc7aa_radius_14dp.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <stroke
+        android:width="1dp"
+        android:color="@color/color_2dc7aa" />
+    <solid android:color="@color/color_e9fff8" />
+    <corners android:radius="14dp" />
+</shape>

+ 5 - 0
teacher/src/main/res/drawable/shape_2dc7aa_14dp.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <solid android:color="@color/color_2dc7aa" />
+    <corners android:radius="14dp" />
+</shape>

+ 32 - 4
teacher/src/main/res/layout/item_teacher_style_video_layout.xml

@@ -2,9 +2,11 @@
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content">
+    android:layout_height="wrap_content"
+    android:layout_marginTop="6dp">
 
     <FrameLayout
+        android:id="@+id/fl_video"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginLeft="5dp"
@@ -15,7 +17,6 @@
             android:layout_width="match_parent"
             android:layout_height="106dp"
             android:layout_marginTop="5dp"
-            android:layout_marginRight="5dp"
             app:qmui_corner_radius="10dp" />
 
         <ImageView
@@ -25,7 +26,6 @@
             android:src="@drawable/icon_play_video" />
 
         <TextView
-            android:visibility="gone"
             android:id="@+id/tv_audit_status"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
@@ -40,9 +40,37 @@
             android:paddingBottom="1dp"
             android:text="审核中"
             android:textColor="@color/white"
-            android:textSize="@dimen/sp_12" />
+            android:textSize="@dimen/sp_12"
+            android:visibility="gone" />
     </FrameLayout>
 
+    <LinearLayout
+        android:id="@+id/ll_upload_cover"
+        android:layout_marginEnd="10dp"
+        android:layout_width="match_parent"
+        android:layout_height="28dp"
+        android:layout_below="@+id/fl_video"
+        android:layout_centerHorizontal="true"
+        android:layout_marginTop="10dp"
+        android:background="@drawable/shape_2dc7aa_14dp"
+        android:gravity="center">
+
+        <ImageView
+            android:id="@+id/iv_upload_video_cover"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:src="@drawable/icon_upload_video_cover" />
+
+        <TextView
+            android:layout_marginStart="10dp"
+            android:id="@+id/tv_upload_cover"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="请上传视频封面"
+            android:textColor="@color/white"
+            android:textSize="@dimen/sp_14" />
+    </LinearLayout>
+
     <ImageView
         android:id="@+id/im_delete"
         android:layout_width="22dp"

+ 18 - 7
teacher/src/main/res/layout/item_teacher_style_video_layout_add.xml

@@ -1,10 +1,13 @@
 <?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
+    android:layout_marginTop="6dp"
     android:layout_height="111dp">
 
     <ImageView
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
         android:id="@+id/iv_video_add"
         android:layout_width="match_parent"
         android:layout_height="106dp"
@@ -15,18 +18,26 @@
         app:qmui_corner_radius="10dp" />
 
     <ImageView
+        app:layout_constraintVertical_chainStyle="packed"
+        app:layout_constraintBottom_toTopOf="@+id/iv_add_video_tip"
+        android:id="@+id/iv_add_video_icon"
+        app:layout_constraintRight_toRightOf="@+id/iv_video_add"
+        app:layout_constraintLeft_toLeftOf="@+id/iv_video_add"
+        app:layout_constraintTop_toTopOf="@+id/iv_video_add"
         android:layout_width="31dp"
         android:layout_height="25dp"
-        android:layout_marginTop="22dp"
         android:background="@drawable/icon_upload_tum"
         android:layout_centerHorizontal="true" />
     <TextView
+        android:layout_marginTop="16dp"
+        android:id="@+id/iv_add_video_tip"
+        app:layout_constraintBottom_toBottomOf="@+id/iv_video_add"
+        app:layout_constraintRight_toRightOf="@+id/iv_add_video_icon"
+        app:layout_constraintLeft_toLeftOf="@+id/iv_add_video_icon"
+        app:layout_constraintTop_toBottomOf="@+id/iv_add_video_icon"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="点击上传视频"
         android:textColor="@color/color_999999"
-        android:textSize="@dimen/sp_14"
-        android:layout_alignParentBottom="true"
-        android:layout_marginBottom="22dp"
-        android:layout_centerHorizontal="true"/>
-</RelativeLayout>
+        android:textSize="@dimen/sp_14" />
+</androidx.constraintlayout.widget.ConstraintLayout>