|
@@ -15,6 +15,7 @@ import com.alibaba.android.arouter.facade.annotation.Route;
|
|
|
import com.alibaba.android.arouter.launcher.ARouter;
|
|
|
import com.cooleshow.base.router.RouterPath;
|
|
|
import com.cooleshow.base.ui.activity.BaseMVPActivity;
|
|
|
+import com.cooleshow.base.utils.ToastUtil;
|
|
|
import com.cooleshow.base.utils.ToastUtils;
|
|
|
import com.cooleshow.teacher.R;
|
|
|
import com.cooleshow.teacher.contract.ModifyPasswordContract;
|
|
@@ -23,6 +24,7 @@ import com.cooleshow.teacher.presenter.mine.ModifyPasswordPresenter;
|
|
|
import com.cooleshow.usercenter.constants.UserConstants;
|
|
|
import com.cooleshow.usercenter.helper.UserHelper;
|
|
|
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
@@ -30,7 +32,12 @@ import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.Timer;
|
|
|
import java.util.TimerTask;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
+import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
|
|
+import io.reactivex.rxjava3.core.Observable;
|
|
|
+import io.reactivex.rxjava3.core.Observer;
|
|
|
+import io.reactivex.rxjava3.disposables.Disposable;
|
|
|
import io.rong.imkit.utils.StatusBarUtil;
|
|
|
|
|
|
/**
|
|
@@ -41,25 +48,27 @@ import io.rong.imkit.utils.StatusBarUtil;
|
|
|
*/
|
|
|
@Route(path = RouterPath.MineCenter.MINE_MODIFY_PASSWORD)
|
|
|
public class ModifyPasswordActivity extends BaseMVPActivity<ActivityModifyPasswordBinding, ModifyPasswordPresenter> implements ModifyPasswordContract.ModifyPasswordView, View.OnClickListener {
|
|
|
+ private Disposable disposable;
|
|
|
+
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
- switch (view.getId()){
|
|
|
+ switch (view.getId()) {
|
|
|
case R.id.tv_confirm:
|
|
|
String password = viewBinding.etPassword.getText().toString().trim();
|
|
|
- if (TextUtils.isEmpty(password)||password.length()<6||password.length()>20){
|
|
|
+ if (TextUtils.isEmpty(password) || password.length() < 6 || password.length() > 20) {
|
|
|
ToastUtils.showShort("请输入6-20位密码");
|
|
|
break;
|
|
|
}
|
|
|
String authCode = viewBinding.etAuthCode.getText().toString().trim();
|
|
|
- if (TextUtils.isEmpty(authCode)){
|
|
|
+ if (TextUtils.isEmpty(authCode)) {
|
|
|
ToastUtils.showShort("请输入验证码");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
Map<String, String> params = new HashMap<>();
|
|
|
- params.put("mobile",phoneNum);
|
|
|
- params.put("authCode",authCode);
|
|
|
- params.put("newPassword",password);
|
|
|
+ params.put("mobile", phoneNum);
|
|
|
+ params.put("authCode", authCode);
|
|
|
+ params.put("newPassword", password);
|
|
|
presenter.updatePassword(params);
|
|
|
break;
|
|
|
case R.id.tv_get_auth_code:
|
|
@@ -80,6 +89,7 @@ public class ModifyPasswordActivity extends BaseMVPActivity<ActivityModifyPasswo
|
|
|
super.onCreate(savedInstanceState);
|
|
|
StatusBarUtil.setStatusBarDarkTheme(this, true);
|
|
|
}
|
|
|
+
|
|
|
@Autowired(name = "phoneNum")
|
|
|
String phoneNum;
|
|
|
|
|
@@ -89,7 +99,7 @@ public class ModifyPasswordActivity extends BaseMVPActivity<ActivityModifyPasswo
|
|
|
initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "修改密码");
|
|
|
viewBinding.tvConfirm.setOnClickListener(this);
|
|
|
viewBinding.tvGetAuthCode.setOnClickListener(this);
|
|
|
- String cPhone = phoneNum.substring(0, 3) + "****" + phoneNum.substring(7, phoneNum.length());
|
|
|
+ String cPhone = phoneNum.substring(0, 3) + "****" + phoneNum.substring(7);
|
|
|
viewBinding.tvPhone.setText(cPhone);
|
|
|
}
|
|
|
|
|
@@ -105,6 +115,7 @@ public class ModifyPasswordActivity extends BaseMVPActivity<ActivityModifyPasswo
|
|
|
|
|
|
@Override
|
|
|
public void updatePasswordSuccess(Object object) {
|
|
|
+ ToastUtil.getInstance().showShort("修改成功");
|
|
|
UserHelper.saveUserToken("");
|
|
|
ARouter.getInstance().build(RouterPath.UserCenter.PATH_VERIFY_LOGIN)
|
|
|
.withString(UserConstants.PHONE_NUM_KEY, UserHelper.getUserPhone())
|
|
@@ -123,82 +134,56 @@ public class ModifyPasswordActivity extends BaseMVPActivity<ActivityModifyPasswo
|
|
|
public void getCodeSuccess() {
|
|
|
ToastUtils.showShort("验证码发送成功,请注意查收!");
|
|
|
startTimer();
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
/**
|
|
|
- * 执行完成
|
|
|
- */
|
|
|
- public static final int EXECUTE_FINISH = 0X11000;
|
|
|
- /**
|
|
|
- * 执行中
|
|
|
+ * 开始倒计时
|
|
|
*/
|
|
|
- public static final int EXECUTE_LOADING = 0X4000;
|
|
|
- private int mTimerId = 60;
|
|
|
+ private void startTimer() {
|
|
|
+ Observable.interval(1000, TimeUnit.MILLISECONDS)
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new Observer<Long>() {
|
|
|
+ @Override
|
|
|
+ public void onSubscribe(@NotNull Disposable d) {
|
|
|
+ disposable = d;
|
|
|
+ }
|
|
|
|
|
|
- private TimerTask timerTask;
|
|
|
+ @Override
|
|
|
+ public void onNext(@NotNull Long aLong) {
|
|
|
+ if (aLong < 60) {
|
|
|
+ viewBinding.tvGetAuthCode.setText(59 - aLong + "s");
|
|
|
+ viewBinding.tvGetAuthCode.setClickable(false);
|
|
|
+ } else {
|
|
|
+ onComplete();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- private Timer timer;
|
|
|
+ @Override
|
|
|
+ public void onError(@NotNull Throwable e) {
|
|
|
|
|
|
- /**
|
|
|
- * 开始倒计时
|
|
|
- */
|
|
|
- private void startTimer() {
|
|
|
+ }
|
|
|
|
|
|
- if (timerTask == null) {
|
|
|
- timerTask = new TimerTask() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- Message msg = new Message();
|
|
|
- msg.what = EXECUTE_LOADING;
|
|
|
- msg.arg1 = --mTimerId;
|
|
|
- handler.sendMessage(msg);
|
|
|
- }
|
|
|
- };
|
|
|
- timer = new Timer();
|
|
|
- timer.schedule(timerTask, 100, 1000);
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void onComplete() {
|
|
|
+ closeTimer();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 结束计时
|
|
|
*/
|
|
|
private void closeTimer() {
|
|
|
- if (timer != null) {
|
|
|
- timer.cancel();
|
|
|
- timer = null;
|
|
|
- }
|
|
|
- if (timerTask != null) {
|
|
|
- timerTask = null;
|
|
|
+ if (disposable != null && !disposable.isDisposed()) {
|
|
|
+ disposable.dispose();
|
|
|
}
|
|
|
- mTimerId = 60;
|
|
|
- handler.sendEmptyMessage(EXECUTE_FINISH);
|
|
|
+ viewBinding.tvGetAuthCode.setText("获取验证码");
|
|
|
+ viewBinding.tvGetAuthCode.setClickable(true);
|
|
|
}
|
|
|
|
|
|
- @SuppressLint("HandlerLeak")
|
|
|
- private Handler handler = new Handler() {
|
|
|
- @Override
|
|
|
- public void handleMessage(Message msg) {
|
|
|
- switch (msg.what) {
|
|
|
- case EXECUTE_LOADING:
|
|
|
- viewBinding.tvGetAuthCode.setText(msg.arg1 + "s");
|
|
|
- viewBinding.tvGetAuthCode.setClickable(false);
|
|
|
- if (msg.arg1 == 0) {
|
|
|
- closeTimer();
|
|
|
- viewBinding.tvGetAuthCode.setClickable(true);
|
|
|
- }
|
|
|
- break;
|
|
|
- case EXECUTE_FINISH:
|
|
|
- viewBinding.tvGetAuthCode.setClickable(true);
|
|
|
- viewBinding.tvGetAuthCode.setText("获取验证码");
|
|
|
- break;
|
|
|
- }
|
|
|
- super.handleMessage(msg);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
@Override
|
|
|
public void onDestroy() {
|
|
|
+ closeTimer();
|
|
|
super.onDestroy();
|
|
|
- handler.removeCallbacksAndMessages(EXECUTE_LOADING);
|
|
|
}
|
|
|
}
|