|
|
@@ -1,24 +1,40 @@
|
|
|
package com.itant.shibei.ui.mine.forget;
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
|
|
|
-import androidx.annotation.Nullable;
|
|
|
-
|
|
|
+import com.google.android.material.textfield.TextInputEditText;
|
|
|
import com.itant.shibei.R;
|
|
|
import com.itant.shibei.base.BaseBeiActivity;
|
|
|
+import com.itant.shibei.bean.BeiUser;
|
|
|
+import com.itant.shibei.manager.UserInfoManager;
|
|
|
+import com.itant.shibei.tool.StringTool;
|
|
|
+import com.itant.shibei.ui.mine.register.CodePresenter;
|
|
|
+import com.itant.shibei.ui.mine.register.ICodeView;
|
|
|
+import com.miekir.common.utils.ToastTool;
|
|
|
+import com.miekir.common.utils.ViewTool;
|
|
|
+import com.miekir.mvp.presenter.InjectPresenter;
|
|
|
|
|
|
/**
|
|
|
* @author Miekir
|
|
|
* @date 2020/6/18 16:48
|
|
|
* Description: 登录界面
|
|
|
*/
|
|
|
-public class ForgetActivity extends BaseBeiActivity implements View.OnClickListener {
|
|
|
- @Override
|
|
|
- protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
+public class ForgetActivity extends BaseBeiActivity implements View.OnClickListener, ICodeView, IForgetView {
|
|
|
+ private TextInputEditText et_email;
|
|
|
+ private TextInputEditText et_code;
|
|
|
+ private TextInputEditText et_new_password;
|
|
|
|
|
|
- }
|
|
|
+ private String email;
|
|
|
+ private String code;
|
|
|
+ private String password;
|
|
|
+
|
|
|
+ @InjectPresenter
|
|
|
+ private CodePresenter mCodePresenter;
|
|
|
+
|
|
|
+ @InjectPresenter
|
|
|
+ private ForgetPresenter mForgetPresenter;
|
|
|
|
|
|
@Override
|
|
|
public int getLayoutID() {
|
|
|
@@ -28,14 +44,83 @@ public class ForgetActivity extends BaseBeiActivity implements View.OnClickListe
|
|
|
@Override
|
|
|
public void initViews(Bundle savedInstanceState) {
|
|
|
setTitle("重置密码");
|
|
|
+
|
|
|
+ et_email = findViewById(R.id.et_email);
|
|
|
+ et_code = findViewById(R.id.et_code);
|
|
|
+ et_new_password = findViewById(R.id.et_new_password);
|
|
|
+ ViewTool.setOnClickListener(this, this,
|
|
|
+ new int[]{R.id.btn_get_code, R.id.btn_reset_password});
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
switch (v.getId()) {
|
|
|
+ case R.id.btn_get_code:
|
|
|
+ // 获取验证码
|
|
|
+ email = et_email.getEditableText().toString();
|
|
|
+ if (TextUtils.isEmpty(email)) {
|
|
|
+ ToastTool.showShort("邮箱不能为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ showLoading();
|
|
|
+ mCodePresenter.getCode(email);
|
|
|
+ break;
|
|
|
+ case R.id.btn_reset_password:
|
|
|
+ email = et_email.getEditableText().toString();
|
|
|
+ if (TextUtils.isEmpty(email)) {
|
|
|
+ ToastTool.showShort("邮箱不能为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!email.contains("@")) {
|
|
|
+ ToastTool.showShort("请输入合法的邮箱");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 重设密码
|
|
|
+ code = et_code.getEditableText().toString();
|
|
|
+ if (TextUtils.isEmpty(code)) {
|
|
|
+ ToastTool.showShort("验证码不能为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ password = et_new_password.getEditableText().toString();
|
|
|
+ if (TextUtils.isEmpty(password)) {
|
|
|
+ ToastTool.showShort("新密码不能为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String encodePassword = StringTool.getEncodeString(password);
|
|
|
+ showLoading();
|
|
|
+ mForgetPresenter.submitReset(email, code, encodePassword);
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGetCode(boolean isSuccess, String message) {
|
|
|
+ dismissLoading();
|
|
|
+ if (isSuccess) {
|
|
|
+ ToastTool.showShort("验证码发送成功");
|
|
|
+ } else {
|
|
|
+ ToastTool.showShort(message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onForgetResult(BeiUser user, String message) {
|
|
|
+ dismissLoading();
|
|
|
+ if (user != null) {
|
|
|
+ UserInfoManager.getInstance().setBeiUser(user);
|
|
|
+ ToastTool.showShort("重设密码成功");
|
|
|
+ setResult(RESULT_OK);
|
|
|
+ finish();
|
|
|
+ } else {
|
|
|
+ ToastTool.showShort(message);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|