+ * hideSoftInputFromWindow 隐藏键盘
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
- if (event.getAction() == MotionEvent.ACTION_DOWN){
+ if (event.getAction() == MotionEvent.ACTION_DOWN) {
//隐藏键盘
//1.获取系统输入的管理器
InputMethodManager inputManager =
(InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
//2.隐藏键盘
- inputManager.hideSoftInputFromWindow(binding.etUser.getWindowToken(),0);
+ inputManager.hideSoftInputFromWindow(binding.etUser.getWindowToken(), 0);
//3.取消焦点
View focusView = getCurrentFocus();
@@ -209,18 +219,28 @@ public class LoginActivity extends BaseActivity implements TextWatcher {
//判断两个输入框是否有内容
if (binding.etUser.getEditText().getText().toString().length() > 0 &&
binding.etPassword.getEditText().getText().toString().length() > 0 &&
- binding.etCaptcha.getEditText().getText().toString().length() > 0){
+ binding.etCaptcha.getEditText().getText().toString().length() > 0) {
//按钮可以点击
binding.btLogin.setEnabled(true);
- }else{
+ } else {
//按钮不能点击
binding.btLogin.setEnabled(false);
}
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (resultCode == Activity.RESULT_OK) {
+ if (requestCode == APPCONST.REQUEST_AUTH_EMAIL) {
+ loginSuccess();
+ }
+ }
+ }
+
@Override
protected void onDestroy() {
+ dialog.dismiss();
super.onDestroy();
- ProgressUtils.dismiss();
}
}
diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/RegisterActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/RegisterActivity.java
index 55111f7..d725a22 100644
--- a/app/src/main/java/xyz/fycz/myreader/ui/activity/RegisterActivity.java
+++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/RegisterActivity.java
@@ -2,6 +2,7 @@ package xyz.fycz.myreader.ui.activity;
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
+import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
@@ -9,17 +10,28 @@ import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.view.View;
+import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import java.util.HashMap;
import java.util.Map;
+import io.reactivex.disposables.Disposable;
import xyz.fycz.myreader.R;
+import xyz.fycz.myreader.application.App;
import xyz.fycz.myreader.base.BaseActivity;
+import xyz.fycz.myreader.base.MyTextWatcher;
+import xyz.fycz.myreader.base.observer.MySingleObserver;
+import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.databinding.ActivityRegisterBinding;
-import xyz.fycz.myreader.model.backup.UserService;
+import xyz.fycz.myreader.model.user.Result;
+import xyz.fycz.myreader.model.user.User;
+import xyz.fycz.myreader.model.user.UserService;
+import xyz.fycz.myreader.model.user.UserService2;
import xyz.fycz.myreader.ui.dialog.DialogCreator;
+import xyz.fycz.myreader.ui.dialog.LoadingDialog;
import xyz.fycz.myreader.util.CodeUtil;
+import xyz.fycz.myreader.util.CyptoUtils;
import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.utils.ProgressUtils;
import xyz.fycz.myreader.util.utils.StringUtils;
@@ -36,27 +48,12 @@ public class RegisterActivity extends BaseActivity {
private String code;
private String username = "";
private String password = "";
- private String rpPassword = "";
+ private String email = "";
+ private String emailCode = "";
+ private String keyc = "";
private String inputCode = "";
-
- @SuppressLint("HandlerLeak")
- private Handler mHandler = new Handler() {
- @SuppressLint("HandlerLeak")
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case 1:
- createCaptcha();
- break;
- case 2:
- showTip((String) msg.obj);
- break;
- case 3:
- binding.tvRegisterTip.setVisibility(View.GONE);
- break;
- }
- }
- };
+ private LoadingDialog dialog;
+ private Disposable disp;
@Override
protected void bindView() {
@@ -71,164 +68,178 @@ public class RegisterActivity extends BaseActivity {
getSupportActionBar().setTitle("注册");
}
+ @Override
+ protected void initData(Bundle savedInstanceState) {
+ dialog = new LoadingDialog(this, "正在注册", () -> {
+ if (disp != null) {
+ disp.dispose();
+ }
+ });
+ }
+
@Override
protected void initWidget() {
super.initWidget();
- mHandler.sendMessage(mHandler.obtainMessage(1));
+ createCaptcha();
binding.etUsername.requestFocus();
- binding.etUsername.getEditText().addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
-
- }
-
+ binding.etUsername.getEditText().addTextChangedListener(new MyTextWatcher() {
@Override
public void afterTextChanged(Editable s) {
StringUtils.isNotChinese(s);
username = s.toString();
- if (username.length() < 6 || username.length() >14){
- mHandler.sendMessage(mHandler.obtainMessage(2, "用户名必须在6-14位之间"));
- } else if(!username.substring(0, 1).matches("^[A-Za-z]$")){
- mHandler.sendMessage(mHandler.obtainMessage(2,
- "用户名只能以字母开头"));
- }else if(!username.matches("^[A-Za-z0-9-_]+$")){
- mHandler.sendMessage(mHandler.obtainMessage(2,
- "用户名只能由数字、字母、下划线、减号组成"));
- }else {
- mHandler.sendMessage(mHandler.obtainMessage(3));
+ if (username.length() < 6 || username.length() > 14) {
+ showTip("用户名必须在6-14位之间");
+ } else if (!username.substring(0, 1).matches("^[A-Za-z]$")) {
+ showTip("用户名只能以字母开头");
+ } else if (!username.matches("^[A-Za-z0-9-_]+$")) {
+ showTip("用户名只能由数字、字母、下划线、减号组成");
+ } else {
+ binding.tvRegisterTip.setVisibility(View.GONE);
}
checkNotNone();
}
});
- binding.etPassword.getEditText().addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
-
- }
-
+ binding.etPassword.getEditText().addTextChangedListener(new MyTextWatcher() {
@Override
public void afterTextChanged(Editable s) {
password = s.toString();
- if (password.length() < 8 || password.length() > 16){
- mHandler.sendMessage(mHandler.obtainMessage(2, "密码必须在8-16位之间"));
- } else if(password.matches("^\\d+$")){
- mHandler.sendMessage(mHandler.obtainMessage(2, "密码不能是纯数字"));
+ if (password.length() < 8 || password.length() > 16) {
+ showTip("密码必须在8-16位之间");
+ } else if (password.matches("^\\d+$")) {
+ showTip("密码不能是纯数字");
} else {
- mHandler.sendMessage(mHandler.obtainMessage(3));
+ binding.tvRegisterTip.setVisibility(View.GONE);
}
checkNotNone();
}
});
- binding.etRpPassword.getEditText().addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
-
- }
-
+ binding.etEmail.getEditText().addTextChangedListener(new MyTextWatcher() {
@Override
public void afterTextChanged(Editable s) {
- rpPassword = s.toString();
- if (!rpPassword.equals(password)){
- mHandler.sendMessage(mHandler.obtainMessage(2, "两次输入的密码不一致"));
+ email = s.toString();
+ if (!email.matches("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,})$")) {
+ showTip("邮箱格式错误");
} else {
- mHandler.sendMessage(mHandler.obtainMessage(3));
+ binding.tvRegisterTip.setVisibility(View.GONE);
}
checkNotNone();
}
});
- binding.etCaptcha.getEditText().addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-
- }
-
+ binding.etEmailCode.getEditText().addTextChangedListener(new MyTextWatcher() {
@Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
-
+ public void afterTextChanged(Editable s) {
+ emailCode = s.toString().trim();
+ checkNotNone();
}
+ });
+ binding.etCaptcha.getEditText().addTextChangedListener(new MyTextWatcher() {
@Override
public void afterTextChanged(Editable s) {
inputCode = s.toString().trim().toLowerCase();
- if (!inputCode.equals(code.toLowerCase())){
- mHandler.sendMessage(mHandler.obtainMessage(2, "验证码错误"));
+ if (!inputCode.equals(code.toLowerCase())) {
+ showTip("验证码错误");
} else {
- mHandler.sendMessage(mHandler.obtainMessage(3));
+ binding.tvRegisterTip.setVisibility(View.GONE);
}
checkNotNone();
}
});
- binding.tvAgreement.setMovementMethod(LinkMovementMethod.getInstance());
-
+ binding.cbAgreement.setMovementMethod(LinkMovementMethod.getInstance());
}
@Override
protected void initClick() {
super.initClick();
- binding.ivCaptcha.setOnClickListener(v -> mHandler.sendMessage(mHandler.obtainMessage(1)));
+ binding.ivCaptcha.setOnClickListener(v -> createCaptcha());
+ binding.tvGetEmailCode.setOnClickListener(v -> {
+ if (!email.matches("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,})$")) {
+ ToastUtils.showWarring("请正确输入邮箱");
+ return;
+ }
+ dialog.show();
+ dialog.setmMessage("正在发送");
+ UserService2.INSTANCE.sendEmail(email, "reg", keyc).subscribe(new MySingleObserver yuSG1b@h_98?w|Jlf|?hJV;Kt+6V37i9YRV;*rgVd
zZdZd@e}0b9t<%$61GQXUU)7_kjz4d!_&2UB>c%Cm`rYsnl+tp;3$ZSmXw!v`Gi7P(
z ~l;(!#$yEw6#0}MboOQO{=Xeaf=3ODa7*fhY+
ziAvVZkn8@dQ3dnmj@MBV#6LTCW=t5gaz$Qy3<8R_ox$h_f|D^82(t0RIu)Swv#NkR
z_7`L`F(TVs)H;)(=pj(+`FWDSRlGH~w$AtVnpZh>IAnI`d!ne)NoGs80!kh+z6_rt
z*c?6C$AT%%HdUFl0)}}6g&P7dw84P}Gqrf{uMLF{=?qM{z4WGgCTvY8ElL>%n)F(j
z6khB)3b$9xjQ`4PEs;98sK?x!XSwQ4k^su<;>sVWB(!2sB-Qf|E5c6pbdz{~j7EHI
zFpOZ^K734eY+iyFwii2#6i7TT3j`g>Lh*)XgWW72iPOOAX`|qe+v2Daq-^YJdOA}>m@^;ZO2@8p$&
zcv!11dBhTJV>2`vgtM1W+%E^)?n&$s^07TAB*@pgkAXPtZNJB5&S
zJ!!lD{>ua~Zx}R9aivSdSN8CtZUyU~s`ETIL*zP;B#|bu(u_F|a&8N=cgv9+u==dM
z7@MMB{y_VEm5gvS-o=*pS%T9%rJvSb_^KW%U485Q*@-C0fk;F=sK@E|m@$ka<)lpL
zdK?IK>_WIr%F36amGcT0T(Aj!Q*JjHT;k$fS+Zv8>AO)q`WI^f;T-HVY6@mMAJVI8
zC74|-T=kV8Bu`Zx^^=+pBL?54>6^irV=FjVxFVy=oKgd$Xl)^yFla}|t?0L=vUV9F
z!qa>>TpRg0^n%q~lADSr}3_R{fme;Ok$><{>h!&
ze}G^D1527K$K3r)pFTvZqUL-gQ!}DkB+b_BgBg755nt*VRj-
z^=}#kS;b*G8D9atWXN)=T4E^F!A&qdyvr
X
zdz~BkCivlb?h_|N$1yF_aXTe4?cyYZhLJc)_~bJ5N14I>;YToq$`#I(tLStk^3Slf
z;{s5FO(7^?>ocmIIeNj93($0<#<)JauGj{HVweT