소스 검색

处理登录逻辑

Pq 3 년 전
부모
커밋
6b6ca5977a

+ 3 - 0
usercenter/src/main/java/com/cooleshow/usercenter/UserConstants.java

@@ -4,6 +4,9 @@ package com.cooleshow.usercenter;
  * Author by pq, Date on 2022/4/24.
  */
 public class UserConstants {
+    public static final String PHONE_NUM_KEY="phone_num_key";
     public static final String TEMP_TOKEN="temp_token";
+    public static final String LOGIN_STATUS="login_status";
+    public static final String LOGIN_STATUS_SUCCESS="login_success";
 
 }

+ 14 - 4
usercenter/src/main/java/com/cooleshow/usercenter/ui/activity/LoginActivity.kt

@@ -1,14 +1,15 @@
 package com.cooleshow.usercenter.ui.activity
 
+import android.content.Intent
 import android.os.Bundle
 import android.text.TextUtils
 import com.alibaba.android.arouter.facade.annotation.Route
-import com.alibaba.android.arouter.launcher.ARouter
 import com.cooleshow.base.ext.onClick
 import com.cooleshow.base.ui.activity.BaseMVPActivity
 import com.cooleshow.base.utils.ToastUtils
 import com.cooleshow.base.utils.helper.QMUIStatusBarHelper
 import com.cooleshow.provider.router.RouterPath
+import com.cooleshow.usercenter.UserConstants
 import com.cooleshow.usercenter.bean.UserInfo
 import com.cooleshow.usercenter.databinding.ActivityLoginBinding
 import com.cooleshow.usercenter.helper.UserHelper
@@ -35,9 +36,12 @@ class LoginActivity : BaseMVPActivity<ActivityLoginBinding, LoginPresenter>(),
 
     override fun initView() {
         tv_login_by_code.onClick {
-            ARouter.getInstance().build(RouterPath.UserCenter.PATH_VERIFY_LOGIN).navigation()
+            finish()
+        }
+        var phone: String? = intent.getStringExtra(UserConstants.PHONE_NUM_KEY);
+        if (!TextUtils.isEmpty(phone)) {
+            viewBinding.etPhoneNum.setText(phone);
         }
-
         mLoginBtn.setOnClickListener {
             if (TextUtils.isEmpty(et_phone_num?.text)) {
                 ToastUtils.showShort("手机号不可为空")
@@ -59,7 +63,13 @@ class LoginActivity : BaseMVPActivity<ActivityLoginBinding, LoginPresenter>(),
             return;
         }
         UserHelper.handleLoginSuccessAction(result)
-        ARouter.getInstance().build(RouterPath.APPCenter.PATH_HOME).navigation()
+        setLoginResult()
     }
 
+    private fun setLoginResult() {
+        val intent = Intent()
+        intent.putExtra(UserConstants.LOGIN_STATUS, UserConstants.LOGIN_STATUS_SUCCESS)
+        setResult(RESULT_OK, intent)
+        finish()
+    }
 }

+ 10 - 5
usercenter/src/main/java/com/cooleshow/usercenter/ui/activity/VerifyCodeInputActivity.java

@@ -178,8 +178,7 @@ public class VerifyCodeInputActivity extends BaseMVPActivity<ActivityInputCodeLa
             if (data.password) {
                 //有设置密码
                 UserHelper.handleLoginSuccessAction(data);
-                ARouter.getInstance().build(RouterPath.APPCenter.PATH_HOME).navigation();
-                AppManager.Companion.getInstance().finishAllActivity();
+                setLoginResult();
             } else {
                 //无密码,跳设置密码
                 String tempToken = UserHelper.handleLoginSuccessActionNotSave(data);
@@ -194,13 +193,19 @@ public class VerifyCodeInputActivity extends BaseMVPActivity<ActivityInputCodeLa
         if (resultCode == RESULT_OK) {
             if (requestCode == REQUEST_CODE_FOR_SET_PASSWORD) {
                 //设置密码成功
-                if(data!=null){
+                if (data != null) {
                     String tokenResult = data.getStringExtra(UserConstants.TEMP_TOKEN);
                     UserHelper.saveUserToken(tokenResult);
-                    ARouter.getInstance().build(RouterPath.APPCenter.PATH_HOME).navigation();
-                    AppManager.Companion.getInstance().finishAllActivity();
+                    setLoginResult();
                 }
             }
         }
     }
+
+    private void setLoginResult() {
+        Intent intent = new Intent();
+        intent.putExtra(UserConstants.LOGIN_STATUS, UserConstants.LOGIN_STATUS_SUCCESS);
+        setResult(RESULT_OK, intent);
+        finish();
+    }
 }

+ 42 - 12
usercenter/src/main/java/com/cooleshow/usercenter/ui/activity/VerifyCodeLoginActivity.java

