|
|
@@ -2,27 +2,74 @@ package com.itant.shibei.ui.mine.login.register;
|
|
|
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
+import android.widget.Button;
|
|
|
|
|
|
-import androidx.annotation.Nullable;
|
|
|
+import androidx.annotation.NonNull;
|
|
|
|
|
|
+import com.google.android.material.textfield.TextInputEditText;
|
|
|
import com.itant.shibei.R;
|
|
|
import com.itant.shibei.base.BaseShiBeiActivity;
|
|
|
+import com.itant.shibei.ui.mine.login.register.fill.FillDataActivity;
|
|
|
+import com.miekir.common.utils.ToastTool;
|
|
|
+import com.miekir.common.utils.ViewTool;
|
|
|
+import com.miekir.mvp.presenter.InjectPresenter;
|
|
|
+
|
|
|
+import java.lang.ref.WeakReference;
|
|
|
+
|
|
|
+import rx_activity_result2.RxActivityResult;
|
|
|
|
|
|
/**
|
|
|
- * @author 詹子聪
|
|
|
+ * @author Miekir
|
|
|
* @date 2020/6/18 16:48
|
|
|
* Description: 登录界面
|
|
|
*/
|
|
|
-public class RegisterActivity extends BaseShiBeiActivity implements View.OnClickListener {
|
|
|
- @Override
|
|
|
- protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- findViewById(R.id.btn_next).setOnClickListener(v -> {
|
|
|
- startActivity(new Intent(RegisterActivity.this, FillDataActivity.class));
|
|
|
- finish();
|
|
|
- });
|
|
|
+public class RegisterActivity extends BaseShiBeiActivity implements View.OnClickListener, ICodeView {
|
|
|
+ public static final String KEY_EMAIL = "email";
|
|
|
+ public static final String KEY_CODE = "code";
|
|
|
+
|
|
|
+ private TextInputEditText et_email;
|
|
|
+ private TextInputEditText et_code;
|
|
|
+ private Button btn_get_code;
|
|
|
+
|
|
|
+ private String email;
|
|
|
+ private String code;
|
|
|
+
|
|
|
+ @InjectPresenter
|
|
|
+ CodePresenter presenter;
|
|
|
+
|
|
|
+ /**验证码倒计时*/
|
|
|
+ private static final int MSG_TIME = 0;
|
|
|
+ private static final int TIME_GET_PERIOD = 61;
|
|
|
+ private int mRestTime = TIME_GET_PERIOD;
|
|
|
+ private static class TimeHandler extends Handler {
|
|
|
+ private WeakReference<RegisterActivity> weakReference;
|
|
|
+ public TimeHandler(RegisterActivity activity) {
|
|
|
+ weakReference = new WeakReference<>(activity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void handleMessage(@NonNull Message msg) {
|
|
|
+ super.handleMessage(msg);
|
|
|
+ RegisterActivity activity = weakReference.get();
|
|
|
+ if (activity == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ activity.mRestTime -= 1;
|
|
|
+ if (activity.mRestTime == 0) {
|
|
|
+ activity.btn_get_code.setText("获取验证码");
|
|
|
+ activity.btn_get_code.setEnabled(true);
|
|
|
+ activity.mRestTime = TIME_GET_PERIOD;
|
|
|
+ } else {
|
|
|
+ activity.btn_get_code.setText("重新获取(" + activity.mRestTime + "S)");
|
|
|
+ activity.mTimeHandler.sendEmptyMessageDelayed(MSG_TIME, 1000);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ private Handler mTimeHandler = new TimeHandler(this);
|
|
|
|
|
|
@Override
|
|
|
public int getLayoutID() {
|
|
|
@@ -32,13 +79,74 @@ public class RegisterActivity extends BaseShiBeiActivity implements View.OnClick
|
|
|
@Override
|
|
|
public void initViews(Bundle savedInstanceState) {
|
|
|
setTitle("使用电子邮箱注册");
|
|
|
+ ViewTool.setOnClickListener(this, this, new int[]{R.id.btn_get_code, R.id.btn_next});
|
|
|
+ et_email = findViewById(R.id.et_email);
|
|
|
+ et_code = findViewById(R.id.et_code);
|
|
|
+ btn_get_code = findViewById(R.id.btn_get_code);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
switch (v.getId()) {
|
|
|
+ case R.id.btn_next:
|
|
|
+ // 完善资料
|
|
|
+ if (TextUtils.isEmpty(email)) {
|
|
|
+ ToastTool.showShort("邮箱不能为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ code = et_code.getEditableText().toString();
|
|
|
+ if (TextUtils.isEmpty(code)) {
|
|
|
+ ToastTool.showShort("验证码不能为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Intent fillDataIntent = new Intent(this, FillDataActivity.class);
|
|
|
+ fillDataIntent.putExtra(KEY_EMAIL, email);
|
|
|
+ fillDataIntent.putExtra(KEY_CODE, code);
|
|
|
+ RxActivityResult.on(this).startIntent(fillDataIntent)
|
|
|
+ .filter(result -> result.resultCode() == RESULT_OK)
|
|
|
+ .subscribe(result -> {
|
|
|
+ // 注册成功之后关闭登录界面
|
|
|
+ setResult(RESULT_OK);
|
|
|
+ finish();
|
|
|
+ });
|
|
|
+ break;
|
|
|
+
|
|
|
+ case R.id.btn_get_code:
|
|
|
+ // 获取验证码
|
|
|
+ email = et_email.getEditableText().toString();
|
|
|
+ if (TextUtils.isEmpty(email)) {
|
|
|
+ ToastTool.showShort("邮箱不能为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ showLoading();
|
|
|
+ presenter.getCode(email);
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGetCode(boolean isSuccess, String message) {
|
|
|
+ dismissLoading();
|
|
|
+ if (isSuccess) {
|
|
|
+ ToastTool.showShort("验证码发送成功");
|
|
|
+ btn_get_code.setEnabled(false);
|
|
|
+ mTimeHandler.sendEmptyMessage(MSG_TIME);
|
|
|
+ } else {
|
|
|
+ if (TextUtils.isEmpty(message)) {
|
|
|
+ ToastTool.showShort("验证码发送失败");
|
|
|
+ } else {
|
|
|
+ ToastTool.showShort(message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ mTimeHandler.removeMessages(MSG_TIME);
|
|
|
+ }
|
|
|
}
|