|
@@ -0,0 +1,357 @@
|
|
|
+package com.cooleshow.teacher.ui.minestyle;
|
|
|
+
|
|
|
+import android.Manifest;
|
|
|
+import android.content.ContentResolver;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.database.Cursor;
|
|
|
+import android.net.Uri;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Environment;
|
|
|
+import android.provider.MediaStore;
|
|
|
+import android.provider.OpenableColumns;
|
|
|
+import android.text.Editable;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.text.TextWatcher;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.MotionEvent;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.view.WindowManager;
|
|
|
+import android.view.inputmethod.InputMethodManager;
|
|
|
+import android.widget.EditText;
|
|
|
+import android.widget.ScrollView;
|
|
|
+
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
+import androidx.recyclerview.widget.RecyclerView;
|
|
|
+
|
|
|
+import com.alibaba.android.arouter.facade.annotation.Route;
|
|
|
+import com.alibaba.android.arouter.launcher.ARouter;
|
|
|
+import com.cooleshow.base.data.net.BaseResponse;
|
|
|
+import com.cooleshow.base.router.RouterPath;
|
|
|
+import com.cooleshow.base.ui.activity.BaseMVPActivity;
|
|
|
+import com.cooleshow.base.utils.ActivityUtils;
|
|
|
+import com.cooleshow.base.utils.FileUtils;
|
|
|
+import com.cooleshow.base.utils.ToastUtil;
|
|
|
+import com.cooleshow.base.utils.helper.upload.UploadHelper;
|
|
|
+import com.cooleshow.teacher.R;
|
|
|
+import com.cooleshow.teacher.adapter.MineStyleVideoAdapter;
|
|
|
+import com.cooleshow.teacher.adapter.TeachableSelectAdapter;
|
|
|
+import com.cooleshow.teacher.bean.TeachableInstrumentBean;
|
|
|
+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.web.WebActivity;
|
|
|
+import com.daya.live_teaching.model.FileUploadBean;
|
|
|
+import com.daya.live_teaching.repository.ClassRepository;
|
|
|
+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.tbruyelle.rxpermissions3.RxPermissions;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.io.Serializable;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import retrofit2.Call;
|
|
|
+import retrofit2.Callback;
|
|
|
+import retrofit2.Response;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 创建日期:2022/5/13 14:02
|
|
|
+ *
|
|
|
+ * @author Ryan
|
|
|
+ * 类说明:
|
|
|
+ */
|
|
|
+@Route(path = RouterPath.MineCenter.MINE_STYLE_PAGE)
|
|
|
+public class MineStylePageActivity extends BaseMVPActivity<ActivityMineStylePageBinding, MineStylePagePresenter> implements MineStylePageContract.MineStylePageView, View.OnClickListener {
|
|
|
+ private final int SELECT_RESULT = 1001;
|
|
|
+ private final int CHOOSE_VIDEO = 1002;
|
|
|
+ private EditText etSelfIntroduction;
|
|
|
+ private RecyclerView videoList;
|
|
|
+ private MineStyleVideoAdapter mMineStyleVideoListAdapter;
|
|
|
+ private RecyclerView rvTopSelect;
|
|
|
+ private TeachableSelectAdapter teachableSelectAdapter;
|
|
|
+ private TeacherSelfStyleInfoBean myStyleInfoBean = null;
|
|
|
+ private List<TeachableInstrumentBean> selectTeachableInstrument = new ArrayList<>();
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ switch (view.getId()) {
|
|
|
+ case R.id.tv_select_fans:
|
|
|
+ Bundle bundle=new Bundle();
|
|
|
+ bundle.putSerializable("selectTeachableInstrument", (Serializable) selectTeachableInstrument);
|
|
|
+ ARouter.getInstance().build(RouterPath.MineCenter.MINE_TEACHABLE_INSTRUMENT)
|
|
|
+ .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){
|
|
|
+ myStyleInfoBean.styleVideo.add(styleVideoBean);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ myStyleInfoBean.introduction=etSelfIntroduction.getText().toString().trim();
|
|
|
+ String subjectIdStr="";
|
|
|
+ String subjectNameStr="";
|
|
|
+ for (TeachableInstrumentBean teachableInstrumentBean : selectTeachableInstrument) {
|
|
|
+ subjectIdStr+=","+teachableInstrumentBean.id;
|
|
|
+ subjectNameStr+=","+teachableInstrumentBean.name;
|
|
|
+ }
|
|
|
+ if (subjectIdStr.startsWith(",")){
|
|
|
+ subjectIdStr= subjectIdStr.replaceFirst(",","");
|
|
|
+ }
|
|
|
+ if (subjectNameStr.startsWith(",")){
|
|
|
+ subjectNameStr= subjectNameStr.replaceFirst(",","");
|
|
|
+ }
|
|
|
+ myStyleInfoBean.subjectId=subjectIdStr;
|
|
|
+ myStyleInfoBean.subjectName=subjectNameStr;
|
|
|
+ presenter.saveTeacherStyle(gson.toJson(myStyleInfoBean));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
+ getWindow().setSoftInputMode
|
|
|
+ (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN |
|
|
|
+ WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initData() {
|
|
|
+ super.initData();
|
|
|
+ presenter.getTeacherSelfStyle();
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<TeacherSelfStyleInfoBean.StyleVideoBean> videoBeanList = new ArrayList<>();
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initView() {
|
|
|
+ initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "个人风采");
|
|
|
+ etSelfIntroduction = viewBinding.etSelfIntroduction;
|
|
|
+ videoList = viewBinding.rvTeacherStyleVideo;
|
|
|
+ viewBinding.tvSelectFans.setOnClickListener(this);
|
|
|
+ viewBinding.tvSave.setOnClickListener(this);
|
|
|
+ GridLayoutManager manager = new GridLayoutManager(this, 2);
|
|
|
+ videoList.setLayoutManager(manager);
|
|
|
+ addEmptyVideoBean();
|
|
|
+ mMineStyleVideoListAdapter = new MineStyleVideoAdapter(videoBeanList);
|
|
|
+ videoList.setAdapter(mMineStyleVideoListAdapter);
|
|
|
+ mMineStyleVideoListAdapter.setItemAddClickAction(new MineStyleVideoAdapter.ItemAddClickAction() {
|
|
|
+ @Override
|
|
|
+ public void add() {
|
|
|
+ getVideoPermission();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(String url) {
|
|
|
+ for (TeacherSelfStyleInfoBean.StyleVideoBean styleVideoBean : videoBeanList) {
|
|
|
+ if (styleVideoBean.type == 0 && styleVideoBean.videoUrl.equals(url)) {
|
|
|
+ videoBeanList.remove(styleVideoBean);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mMineStyleVideoListAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ rvTopSelect = viewBinding.rvTopSelect;
|
|
|
+ //设置LayoutManager
|
|
|
+ FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(this);
|
|
|
+ //主轴为水平方向,起点在左端
|
|
|
+ flexboxLayoutManager.setFlexDirection(FlexDirection.ROW);
|
|
|
+ //按正常方向换行
|
|
|
+ flexboxLayoutManager.setFlexWrap(FlexWrap.WRAP);
|
|
|
+ //定义项目在副轴轴上如何对齐
|
|
|
+ flexboxLayoutManager.setAlignItems(AlignItems.CENTER);
|
|
|
+ //多个轴对齐方式
|
|
|
+ flexboxLayoutManager.setJustifyContent(JustifyContent.FLEX_START);
|
|
|
+ rvTopSelect.setLayoutManager(flexboxLayoutManager);
|
|
|
+ teachableSelectAdapter = new TeachableSelectAdapter(selectTeachableInstrument);
|
|
|
+ rvTopSelect.setAdapter(teachableSelectAdapter);
|
|
|
+ addETListener();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addETListener() {
|
|
|
+ etSelfIntroduction.addTextChangedListener(new TextWatcher() {
|
|
|
+ @Override
|
|
|
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable s) {
|
|
|
+ String trim = etSelfIntroduction.getText().toString();
|
|
|
+ viewBinding.tvNumHint.setText(trim.length() + "/150");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected ActivityMineStylePageBinding getLayoutView() {
|
|
|
+ return ActivityMineStylePageBinding.inflate(getLayoutInflater());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected MineStylePagePresenter createPresenter() {
|
|
|
+ return new MineStylePagePresenter();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getSelfStyleSuccess(TeacherSelfStyleInfoBean styleInfoBean) {
|
|
|
+ myStyleInfoBean = styleInfoBean;
|
|
|
+ //个人介绍
|
|
|
+ viewBinding.etSelfIntroduction.setText(styleInfoBean.introduction);
|
|
|
+ //视频信息
|
|
|
+ if (mMineStyleVideoListAdapter != null) {
|
|
|
+ videoBeanList.clear();
|
|
|
+ videoBeanList.addAll(styleInfoBean.styleVideo);
|
|
|
+ addEmptyVideoBean();
|
|
|
+ mMineStyleVideoListAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ 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];
|
|
|
+ selectTeachableInstrument.add(instrumentBean);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ TeachableInstrumentBean instrumentBean=new TeachableInstrumentBean();
|
|
|
+ instrumentBean.id=Integer.parseInt(styleInfoBean.subjectId);
|
|
|
+ instrumentBean.name=styleInfoBean.subjectName;
|
|
|
+ selectTeachableInstrument.add(instrumentBean);
|
|
|
+ }
|
|
|
+ teachableSelectAdapter.notifyDataSetChanged();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveTeacherStyleSuccess(TeacherSelfStyleInfoBean styleInfoBean) {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void upLoadVideoSuccess(TeacherSelfStyleInfoBean.StyleVideoBean styleVideoBean) {
|
|
|
+ hideLoading();
|
|
|
+ videoBeanList.add(0, styleVideoBean);
|
|
|
+ mMineStyleVideoListAdapter.notifyDataSetChanged();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void upLoadVideoFailure() {
|
|
|
+ hideLoading();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addEmptyVideoBean() {
|
|
|
+ TeacherSelfStyleInfoBean.StyleVideoBean styleVideoBean = new TeacherSelfStyleInfoBean.StyleVideoBean();
|
|
|
+ styleVideoBean.type = 1;
|
|
|
+ videoBeanList.add(styleVideoBean);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+ if (resultCode == RESULT_OK) {
|
|
|
+ if (requestCode == SELECT_RESULT) {
|
|
|
+ List<TeachableInstrumentBean> dataSerializableExtra = (List<TeachableInstrumentBean>) data.getSerializableExtra("selectTeachableInstrument");
|
|
|
+ selectTeachableInstrument.clear();
|
|
|
+ selectTeachableInstrument.addAll(dataSerializableExtra);
|
|
|
+ teachableSelectAdapter.notifyDataSetChanged();
|
|
|
+ } else if (requestCode == CHOOSE_VIDEO) {
|
|
|
+ showLoading();
|
|
|
+ Uri uri = data.getData();
|
|
|
+ String v_path = FileUtils.getFilePathForN(uri, MineStylePageActivity.this);
|
|
|
+ presenter.upLoadVideo(MineStylePageActivity.this, v_path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void getVideoPermission() {
|
|
|
+ new RxPermissions(this)
|
|
|
+ .request(Manifest.permission.CAMERA,
|
|
|
+ Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
|
+ Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
|
|
+ .subscribe(granted -> {
|
|
|
+ if (granted) {
|
|
|
+ // All requested permissions are granted
|
|
|
+ chooseVideo();
|
|
|
+ } else {
|
|
|
+ // At least one permission is denied
|
|
|
+ ToastUtil.getInstance().show(this, "请选择存储和相机权限!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void chooseVideo() {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setType("video/*"); //选择视频 (mp4 3gp 是android支持的视频格式)
|
|
|
+ intent.setAction(Intent.ACTION_GET_CONTENT);
|
|
|
+ /* 取得相片后返回本画面 */
|
|
|
+ ActivityUtils.startActivityForResult(this, intent, CHOOSE_VIDEO);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
+ if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
+
|
|
|
+ View v = getCurrentFocus();
|
|
|
+ if (isShouldHideInput(v, ev)) {
|
|
|
+
|
|
|
+ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
+ if (imm != null) {
|
|
|
+ imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return super.dispatchTouchEvent(ev);
|
|
|
+ }
|
|
|
+ // 必不可少,否则所有的组件都不会有TouchEvent了
|
|
|
+ if (getWindow().superDispatchTouchEvent(ev)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return onTouchEvent(ev);
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isShouldHideInput(View v, MotionEvent event) {
|
|
|
+ if (v != null && (v instanceof EditText)) {
|
|
|
+ int[] leftTop = {0, 0};
|
|
|
+ //获取输入框当前的location位置
|
|
|
+ v.getLocationInWindow(leftTop);
|
|
|
+ int left = leftTop[0];
|
|
|
+ int top = leftTop[1];
|
|
|
+ int bottom = top + v.getHeight();
|
|
|
+ int right = left + v.getWidth();
|
|
|
+ return !(event.getX() > left && event.getX() < right
|
|
|
+ && event.getY() > top && event.getY() < bottom);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|