@@ -1,15 +1,19 @@
 package com.cooleshow.usercenter.ui.activity;
 
+import android.content.Intent;
 import android.os.Bundle;
 import android.text.TextUtils;
 import android.view.View;
 
 import com.alibaba.android.arouter.facade.annotation.Route;
 import com.alibaba.android.arouter.launcher.ARouter;
+import com.cooleshow.base.common.AppManager;
 import com.cooleshow.base.ui.activity.BaseMVPActivity;
 import com.cooleshow.base.utils.ToastUtils;
 import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
 import com.cooleshow.provider.router.RouterPath;
+import com.cooleshow.usercenter.R;
+import com.cooleshow.usercenter.UserConstants;
 import com.cooleshow.usercenter.bean.UserInfo;
 import com.cooleshow.usercenter.databinding.ActivityVerifyCodeLoginBinding;
 import com.cooleshow.usercenter.helper.PhoneCheckHelper;
@@ -23,7 +27,8 @@ import androidx.annotation.Nullable;
  * Author by pq, Date on 2022/4/19.
  */
 @Route(path = RouterPath.UserCenter.PATH_VERIFY_LOGIN)
-public class VerifyCodeLoginActivity extends BaseMVPActivity<ActivityVerifyCodeLoginBinding, VerifyLoginPresenter> {
+public class VerifyCodeLoginActivity extends BaseMVPActivity<ActivityVerifyCodeLoginBinding, VerifyLoginPresenter> implements View.OnClickListener {
+    public static final int LOGIN_STATUS_REQUEST_CODE = 10000002;
 
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -39,17 +44,8 @@ public class VerifyCodeLoginActivity extends BaseMVPActivity<ActivityVerifyCodeL
 
     @Override
     protected void initView() {
-        viewBinding.tvSendVerifyCode.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                String phone = viewBinding.etPhoneNum.getText().toString();
-                if (PhoneCheckHelper.checkPhoneValidity(phone)) {
-                    ARouter.getInstance().build(RouterPath.UserCenter.PATH_VERIFY_INPUT)
-                            .withString(VerifyCodeInputActivity.TARGET_PHONE, phone)
-                            .navigation();
-                }
-            }
-        });
+        viewBinding.tvSendVerifyCode.setOnClickListener(this);
+        viewBinding.tvLoginByCode.setOnClickListener(this);
     }
 
 
@@ -58,4 +54,38 @@ public class VerifyCodeLoginActivity extends BaseMVPActivity<ActivityVerifyCodeL
         return new VerifyLoginPresenter();
     }
 
+    @Override
+    public void onClick(View v) {
+        if (v.getId() == R.id.tv_login_by_code) {
+            //密码登录
+            String phone = viewBinding.etPhoneNum.getText().toString();
+            ARouter.getInstance().build(RouterPath.UserCenter.PATH_LOGIN)
+                    .withString(UserConstants.PHONE_NUM_KEY, phone).navigation(this, LOGIN_STATUS_REQUEST_CODE);
+        }
+
+        if (v.getId() == R.id.tv_send_verify_code) {
+            //获取验证码
+            String phone = viewBinding.etPhoneNum.getText().toString();
+            if (PhoneCheckHelper.checkPhoneValidity(phone)) {
+                ARouter.getInstance().build(RouterPath.UserCenter.PATH_VERIFY_INPUT)
+                        .withString(VerifyCodeInputActivity.TARGET_PHONE, phone)
+                        .navigation(this, LOGIN_STATUS_REQUEST_CODE);
+            }
+        }
+    }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+        if (resultCode == RESULT_OK) {
+            if (data != null && requestCode == LOGIN_STATUS_REQUEST_CODE) {
+                String status = data.getStringExtra(UserConstants.LOGIN_STATUS);
+                if (TextUtils.equals(status, UserConstants.LOGIN_STATUS_SUCCESS)) {
+                    //跳转首页
+                    ARouter.getInstance().build(RouterPath.APPCenter.PATH_HOME).navigation();
+                    finish();
+                }
+            }
+        }
+    }
 }

+ 0 - 1
usercenter/src/main/res/layout/activity_login.xml

@@ -91,7 +91,6 @@
         android:hint="@string/please_input_pwd"
         android:inputType="textPassword"
         android:paddingLeft="@dimen/common_padding_small"
-        android:text="123456"
         android:textColorHint="@color/color_ffc1c1c1"
         app:layout_constraintLeft_toLeftOf="@+id/et_phone_num"
         app:layout_constraintRight_toRightOf="@+id/et_phone_num"

+ 1 - 0
usercenter/src/main/res/layout/activity_verify_code_login.xml

@@ -44,6 +44,7 @@
 
 
     <EditText
+        android:text="13627281518"
         android:id="@+id/et_phone_num"
         android:layout_width="match_parent"
         android:layout_height="@dimen/common_line_height"