|
@@ -0,0 +1,267 @@
|
|
|
+package com.cooleshow.usercenter.ui.activity.setting;
|
|
|
+
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.View;
|
|
|
+
|
|
|
+import com.alibaba.android.arouter.facade.annotation.Autowired;
|
|
|
+import com.alibaba.android.arouter.facade.annotation.Route;
|
|
|
+import com.alibaba.android.arouter.launcher.ARouter;
|
|
|
+import com.cooleshow.base.constanst.StyleConfig;
|
|
|
+import com.cooleshow.base.router.RouterPath;
|
|
|
+import com.cooleshow.base.ui.activity.BaseMVPActivity;
|
|
|
+import com.cooleshow.base.utils.ToastUtil;
|
|
|
+import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
|
|
|
+import com.cooleshow.base.widgets.dialog.ImgVerifyCodeDialog;
|
|
|
+import com.cooleshow.usercenter.R;
|
|
|
+import com.cooleshow.usercenter.constants.UserConstants;
|
|
|
+import com.cooleshow.usercenter.databinding.AcModifyPasswordBinding;
|
|
|
+import com.cooleshow.usercenter.helper.UserHelper;
|
|
|
+import com.cooleshow.usercenter.presenter.ModifyPasswordPresenter;
|
|
|
+import com.cooleshow.usercenter.presenter.contract.ModifyPasswordContract;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Timer;
|
|
|
+import java.util.TimerTask;
|
|
|
+
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 创建日期:2022/5/17 13:33
|
|
|
+ *
|
|
|
+ * @author Ryan
|
|
|
+ * 类说明:
|
|
|
+ */
|
|
|
+@Route(path = RouterPath.UserCenter.MINE_MODIFY_PASSWORD)
|
|
|
+public class ModifyPasswordActivity extends BaseMVPActivity<AcModifyPasswordBinding, ModifyPasswordPresenter> implements ModifyPasswordContract.ModifyPasswordView, View.OnClickListener {
|
|
|
+
|
|
|
+ private ImgVerifyCodeDialog mImgVerifyCodeDialog;
|
|
|
+ private boolean isNeedSmsCode = true;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired(name = "phoneNum")
|
|
|
+ String phoneNum;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ int id = view.getId();
|
|
|
+ if (id == R.id.tv_confirm) {
|
|
|
+ String password = viewBinding.etPassword.getText().toString().trim();
|
|
|
+ String password2 = viewBinding.etPassword2.getText().toString().trim();
|
|
|
+ if (!checkPwd(password, password2)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String authCode = viewBinding.etAuthCode.getText().toString().trim();
|
|
|
+ if (isNeedSmsCode && TextUtils.isEmpty(authCode)) {
|
|
|
+ ToastUtil.getInstance().showShort("请输入验证码");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
+ params.put("id", UserHelper.getUserId());
|
|
|
+ if (!TextUtils.isEmpty(authCode)) {
|
|
|
+ params.put("code", authCode);
|
|
|
+ }
|
|
|
+ params.put("password", password);
|
|
|
+ presenter.updatePassword(params);
|
|
|
+ } else if (id == R.id.tv_get_auth_code) {
|
|
|
+ showImgVerifyCodeDialog();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkPwd(String pwd, String pwd2) {
|
|
|
+ if (TextUtils.isEmpty(pwd) || pwd.length() < 6 || pwd.length() > 20) {
|
|
|
+ ToastUtil.getInstance().showShort("请输入6-20位密码");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(pwd2) || pwd2.length() < 6 || pwd2.length() > 20) {
|
|
|
+ ToastUtil.getInstance().showShort("请输入6-20位密码");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!TextUtils.equals(pwd, pwd2)) {
|
|
|
+ ToastUtil.getInstance().showShort("两次密码输入不一致");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
+ StyleConfig.setTheme(this);
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ QMUIStatusBarHelper.setStatusBarLightMode(this);
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ protected void initView() {
|
|
|
+ ARouter.getInstance().inject(this);
|
|
|
+ initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "修改密码");
|
|
|
+ isNeedSmsCode = getIntent().getBooleanExtra("isNeedSmsCode", true);
|
|
|
+ viewBinding.groupCode.setVisibility(isNeedSmsCode ? View.VISIBLE : View.GONE);
|
|
|
+
|
|
|
+ viewBinding.tvConfirm.setOnClickListener(this);
|
|
|
+ viewBinding.tvGetAuthCode.setOnClickListener(this);
|
|
|
+ if (!TextUtils.isEmpty(phoneNum)) {
|
|
|
+ try {
|
|
|
+ String cPhone = phoneNum.substring(0, 3) + "****" + phoneNum.substring(7, phoneNum.length());
|
|
|
+ viewBinding.tvPhone.setText(cPhone);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void showImgVerifyCodeDialog() {
|
|
|
+ if (mImgVerifyCodeDialog == null) {
|
|
|
+ mImgVerifyCodeDialog = new ImgVerifyCodeDialog(ModifyPasswordActivity.this);
|
|
|
+ }
|
|
|
+ if (!mImgVerifyCodeDialog.isShowing()) {
|
|
|
+ mImgVerifyCodeDialog.show();
|
|
|
+ }
|
|
|
+ mImgVerifyCodeDialog.setPhone(phoneNum);
|
|
|
+ mImgVerifyCodeDialog.setOnEventListener(new ImgVerifyCodeDialog.OnEventListener() {
|
|
|
+ @Override
|
|
|
+ public void onVerifyImgCode(String phone, String imgCode) {
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.verifyImgCode(phone, imgCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected AcModifyPasswordBinding getLayoutView() {
|
|
|
+ return AcModifyPasswordBinding.inflate(getLayoutInflater());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected ModifyPasswordPresenter createPresenter() {
|
|
|
+ return new ModifyPasswordPresenter();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updatePasswordSuccess(Object object) {
|
|
|
+ UserHelper.saveUserToken("");
|
|
|
+ ARouter.getInstance().build(RouterPath.UserCenter.PATH_VERIFY_LOGIN)
|
|
|
+ .withString(UserConstants.PHONE_NUM_KEY, UserHelper.getUserPhone())
|
|
|
+ .navigation();
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void sendSmsCodeSuccess(Object object) {
|
|
|
+ getCodeSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void verifyImgCodeSuccess(String phone) {
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (mImgVerifyCodeDialog != null) {
|
|
|
+ mImgVerifyCodeDialog.dismiss();
|
|
|
+ }
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("mobile", phone);
|
|
|
+ map.put("type", "PASSWD");
|
|
|
+ presenter.sendSmsCode(map);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void getCodeSuccess() {
|
|
|
+ ToastUtil.getInstance().showShort("验证码发送成功,请注意查收!");
|
|
|
+ startTimer();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 执行完成
|
|
|
+ */
|
|
|
+ public static final int EXECUTE_FINISH = 0X11000;
|
|
|
+ /**
|
|
|
+ * 执行中
|
|
|
+ */
|
|
|
+ public static final int EXECUTE_LOADING = 0X4000;
|
|
|
+ private int mTimerId = 60;
|
|
|
+
|
|
|
+ private TimerTask timerTask;
|
|
|
+
|
|
|
+ private Timer timer;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开始倒计时
|
|
|
+ */
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结束计时
|
|
|
+ */
|
|
|
+ private void closeTimer() {
|
|
|
+ if (timer != null) {
|
|
|
+ timer.cancel();
|
|
|
+ timer = null;
|
|
|
+ }
|
|
|
+ if (timerTask != null) {
|
|
|
+ timerTask = null;
|
|
|
+ }
|
|
|
+ mTimerId = 60;
|
|
|
+ handler.sendEmptyMessage(EXECUTE_FINISH);
|
|
|
+ }
|
|
|
+
|
|
|
+ @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() {
|
|
|
+ super.onDestroy();
|
|
|
+ if (timer != null) {
|
|
|
+ timer.cancel();
|
|
|
+ timer = null;
|
|
|
+ }
|
|
|
+ if (timerTask != null) {
|
|
|
+ timerTask = null;
|
|
|
+ }
|
|
|
+ if (handler != null) {
|
|
|
+ handler.removeCallbacksAndMessages(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|