1:修改手机换绑倒计时添加管理类
This commit is contained in:
@@ -13,10 +13,17 @@ import com.hjq.toast.ToastUtils;
|
||||
import com.xscm.modulemain.activity.user.conacts.PhoneReplacementConacts;
|
||||
import com.xscm.modulemain.activity.user.presenter.PhoneReplacementPresenter;
|
||||
import com.xscm.modulemain.BaseMvpActivity;
|
||||
import com.xscm.modulemain.utils.CountDownManager;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
import com.xscm.moduleutil.color.ThemeableDrawableUtils;
|
||||
import com.xscm.moduleutil.utils.ColorManager;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
import com.xscm.moduleutil.utils.TimeUtils;
|
||||
import com.xscm.moduleutil.utils.TimerManager;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import kotlin.Unit;
|
||||
|
||||
/**
|
||||
* @author
|
||||
@@ -24,7 +31,7 @@ import com.xscm.moduleutil.utils.SpUtil;
|
||||
* @description: 手机换绑
|
||||
*/
|
||||
public class PhoneReplacementActivity extends BaseMvpActivity<PhoneReplacementPresenter, ActivityPhoneReplacementBinding> implements PhoneReplacementConacts.View {
|
||||
private CountDownTimer mTimer;
|
||||
private CountDownManager countDownManager;
|
||||
private String mobile;
|
||||
private String type;//1:更换手机 2:绑定手机
|
||||
|
||||
@@ -86,9 +93,9 @@ public class PhoneReplacementActivity extends BaseMvpActivity<PhoneReplacementPr
|
||||
MvpPre.sendCode(mBinding.edPhone.getText().toString(), type, mBinding.tvSendCode);
|
||||
|
||||
} else if (view.getId() == R.id.btnSubmit) {
|
||||
if (type.equals("1")){
|
||||
if (type.equals("1")) {
|
||||
|
||||
if(mBinding.edTheOldPassword.getText().toString().isEmpty()){
|
||||
if (mBinding.edTheOldPassword.getText().toString().isEmpty()) {
|
||||
com.blankj.utilcode.util.ToastUtils.showShort("请输入旧手机验证码");
|
||||
return;
|
||||
}
|
||||
@@ -101,11 +108,11 @@ public class PhoneReplacementActivity extends BaseMvpActivity<PhoneReplacementPr
|
||||
com.blankj.utilcode.util.ToastUtils.showShort("请输入验证码");
|
||||
return;
|
||||
}
|
||||
if (MvpPre!=null){
|
||||
MvpPre.mobileView(SpUtil.getUserBean().getMobile(), mBinding.edPhone.getText().toString(),mBinding.edTheOldPassword.getText().toString(), mBinding.edPassword.getText().toString(), type);
|
||||
if (MvpPre != null) {
|
||||
MvpPre.mobileView(SpUtil.getUserBean().getMobile(), mBinding.edPhone.getText().toString(), mBinding.edTheOldPassword.getText().toString(), mBinding.edPassword.getText().toString(), type);
|
||||
}
|
||||
|
||||
}else if (type.equals("2")){
|
||||
} else if (type.equals("2")) {
|
||||
if (mBinding.edPhone.getText().toString().isEmpty()) {
|
||||
com.blankj.utilcode.util.ToastUtils.showShort("请输入手机号");
|
||||
return;
|
||||
@@ -114,8 +121,8 @@ public class PhoneReplacementActivity extends BaseMvpActivity<PhoneReplacementPr
|
||||
com.blankj.utilcode.util.ToastUtils.showShort("请输入验证码");
|
||||
return;
|
||||
}
|
||||
if (MvpPre!=null){
|
||||
MvpPre.mobileView("", mBinding.edPhone.getText().toString(), mBinding.edPassword.getText().toString(),"", type);
|
||||
if (MvpPre != null) {
|
||||
MvpPre.mobileView("", mBinding.edPhone.getText().toString(), mBinding.edPassword.getText().toString(), "", type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,42 +137,52 @@ public class PhoneReplacementActivity extends BaseMvpActivity<PhoneReplacementPr
|
||||
}
|
||||
}
|
||||
|
||||
public void sendCodeSuccess2(String phoneNumber,TextView textView) {
|
||||
public void sendCodeSuccess2(String phoneNumber, TextView textView) {
|
||||
com.blankj.utilcode.util.ToastUtils.showShort("短信验证码发送成功请注意查收");
|
||||
textView.setEnabled(false);
|
||||
textView.setAlpha(0.5f);
|
||||
releaseTimer();
|
||||
if (mTimer != null) {
|
||||
mTimer.cancel();
|
||||
}
|
||||
mTimer = new CountDownTimer(60000L, 1000L) {
|
||||
@Override
|
||||
public void onTick(long millisUntilFinished) {
|
||||
if (textView != null) {
|
||||
textView.setText(String.format("重新发送(%s)", millisUntilFinished / 1000));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
textView.setAlpha(1f);
|
||||
textView.setEnabled(true);
|
||||
textView.setText("重新发送");
|
||||
// 获取CountDownManager单例实例
|
||||
if (countDownManager == null) {
|
||||
countDownManager = CountDownManager.Companion.getInstance();
|
||||
}
|
||||
|
||||
// 使用手机号作为tag来标识不同的倒计时任务
|
||||
String tag = "countdown_" + textView.hashCode();
|
||||
|
||||
// 开始倒计时,60秒
|
||||
countDownManager.startCountDown(
|
||||
tag,
|
||||
60,
|
||||
1000,
|
||||
(remainingSeconds, tagParam) -> {
|
||||
// 倒计时进行中
|
||||
if (textView != null) {
|
||||
textView.setText(String.format("重新发送(%s)", remainingSeconds));
|
||||
}
|
||||
return null;
|
||||
},
|
||||
tagParam -> {
|
||||
// 倒计时结束
|
||||
if (textView != null) {
|
||||
textView.setAlpha(1f);
|
||||
textView.setEnabled(true);
|
||||
textView.setText("重新发送");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
mTimer.start();
|
||||
);
|
||||
}
|
||||
|
||||
private void releaseTimer() {
|
||||
if (mTimer != null) {
|
||||
mTimer.cancel();
|
||||
mTimer = null;
|
||||
if (countDownManager != null) {
|
||||
countDownManager.cancelAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendCodeSuccess1(String phoneNumber, TextView textView) {
|
||||
sendCodeSuccess2(mBinding.edPhone.getText().toString(),textView);
|
||||
sendCodeSuccess2(mBinding.edPhone.getText().toString(), textView);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -177,10 +194,10 @@ public class PhoneReplacementActivity extends BaseMvpActivity<PhoneReplacementPr
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
releaseTimer();
|
||||
finish();
|
||||
} else {
|
||||
ToastUtils.show(s);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user