|
@@ -0,0 +1,556 @@
|
|
|
+package com.cooleshow.institution.stu.ui.setting;
|
|
|
+
|
|
|
+import android.Manifest;
|
|
|
+import android.content.Intent;
|
|
|
+import android.net.Uri;
|
|
|
+import android.os.Build;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.provider.MediaStore;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.alibaba.android.arouter.facade.annotation.Route;
|
|
|
+import com.alibaba.android.arouter.launcher.ARouter;
|
|
|
+import com.bigkoo.pickerview.builder.TimePickerBuilder;
|
|
|
+import com.bigkoo.pickerview.listener.CustomListener;
|
|
|
+import com.bigkoo.pickerview.view.TimePickerView;
|
|
|
+import com.cooleshow.base.bean.TeachableInstrumentBean;
|
|
|
+import com.cooleshow.base.constanst.EventConstants;
|
|
|
+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.GlideUtils;
|
|
|
+import com.cooleshow.base.utils.MyFileUtils;
|
|
|
+import com.cooleshow.base.utils.PopupUtil;
|
|
|
+import com.cooleshow.base.utils.ToastUtil;
|
|
|
+import com.cooleshow.base.utils.helper.GlideEngine;
|
|
|
+import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
|
|
|
+import com.cooleshow.institution.stu.R;
|
|
|
+import com.cooleshow.institution.stu.contract.PersonalSettingContract;
|
|
|
+import com.cooleshow.institution.stu.databinding.JgActivityPersonalSettingBinding;
|
|
|
+import com.cooleshow.institution.stu.presenter.PersonalSettingPresenter;
|
|
|
+import com.cooleshow.usercenter.bean.SetDetailBean;
|
|
|
+import com.cooleshow.usercenter.bean.StudentUserInfo;
|
|
|
+import com.cooleshow.usercenter.constants.UserConstants;
|
|
|
+import com.cooleshow.usercenter.helper.UserHelper;
|
|
|
+import com.luck.picture.lib.PictureSelector;
|
|
|
+import com.luck.picture.lib.compress.CompressionPredicate;
|
|
|
+import com.luck.picture.lib.compress.Luban;
|
|
|
+import com.luck.picture.lib.compress.OnCompressListener;
|
|
|
+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 org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.Serializable;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+import androidx.core.content.FileProvider;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 创建日期:2022/5/16 16:07
|
|
|
+ *
|
|
|
+ * @author Ryan
|
|
|
+ * 类说明:
|
|
|
+ */
|
|
|
+@Route(path = RouterPath.JGCenter.MINE_PERSONAL_SETTING)
|
|
|
+public class PersonalSettingActivity extends BaseMVPActivity<JgActivityPersonalSettingBinding, PersonalSettingPresenter> implements PersonalSettingContract.PersonalSettingView, View.OnClickListener {
|
|
|
+ private StudentUserInfo mySetDetailBean;
|
|
|
+ private final int MODIFY_NICKNAME = 1001;
|
|
|
+ private final int MODIFY_PHONE = 1002;
|
|
|
+ private final int PERSONAL_CERTIFICATION = 1003;
|
|
|
+ private final int REQUEST_CODE_CAMERA = 0x44;
|
|
|
+ public final int REQUEST_CODE_LOCAL = 0x19;
|
|
|
+
|
|
|
+ private String imagePath = null;//当前图片的路径
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ QMUIStatusBarHelper.setStatusBarLightMode(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ int id = view.getId();
|
|
|
+ if (id == R.id.cl_header) {
|
|
|
+ selectHeader();
|
|
|
+ } else if (id == R.id.cl_name) {
|
|
|
+ if (null != mySetDetailBean) {
|
|
|
+ ARouter.getInstance().build(RouterPath.MineCenter.MINE_MODIFY_NICKNAME)
|
|
|
+ .withString("userName", mySetDetailBean.username)
|
|
|
+ .navigation(this, MODIFY_NICKNAME);
|
|
|
+ }
|
|
|
+ } else if (id == R.id.cl_sex) {
|
|
|
+ modifySex();
|
|
|
+ } else if (id == R.id.cl_phone) {
|
|
|
+ ARouter.getInstance().build(RouterPath.MineCenter.MINE_CHECK_MODIFY_PHONENUM)
|
|
|
+ .navigation(this, MODIFY_PHONE);
|
|
|
+ } else if (id == R.id.cl_modify_psd) {
|
|
|
+ ARouter.getInstance().build(RouterPath.MineCenter.MINE_MODIFY_PASSWORD)
|
|
|
+ .withString("phoneNum", UserHelper.getUserPhone())
|
|
|
+ .navigation();
|
|
|
+ } else if (id == R.id.cl_certification) {
|
|
|
+ if (viewBinding.tvCertificationStatus.getText().equals("未认证")) {
|
|
|
+ ARouter.getInstance().build(RouterPath.MineCenter.MINE_PERSONAL_CERTIFICATION)
|
|
|
+ .navigation(this, PERSONAL_CERTIFICATION);
|
|
|
+ }
|
|
|
+ } else if (id == R.id.cl_birthday) {
|
|
|
+ selectBirthday();
|
|
|
+ } else if (id == R.id.cl_score) {
|
|
|
+ if (null != mySetDetailBean) {
|
|
|
+ try {
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ TeachableInstrumentBean teachableInstrumentBean = new TeachableInstrumentBean();
|
|
|
+ teachableInstrumentBean.id = Long.parseLong(mySetDetailBean.subjectId);
|
|
|
+ teachableInstrumentBean.name = mySetDetailBean.subjectName;
|
|
|
+ bundle.putSerializable("selectTeachableInstrument", (Serializable) teachableInstrumentBean);
|
|
|
+ ARouter.getInstance().build(RouterPath.MineCenter.MINE_TEACHABLE_INSTRUMENT)
|
|
|
+ .withBundle("bundle", bundle)
|
|
|
+ .navigation();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == R.id.tv_logout) {
|
|
|
+ //事件埋点->退出登录
|
|
|
+ UserHelper.saveUserToken("");
|
|
|
+ ARouter.getInstance().build(RouterPath.UserCenter.PATH_VERIFY_LOGIN)
|
|
|
+ .withString(UserConstants.PHONE_NUM_KEY, UserHelper.getUserPhone())
|
|
|
+ .navigation();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private TimePickerView pvTime;
|
|
|
+
|
|
|
+ private void selectBirthday() {
|
|
|
+ Calendar selectedDate = Calendar.getInstance();
|
|
|
+ Calendar startDate = Calendar.getInstance();
|
|
|
+ Calendar endDate = Calendar.getInstance();
|
|
|
+ //正确设置方式 原因:注意事项有说明
|
|
|
+ // startDate.set(2019, 0, 1);
|
|
|
+ // endDate.set(2050, 11, 31);
|
|
|
+ pvTime = new TimePickerBuilder(this, (date, v) -> {//选中事件回调
|
|
|
+
|
|
|
+ String birthdate = getTime(date);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ try {
|
|
|
+ jsonObject.put("birthdate", birthdate);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ presenter.submitSetDetail(jsonObject.toString());
|
|
|
+ }).setRangDate(startDate, endDate)
|
|
|
+ .setDate(endDate)
|
|
|
+ .setLayoutRes(com.cooleshow.base.R.layout.pickerview_default_layout, new CustomListener() {
|
|
|
+ @Override
|
|
|
+ public void customLayout(View 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(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ pvTime.returnData();
|
|
|
+ pvTime.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ ivCancel.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ pvTime.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .setLineSpacingMultiplier(2.5f)
|
|
|
+ .setType(new boolean[]{true, true, true, false, false, false})// 默认全部显示
|
|
|
+ .isCyclic(true)//是否循环滚动
|
|
|
+ .setOutSideCancelable(true)//点击屏幕,点在控件外部范围时,是否取消显示
|
|
|
+ .setTextColorCenter(getResources().getColor(com.cooleshow.base.R.color.color_1a1a1a))//设置选中项的颜色
|
|
|
+ // .setDate(selectedDate)// 如果不设置的话,默认是系统时间*/
|
|
|
+ .setRangDate(null, endDate)//起始终止年月日设定
|
|
|
+ .isDialog(false)//是否显示为对话框样式
|
|
|
+ .setLabel("年", "月", "日", "", "", "")
|
|
|
+ .build();
|
|
|
+ pvTime.show();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getTime(Date date) {//可根据需要自行截取数据显示
|
|
|
+ // SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ return format.format(date);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void modifySex() {
|
|
|
+ PopupUtil.showInBottom(this, R.layout.pop_modify_sex, (view, popupWindow) -> {
|
|
|
+ TextView tv_boy = view.findViewById(R.id.tv_boy);
|
|
|
+ TextView tv_girl = view.findViewById(R.id.tv_girl);
|
|
|
+ TextView tv_cancel = view.findViewById(R.id.tv_cancel);
|
|
|
+ tv_boy.setOnClickListener(view13 -> {
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ try {
|
|
|
+ jsonObject.put("gender", 1);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ popupWindow.dismiss();
|
|
|
+ presenter.submitSetDetail(jsonObject.toString());
|
|
|
+ });
|
|
|
+ tv_girl.setOnClickListener(view12 -> {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ try {
|
|
|
+ jsonObject.put("gender", 0);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ popupWindow.dismiss();
|
|
|
+ presenter.submitSetDetail(jsonObject.toString());
|
|
|
+ });
|
|
|
+ tv_cancel.setOnClickListener(view1 -> popupWindow.dismiss());
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void selectHeader() {
|
|
|
+ PopupUtil.showInBottom(this, R.layout.pop_modify_header, (view, popupWindow) -> {
|
|
|
+ TextView tv_camera = view.findViewById(R.id.tv_camera);
|
|
|
+ TextView tv_album = view.findViewById(R.id.tv_album);
|
|
|
+ TextView tv_cancel = view.findViewById(R.id.tv_cancel);
|
|
|
+ tv_camera.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ toCamera();
|
|
|
+ popupWindow.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ tv_album.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ toAlbum();
|
|
|
+ popupWindow.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ tv_cancel.setOnClickListener(view1 -> popupWindow.dismiss());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void toCamera() {
|
|
|
+ new RxPermissions(this)
|
|
|
+ .request(Manifest.permission.CAMERA,
|
|
|
+ Manifest.permission.READ_EXTERNAL_STORAGE,
|
|
|
+ Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
|
|
+ .subscribe(granted -> {
|
|
|
+ if (granted) {
|
|
|
+ goCamera();
|
|
|
+ } else {
|
|
|
+ ToastUtil.getInstance().show(this, "请选择存储和相机权限!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void requestCamera(String filePath) {
|
|
|
+ File outputImage = new File(filePath);
|
|
|
+ /*
|
|
|
+ 创建一个File文件对象,用于存放摄像头拍下的图片,我们把这个图片命名为output_image.jpg
|
|
|
+ 并把它存放在应用关联缓存目录下,调用getExternalCacheDir()可以得到这个目录,为什么要
|
|
|
+ 用关联缓存目录呢?由于android6.0开始,读写sd卡列为了危险权限,使用的时候必须要有权限,
|
|
|
+ 应用关联目录则可以跳过这一步
|
|
|
+ */
|
|
|
+ try//判断图片是否存在,存在则删除在创建,不存在则直接创建
|
|
|
+ {
|
|
|
+ if (!outputImage.getParentFile().exists()) {
|
|
|
+ outputImage.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+ if (outputImage.exists()) {
|
|
|
+ outputImage.delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ outputImage.createNewFile();
|
|
|
+ Uri imageUri;
|
|
|
+ if (Build.VERSION.SDK_INT >= 24) {
|
|
|
+ imageUri = FileProvider.getUriForFile(this,
|
|
|
+ "com.cooleshow.student.fileprovider", outputImage);
|
|
|
+ } else {
|
|
|
+ imageUri = Uri.fromFile(outputImage);
|
|
|
+ }
|
|
|
+ //使用隐示的Intent,系统会找到与它对应的活动,即调用摄像头,并把它存储
|
|
|
+ Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
|
|
|
+ intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
|
|
|
+ ActivityUtils.startActivityForResult(this, intent, REQUEST_CODE_CAMERA);
|
|
|
+ //调用会返回结果的开启方式,返回成功的话,则把它显示出来
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 goCamera() {
|
|
|
+ PictureSelector.create(this)
|
|
|
+ .openCamera(PictureMimeType.ofImage())
|
|
|
+ .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
|
|
|
+ .cutOutQuality(100)
|
|
|
+ .showCropGrid(false)// 是否显示裁剪矩形网格 圆形裁剪时建议设为false true or false
|
|
|
+ .compress(true)// 是否压缩 true or false
|
|
|
+ .circleDimmedLayer(true)// 是否圆形裁剪 true or false
|
|
|
+ .forResult(REQUEST_CODE_LOCAL);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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
|
|
|
+ .cutOutQuality(100)
|
|
|
+ .showCropGrid(false)// 是否显示裁剪矩形网格 圆形裁剪时建议设为false true or false
|
|
|
+ .compress(true)// 是否压缩 true or false
|
|
|
+ .circleDimmedLayer(true)// 是否圆形裁剪 true or false
|
|
|
+ .forResult(REQUEST_CODE_LOCAL);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initView() {
|
|
|
+ initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "设置");
|
|
|
+ viewBinding.clHeader.setOnClickListener(this);
|
|
|
+ viewBinding.clName.setOnClickListener(this);
|
|
|
+ viewBinding.clSex.setOnClickListener(this);
|
|
|
+ viewBinding.clPhone.setOnClickListener(this);
|
|
|
+ viewBinding.clModifyPsd.setOnClickListener(this);
|
|
|
+ viewBinding.clCertification.setOnClickListener(this);
|
|
|
+ viewBinding.clBirthday.setOnClickListener(this);
|
|
|
+ viewBinding.clScore.setOnClickListener(this);
|
|
|
+ viewBinding.tvLogout.setOnClickListener(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initData() {
|
|
|
+ super.initData();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ presenter.queryUserInfo();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected JgActivityPersonalSettingBinding getLayoutView() {
|
|
|
+ return JgActivityPersonalSettingBinding.inflate(getLayoutInflater());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected PersonalSettingPresenter createPresenter() {
|
|
|
+ return new PersonalSettingPresenter();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void queryUserInfoSuccess(StudentUserInfo data) {
|
|
|
+ mySetDetailBean = data;
|
|
|
+ GlideUtils.INSTANCE.loadImage(this, data.heardUrl, viewBinding.imHeader, com.cooleshow.base.R.drawable.icon_default_head);
|
|
|
+ viewBinding.tvNickname.setText(data.username);
|
|
|
+ if (!TextUtils.isEmpty(data.gender) && data.gender.equals("0")) {
|
|
|
+ //女
|
|
|
+ viewBinding.tvSex.setText("女");
|
|
|
+ } else {
|
|
|
+ //男
|
|
|
+ viewBinding.tvSex.setText("男");
|
|
|
+ }
|
|
|
+ viewBinding.tvPhone.setText(UserHelper.getUserPhone());
|
|
|
+ if (!TextUtils.isEmpty(data.birthdate)) {
|
|
|
+ if (data.birthdate.contains(" ")) {
|
|
|
+ String[] s = data.birthdate.split(" ");
|
|
|
+ viewBinding.tvBirthday.setText(s[0]);
|
|
|
+ } else {
|
|
|
+ viewBinding.tvBirthday.setText(data.birthdate);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ viewBinding.tvBirthday.setText("");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!TextUtils.isEmpty(data.subjectName)) {
|
|
|
+ viewBinding.tvScore.setText(data.subjectName);
|
|
|
+ } else {
|
|
|
+ viewBinding.tvScore.setText("");
|
|
|
+ }
|
|
|
+ if (!TextUtils.isEmpty(data.isReal) && data.isReal.equals("1")) {
|
|
|
+ //是
|
|
|
+ viewBinding.tvCertificationStatus.setText("已认证");
|
|
|
+ } else {
|
|
|
+ //否
|
|
|
+ viewBinding.tvCertificationStatus.setText("未认证");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void submitSetDetailSuccess(SetDetailBean setDetailBean) {
|
|
|
+ mySetDetailBean.gender = setDetailBean.gender + "";
|
|
|
+ mySetDetailBean.heardUrl = setDetailBean.avatar;
|
|
|
+ if (setDetailBean.gender == 0) {
|
|
|
+ //女
|
|
|
+ viewBinding.tvSex.setText("女");
|
|
|
+ } else {
|
|
|
+ //男
|
|
|
+ viewBinding.tvSex.setText("男");
|
|
|
+ }
|
|
|
+ //15510601008
|
|
|
+ if (!TextUtils.isEmpty(setDetailBean.birthdate)) {
|
|
|
+ if (setDetailBean.birthdate.contains(" ")) {
|
|
|
+ String[] s = setDetailBean.birthdate.split(" ");
|
|
|
+ viewBinding.tvBirthday.setText(s[0]);
|
|
|
+ } else {
|
|
|
+ viewBinding.tvBirthday.setText(setDetailBean.birthdate);
|
|
|
+ }
|
|
|
+ mySetDetailBean.birthdate = setDetailBean.birthdate;
|
|
|
+ } else {
|
|
|
+ viewBinding.tvBirthday.setText("");
|
|
|
+ }
|
|
|
+ ToastUtil.getInstance().showShort("修改成功");
|
|
|
+ GlideUtils.INSTANCE.loadImage(this, setDetailBean.avatar, viewBinding.imHeader, com.cooleshow.base.R.drawable.icon_default_head);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void upLoadImageSuccess(String url) {
|
|
|
+ hideLoading();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ try {
|
|
|
+ jsonObject.put("avatar", url);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ presenter.submitSetDetail(jsonObject.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void upLoadImageFailure() {
|
|
|
+ hideLoading();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+ if (resultCode == RESULT_OK) {
|
|
|
+ if (requestCode == MODIFY_NICKNAME) {
|
|
|
+ String userName = data.getStringExtra("userName");
|
|
|
+ mySetDetailBean.username = userName;
|
|
|
+ viewBinding.tvNickname.setText(userName);
|
|
|
+ } else if (requestCode == MODIFY_PHONE) {
|
|
|
+ String newPhoneNum = data.getStringExtra("newPhoneNum");
|
|
|
+ mySetDetailBean.phone = newPhoneNum;
|
|
|
+ viewBinding.tvPhone.setText(newPhoneNum);
|
|
|
+ } else if (requestCode == PERSONAL_CERTIFICATION) {
|
|
|
+ viewBinding.tvCertificationStatus.setText("已认证");
|
|
|
+ } else if (requestCode == REQUEST_CODE_CAMERA) {
|
|
|
+ boolean isImg = MyFileUtils.isImg(imagePath);
|
|
|
+ if (isImg) {
|
|
|
+ compressImg(imagePath);
|
|
|
+ } else {
|
|
|
+ ToastUtil.getInstance().showShort("请选择图片类型文件");
|
|
|
+ }
|
|
|
+ } 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) {
|
|
|
+ compressImg(v_path);
|
|
|
+ } else {
|
|
|
+ ToastUtil.getInstance().showShort("请选择图片类型文件");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void compressImg(String filePath) {
|
|
|
+ LocalMedia localMedia = new LocalMedia();
|
|
|
+ localMedia.setPath(filePath);
|
|
|
+ ArrayList<LocalMedia> list = new ArrayList<>();
|
|
|
+ list.add(localMedia);
|
|
|
+ Luban.with(this)
|
|
|
+ .loadMediaData(list)
|
|
|
+ .ignoreBy(100)
|
|
|
+ .setTargetDir(FileUtils.getCompressPath())
|
|
|
+ .filter(new CompressionPredicate() {
|
|
|
+ @Override
|
|
|
+ public boolean apply(String path) {
|
|
|
+ return !(TextUtils.isEmpty(path) || path.toLowerCase().endsWith(".gif"));
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .setCompressListener(new OnCompressListener() {
|
|
|
+ @Override
|
|
|
+ public void onStart() {
|
|
|
+ // TODO 压缩开始前调用,可以在方法内启动 loading UI
|
|
|
+ showLoading();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(List<LocalMedia> list) {
|
|
|
+ hideLoading();
|
|
|
+ // TODO 压缩成功后调用,返回压缩后的图片文件
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ LocalMedia localMedia = list.get(i);
|
|
|
+ String compressPath = localMedia.getCompressPath();
|
|
|
+ presenter.upLoadImage(PersonalSettingActivity.this, compressPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Throwable e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ hideLoading();
|
|
|
+ ToastUtil.getInstance().showShort("上传失败,请重新选择");
|
|
|
+ }
|
|
|
+ }).launch();
|
|
|
+ }
|
|
|
+}
|