|
@@ -38,6 +38,10 @@ import com.cooleshow.student.contract.PersonalSettingContract;
|
|
|
import com.cooleshow.student.databinding.ActivityPersonalSettingBinding;
|
|
|
import com.cooleshow.student.presenter.mine.PersonalSettingPresenter;
|
|
|
import com.cooleshow.usercenter.bean.SetDetailBean;
|
|
|
+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.entity.LocalMedia;
|
|
|
import com.tbruyelle.rxpermissions3.RxPermissions;
|
|
|
|
|
|
import org.json.JSONException;
|
|
@@ -47,8 +51,10 @@ 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 io.rong.imkit.utils.StatusBarUtil;
|
|
|
|
|
@@ -423,8 +429,8 @@ public class PersonalSettingActivity extends BaseMVPActivity<ActivityPersonalSet
|
|
|
} else {
|
|
|
viewBinding.tvBirthday.setText(setDetailBean.birthdate);
|
|
|
}
|
|
|
- mySetDetailBean.birthdate=setDetailBean.birthdate;
|
|
|
- }else{
|
|
|
+ mySetDetailBean.birthdate = setDetailBean.birthdate;
|
|
|
+ } else {
|
|
|
viewBinding.tvBirthday.setText("");
|
|
|
}
|
|
|
ToastUtil.getInstance().showShort("修改成功");
|
|
@@ -468,7 +474,7 @@ public class PersonalSettingActivity extends BaseMVPActivity<ActivityPersonalSet
|
|
|
} else if (requestCode == REQUEST_CODE_CAMERA) {
|
|
|
boolean isImg = MyFileUtils.isImg(imagePath);
|
|
|
if (isImg) {
|
|
|
- presenter.upLoadImage(PersonalSettingActivity.this, imagePath);
|
|
|
+ compressImg(imagePath);
|
|
|
} else {
|
|
|
ToastUtil.getInstance().showShort("请选择图片类型文件");
|
|
|
}
|
|
@@ -479,7 +485,7 @@ public class PersonalSettingActivity extends BaseMVPActivity<ActivityPersonalSet
|
|
|
String v_path = FileUtils.getFilePathForN(selectedImage, PersonalSettingActivity.this);
|
|
|
boolean isImg = MyFileUtils.isImg(v_path);
|
|
|
if (isImg) {
|
|
|
- presenter.upLoadImage(PersonalSettingActivity.this, v_path);
|
|
|
+ compressImg(v_path);
|
|
|
} else {
|
|
|
ToastUtil.getInstance().showShort("请选择图片类型文件");
|
|
|
}
|
|
@@ -488,4 +494,46 @@ public class PersonalSettingActivity extends BaseMVPActivity<ActivityPersonalSet
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ 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();
|
|
|
+ }
|
|
|
}
|