Kaynağa Gözat

feat: PhoneLoginActivity,手机登录流程

XiaodongLin 1 yıl önce
ebeveyn
işleme
b3c4f64579

+ 1 - 0
app/src/main/java/com/adealink/weparty/module/network/data/ServerCode.kt

@@ -8,6 +8,7 @@ enum class ServerCode(val code: Int) {
     TOKEN_EXPIRE(501), //token过期
     TOKEN_EXPIRE(501), //token过期
     NO_PERMISSION(502), //没有权限
     NO_PERMISSION(502), //没有权限
     NOT_REGISTER(503), //未注册
     NOT_REGISTER(503), //未注册
+    HAS_REGISTER_WITHOUT_PASSWORD(504),//已注册、没有设置密码
     ROOM_ALREADY_CREATE(505), //房间已创建
     ROOM_ALREADY_CREATE(505), //房间已创建
     INVALID_PARAM(506), //存在无效参数
     INVALID_PARAM(506), //存在无效参数
     SERVER_EXCEPTION(507), //后端异常
     SERVER_EXCEPTION(507), //后端异常

+ 6 - 0
module/account/src/main/java/com/adealink/weparty/account/constant/Error.kt

@@ -43,6 +43,11 @@ class AccountServerExceptionError : IError(getCompatString(R.string.account_serv
  */
  */
 class AccountNoRegisterError : IError()
 class AccountNoRegisterError : IError()
 
 
+/**
+ * 已注册、没有设置密码
+ */
+class AccountHasRegisterWithoutPasswordError : IError()
+
 //模块:account,功能:login,错误:auth_cancel
 //模块:account,功能:login,错误:auth_cancel
 class AccountLoginAuthCancelError : IError()
 class AccountLoginAuthCancelError : IError()
 
 
@@ -75,6 +80,7 @@ fun getLoginErrorByServerCode(error: IError): IError {
         ServerCode.COMMON_OP_ERROR.code -> AccountServerOpError()
         ServerCode.COMMON_OP_ERROR.code -> AccountServerOpError()
         ServerCode.SERVER_EXCEPTION.code -> AccountServerExceptionError()
         ServerCode.SERVER_EXCEPTION.code -> AccountServerExceptionError()
         ServerCode.NOT_REGISTER.code -> AccountNoRegisterError()
         ServerCode.NOT_REGISTER.code -> AccountNoRegisterError()
+        ServerCode.HAS_REGISTER_WITHOUT_PASSWORD.code -> AccountHasRegisterWithoutPasswordError()
         ServerCode.INVALID_VERIFY_CODE.code -> AccountInvalidVerifyCodeError()
         ServerCode.INVALID_VERIFY_CODE.code -> AccountInvalidVerifyCodeError()
         ServerCode.PASSWORD_ERROR.code -> AccountPasswordError()
         ServerCode.PASSWORD_ERROR.code -> AccountPasswordError()
         ServerCode.PASSWORD_ERROR_TOO_FREQUENTLY.code -> AccountPasswordFrequentlyError()
         ServerCode.PASSWORD_ERROR_TOO_FREQUENTLY.code -> AccountPasswordFrequentlyError()

+ 7 - 3
module/account/src/main/java/com/adealink/weparty/account/login/phone/PhoneInputActivity.kt

@@ -25,6 +25,7 @@ import com.adealink.frame.util.onClick
 import com.adealink.frame.util.phoneStripSeparators
 import com.adealink.frame.util.phoneStripSeparators
 import com.adealink.frame.util.showSoftKeyboard
 import com.adealink.frame.util.showSoftKeyboard
 import com.adealink.weparty.account.R
 import com.adealink.weparty.account.R
+import com.adealink.weparty.account.constant.AccountHasRegisterWithoutPasswordError
 import com.adealink.weparty.account.constant.AccountNoRegisterError
 import com.adealink.weparty.account.constant.AccountNoRegisterError
 import com.adealink.weparty.account.constant.TAG_ACCOUNT_LOGIN_PHONE
 import com.adealink.weparty.account.constant.TAG_ACCOUNT_LOGIN_PHONE
 import com.adealink.weparty.account.countryselect.SelectCountryContract
 import com.adealink.weparty.account.countryselect.SelectCountryContract
@@ -208,7 +209,7 @@ class PhoneInputActivity : BaseLoginActivity() {
             .message(getCompatString(R.string.account_confirm_phone_right, formatPhone))
             .message(getCompatString(R.string.account_confirm_phone_right, formatPhone))
             .positiveText(getCompatString(APP_R.string.commonui_confirm))
             .positiveText(getCompatString(APP_R.string.commonui_confirm))
             .onPositive {
             .onPositive {
-                checkPhoneRegistered(phone)
+                checkPhoneHasPassword(phone)
             }
             }
             .negativeText(getCompatString(APP_R.string.common_edit))
             .negativeText(getCompatString(APP_R.string.common_edit))
             .onNegative {
             .onNegative {
@@ -218,8 +219,11 @@ class PhoneInputActivity : BaseLoginActivity() {
             .show(supportFragmentManager, "PhoneConfirmDialog")
             .show(supportFragmentManager, "PhoneConfirmDialog")
     }
     }
 
 
-    private fun checkPhoneRegistered(phone: String) {
+    // 检查手机号是否已经设置密码
+    private fun checkPhoneHasPassword(phone: String) {
         showLoading()
         showLoading()
+//        200 - 已注册、已设置密码:直接去密码登录页
+//        503 504 - 没有注册:去手机登录页
         loginViewModel.checkPhoneRegistered(formatAppPhone(phone, currentCountryCode!!))
         loginViewModel.checkPhoneRegistered(formatAppPhone(phone, currentCountryCode!!))
             .observe(this) {
             .observe(this) {
                 dismissLoading()
                 dismissLoading()
@@ -229,7 +233,7 @@ class PhoneInputActivity : BaseLoginActivity() {
                     }
                     }
 
 
                     is Rlt.Failed -> {
                     is Rlt.Failed -> {
-                        if (it.error is AccountNoRegisterError) {
+                        if (it.error is AccountNoRegisterError || it.error is AccountHasRegisterWithoutPasswordError) {
                             goPhoneRegister(phone)
                             goPhoneRegister(phone)
                         } else {
                         } else {
                             showFailedToast(it)
                             showFailedToast(it)

+ 35 - 27
module/account/src/main/java/com/adealink/weparty/account/login/phone/PhoneLoginActivity.kt

@@ -1,11 +1,7 @@
 package com.adealink.weparty.account.login.phone
 package com.adealink.weparty.account.login.phone
 
 
 import androidx.activity.viewModels
 import androidx.activity.viewModels
-import androidx.lifecycle.lifecycleScope
 import com.adealink.frame.base.Rlt
 import com.adealink.frame.base.Rlt
-import com.adealink.weparty.commonui.toast.util.showFailedToast
-import com.adealink.frame.ext.clicks
-import com.adealink.frame.ext.throttleFirst
 import com.adealink.frame.log.Log
 import com.adealink.frame.log.Log
 import com.adealink.frame.mvvm.view.viewBinding
 import com.adealink.frame.mvvm.view.viewBinding
 import com.adealink.frame.router.Router
 import com.adealink.frame.router.Router
@@ -14,7 +10,7 @@ import com.adealink.frame.router.annotation.RouterUri
 import com.adealink.frame.statistics.CommonEventValue
 import com.adealink.frame.statistics.CommonEventValue
 import com.adealink.frame.util.formatAppPhone
 import com.adealink.frame.util.formatAppPhone
 import com.adealink.frame.util.formatPhonePretty
 import com.adealink.frame.util.formatPhonePretty
-import com.adealink.weparty.module.account.Account
+import com.adealink.frame.util.onClick
 import com.adealink.weparty.account.constant.TAG_ACCOUNT_LOGIN_PHONE
 import com.adealink.weparty.account.constant.TAG_ACCOUNT_LOGIN_PHONE
 import com.adealink.weparty.account.databinding.ActivityPhoneLoginBinding
 import com.adealink.weparty.account.databinding.ActivityPhoneLoginBinding
 import com.adealink.weparty.account.login.BaseLoginActivity
 import com.adealink.weparty.account.login.BaseLoginActivity
@@ -25,8 +21,9 @@ import com.adealink.weparty.account.login.data.ThirdType
 import com.adealink.weparty.account.login.viewmodel.LoginViewModel
 import com.adealink.weparty.account.login.viewmodel.LoginViewModel
 import com.adealink.weparty.account.stat.AccountLoginStatEvent
 import com.adealink.weparty.account.stat.AccountLoginStatEvent
 import com.adealink.weparty.account.viewModel.AccountViewModelFactory
 import com.adealink.weparty.account.viewModel.AccountViewModelFactory
+import com.adealink.weparty.commonui.toast.util.showFailedToast
+import com.adealink.weparty.module.account.Account
 import com.qmuiteam.qmui.widget.util.QMUIStatusBarHelper
 import com.qmuiteam.qmui.widget.util.QMUIStatusBarHelper
-import kotlinx.coroutines.launch
 
 
 /**
 /**
  * Created by sunxiaodong on 2021/10/6.
  * Created by sunxiaodong on 2021/10/6.
@@ -52,19 +49,19 @@ class PhoneLoginActivity : BaseLoginActivity() {
     override fun initViews() {
     override fun initViews() {
         QMUIStatusBarHelper.setStatusBarLightMode(this)
         QMUIStatusBarHelper.setStatusBarLightMode(this)
         setContentView(binding.root)
         setContentView(binding.root)
-        lifecycleScope.launch {
-            binding.loginButton.clicks().throttleFirst(1000).collect {
-                login()
-                AccountLoginStatEvent(CommonEventValue.Action.BTN_CLICK).apply {
-                    type to AccountLoginStatEvent.Type.PHONE
-                    btn to AccountLoginStatEvent.Btn.LOG_IN
-                    phone to this@PhoneLoginActivity.phone
-                    this.countryCode to this@PhoneLoginActivity.countryCode
-                    source to getLoginStatSource()
-                }.send()
-            }
+
+        binding.loginButton.onClick(wait = 1000) {
+            login()
+            AccountLoginStatEvent(CommonEventValue.Action.BTN_CLICK).apply {
+                type to AccountLoginStatEvent.Type.PHONE
+                btn to AccountLoginStatEvent.Btn.LOG_IN
+                phone to this@PhoneLoginActivity.phone
+                this.countryCode to this@PhoneLoginActivity.countryCode
+                source to getLoginStatSource()
+            }.send()
         }
         }
-        binding.forgetPassword.setOnClickListener {
+
+        binding.forgetPassword.onClick {
             goResetPassword()
             goResetPassword()
             AccountLoginStatEvent(CommonEventValue.Action.BTN_CLICK).apply {
             AccountLoginStatEvent(CommonEventValue.Action.BTN_CLICK).apply {
                 type to AccountLoginStatEvent.Type.PHONE
                 type to AccountLoginStatEvent.Type.PHONE
@@ -74,6 +71,7 @@ class PhoneLoginActivity : BaseLoginActivity() {
                 source to getLoginStatSource()
                 source to getLoginStatSource()
             }.send()
             }.send()
         }
         }
+
         showPhone()
         showPhone()
     }
     }
 
 
@@ -90,19 +88,22 @@ class PhoneLoginActivity : BaseLoginActivity() {
 
 
         val formatPhone = formatPhonePretty(phone!!, countryCode!!)
         val formatPhone = formatPhonePretty(phone!!, countryCode!!)
         if (formatPhone.isNullOrEmpty()) {
         if (formatPhone.isNullOrEmpty()) {
-            Log.e(TAG_ACCOUNT_LOGIN_PHONE,
-                "phone login, show phone, format phone is null, phone:$phone, countryCode:$countryCode")
+            Log.e(
+                TAG_ACCOUNT_LOGIN_PHONE,
+                "phone login, show phone, format phone is null, phone:$phone, countryCode:$countryCode"
+            )
             return
             return
         }
         }
 
 
-        binding.phone.text = formatPhone
     }
     }
 
 
     override fun initComponents() {
     override fun initComponents() {
         LoginTitleComp(this, binding.loginTitle).attach()
         LoginTitleComp(this, binding.loginTitle).attach()
-        passwordInputComp = PasswordInputComp(this,
+        passwordInputComp = PasswordInputComp(
+            this,
             binding.layoutPasswordInput,
             binding.layoutPasswordInput,
-            binding.loginButton).apply { attach() }
+            binding.loginButton
+        ).apply { attach() }
     }
     }
 
 
     override fun observeViewModel() {
     override fun observeViewModel() {
@@ -112,6 +113,7 @@ class PhoneLoginActivity : BaseLoginActivity() {
                 is Rlt.Success -> {
                 is Rlt.Success -> {
                     handleLoginSuccess(it.data, ThirdType.PHONE, AccountLoginStatEvent.Source.LOGIN)
                     handleLoginSuccess(it.data, ThirdType.PHONE, AccountLoginStatEvent.Source.LOGIN)
                 }
                 }
+
                 is Rlt.Failed -> {
                 is Rlt.Failed -> {
                     showFailedToast(it)
                     showFailedToast(it)
                 }
                 }
@@ -139,14 +141,19 @@ class PhoneLoginActivity : BaseLoginActivity() {
 
 
         val password = passwordInputComp.getPassword()
         val password = passwordInputComp.getPassword()
         if (!passwordInputComp.isPasswordValid(password)) {
         if (!passwordInputComp.isPasswordValid(password)) {
-            Log.e(TAG_ACCOUNT_LOGIN_PHONE, "phone login, login, password invalid, password:$password")
+            Log.e(
+                TAG_ACCOUNT_LOGIN_PHONE,
+                "phone login, login, password invalid, password:$password"
+            )
             return
             return
         }
         }
 
 
         showLoading()
         showLoading()
-        loginViewModel.phonePasswordLogin(formatAppPhone(phone!!, countryCode!!),
+        loginViewModel.phonePasswordLogin(
+            formatAppPhone(phone!!, countryCode!!),
             password,
             password,
-            countryCode!!)
+            countryCode!!
+        )
     }
     }
 
 
     private fun goResetPassword() {
     private fun goResetPassword() {
@@ -155,7 +162,8 @@ class PhoneLoginActivity : BaseLoginActivity() {
             .putExtra(Account.Phone.EXTRA_PHONE, phone)
             .putExtra(Account.Phone.EXTRA_PHONE, phone)
             .putExtra(
             .putExtra(
                 Account.Phone.EXTRA_GET_VERIFY_CODE_REASON,
                 Account.Phone.EXTRA_GET_VERIFY_CODE_REASON,
-                GetVerifyCodeReason.RESET_PASSWORD)
+                GetVerifyCodeReason.RESET_PASSWORD
+            )
             .start()
             .start()
     }
     }
 
 

+ 13 - 38
module/account/src/main/res/layout/activity_phone_login.xml

@@ -13,60 +13,35 @@
         app:layout_constraintTop_toTopOf="parent" />
         app:layout_constraintTop_toTopOf="parent" />
 
 
     <androidx.appcompat.widget.AppCompatTextView
     <androidx.appcompat.widget.AppCompatTextView
-        android:id="@+id/login_tv"
+        android:id="@+id/phone_login_tip"
         android:layout_width="wrap_content"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginTop="40dp"
-        android:text="@string/account_login"
-        android:textColor="@color/color_222222"
-        android:textSize="20sp"
-        android:textStyle="bold"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/login_title" />
-
-    <androidx.appcompat.widget.AppCompatTextView
-        android:id="@+id/enter_password_tip"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="14dp"
+        android:layout_marginHorizontal="28dp"
+        android:layout_marginTop="24dp"
         android:ellipsize="end"
         android:ellipsize="end"
         android:singleLine="true"
         android:singleLine="true"
-        android:text="@string/account_enter_password_tip"
-        android:textColor="@color/color_FF999999"
-        android:textSize="16sp"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/login_tv" />
-
-    <androidx.appcompat.widget.AppCompatTextView
-        android:id="@+id/phone"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="6dp"
+        android:text="Mobile number login"
         android:textColor="@color/color_222222"
         android:textColor="@color/color_222222"
-        android:textSize="16sp"
-        app:layout_constraintEnd_toEndOf="parent"
+        android:textSize="18sp"
+        android:textStyle="bold"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/enter_password_tip" />
+        app:layout_constraintTop_toBottomOf="@id/login_title" />
 
 
     <include
     <include
         android:id="@+id/layout_password_input"
         android:id="@+id/layout_password_input"
         layout="@layout/layout_password_input"
         layout="@layout/layout_password_input"
         android:layout_width="match_parent"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginStart="20dp"
-        android:layout_marginTop="26dp"
-        android:layout_marginEnd="20dp"
-        app:layout_constraintTop_toBottomOf="@+id/phone" />
+        android:layout_marginHorizontal="28dp"
+        android:layout_marginTop="24dp"
+        app:layout_constraintTop_toBottomOf="@+id/phone_login_tip" />
 
 
     <com.adealink.weparty.commonui.widget.CommonButton
     <com.adealink.weparty.commonui.widget.CommonButton
         android:id="@+id/login_button"
         android:id="@+id/login_button"
         android:layout_width="match_parent"
         android:layout_width="match_parent"
-        android:layout_height="48dp"
-        android:layout_marginStart="20dp"
-        android:layout_marginTop="20dp"
-        android:layout_marginEnd="20dp"
+        android:layout_height="44dp"
+        android:layout_marginHorizontal="40dp"
+        android:layout_marginTop="40dp"
         android:enabled="false"
         android:enabled="false"
         android:gravity="center"
         android:gravity="center"
         android:text="@string/account_login"
         android:text="@string/account_login"

+ 0 - 1
module/account/src/main/res/layout/layout_password_input.xml

@@ -26,7 +26,6 @@
         android:hint="@string/account_password"
         android:hint="@string/account_password"
         android:inputType="textPassword"
         android:inputType="textPassword"
         android:maxLength="12"
         android:maxLength="12"
-        android:paddingStart="16dp"
         android:paddingTop="22dp"
         android:paddingTop="22dp"
         android:paddingBottom="22dp"
         android:paddingBottom="22dp"
         android:textColor="@color/color_222222"
         android:textColor="@color/color_222222"