Browse Source

提交人:jtm
提交内容:bug fixed

江天明 1 year ago
parent
commit
3628702272

+ 19 - 0
BusinessAuth/src/main/java/com/develop/auth/ui/MemberProfileFragment.kt

@@ -14,6 +14,7 @@ import com.develop.base.ext.resId2Dimension
 import com.develop.base.ext.setVisible
 import com.develop.base.ext.text_color
 import com.develop.base.mvvm.BaseBVMFragment
+import com.develop.base.util.GlobalToast
 import com.develop.base.util.MMkvUtils
 import com.develop.base.util.ThreadUtils
 import com.develop.common.data_repo.FoodDataProvider
@@ -23,6 +24,7 @@ import com.develop.common.dialog.AgeSelectDialog
 import com.develop.common.dialog.GenderSelectDialog
 import com.develop.common.router.Screens
 import com.develop.common.tag.API_TOKEN
+import com.develop.common.tag.CURRENT_USER_ID
 import com.develop.common.tag.CURRENT_USER_ID_TAG
 import com.develop.common.tag.LOGIN_TAG
 import com.develop.common.ui.CommonBVMFragment
@@ -147,8 +149,25 @@ class MemberProfileFragment : CommonBVMFragment<FragmentMemberProfileBinding, Me
                 val chooseIcon = icons.getOrNull(it ?: 0) ?: com.develop.common.R.drawable.ic_icon1
                 binding.ivMember.setImageResource(chooseIcon)
             }
+            cancelAccountLiveData.observe(viewLifecycleOwner){
+                dismissPlainDialog()
+                FoodDataProvider
+                    .getUserDatabase()
+                    .userInfoDao()
+                    .deleteUserInfoByUserId(CURRENT_USER_ID)
+                val saveToken: String? = null
+                MMkvUtils.save(API_TOKEN, saveToken)
+                MMkvUtils.save(LOGIN_TAG, false)
+                MMkvUtils.save(CURRENT_USER_ID_TAG, 0)
+                FoodDataProvider.getUserDatabase().userInfoDao().deleteAllUserInfo()
+                parentFragmentManager
+                    .beginTransaction()
+                    .replace(R.id.fl_container, MemberLoginFragment())
+                    .commitAllowingStateLoss()
+            }
         }
         binding.tvDestroyAccount.setOnClickListener {
+            showPlainDialog(true)
             viewModel.cancelAccount()
         }
         if (isNightTheme()) {

+ 14 - 6
BusinessAuth/src/main/java/com/develop/auth/ui/MemberRegisterFragment.kt

@@ -7,7 +7,6 @@ import com.develop.auth.databinding.FragmentMemberRegisterBinding
 import com.develop.auth.viewmodel.FragmentTag
 import com.develop.auth.viewmodel.MemberViewModel
 import com.develop.common.ui.CommonBVMFragment
-import java.util.regex.Pattern
 
 class MemberRegisterFragment : CommonBVMFragment<FragmentMemberRegisterBinding, MemberViewModel>() {
 
@@ -54,9 +53,11 @@ class MemberRegisterFragment : CommonBVMFragment<FragmentMemberRegisterBinding,
             return false
         }
         if (inputPsd.length < 8) {
+            showToast("input not available")
             return false
         }
-        if (!isNumeric(inputPsd)) {
+        if (!isPasswordForm(inputPsd)) {
+            showToast("input not available")
             return false
         }
         return true
@@ -71,10 +72,17 @@ class MemberRegisterFragment : CommonBVMFragment<FragmentMemberRegisterBinding,
         return getViewModelOfActivity(MemberViewModel::class.java)
     }
 
-    private fun isNumeric(str: String): Boolean {
-        val pattern: Pattern = Pattern.compile("[a-zA-Z0-9]")
-        return pattern.matcher(str).matches()
-    }
 
 
+    /**
+     * 检测输入密码是否符合规范
+     * 8~16位数字和字母组成
+     * 不能是纯数字或纯字母
+     */
+    private fun isPasswordForm(pwd: String): Boolean {
+        if (TextUtils.isEmpty(pwd)) return false
+        val regex = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$"
+        return pwd.matches(regex.toRegex())
+    }
+
 }

+ 5 - 5
BusinessAuth/src/main/java/com/develop/auth/viewmodel/MemberViewModel.kt

@@ -1,5 +1,6 @@
 package com.develop.auth.viewmodel
 
+import android.util.Log
 import androidx.lifecycle.MutableLiveData
 import androidx.lifecycle.scopeNetLife
 import com.develop.auth.R
@@ -39,7 +40,7 @@ class MemberViewModel : BaseViewModel() {
     var perfectInfoLiveData = MutableLiveData<AuthModel>()
 
     val userInfoLiveData = MutableLiveData<UserInfo>()
-
+    val cancelAccountLiveData = MutableLiveData<Boolean>()
     var fragmentChangeLiveData = MutableLiveData<FragmentTag>()
 
 
@@ -169,15 +170,14 @@ class MemberViewModel : BaseViewModel() {
     }
 
 
-
     fun cancelAccount() = scopeNetLife {
-        Post<CancelAccountResult>(Api.CANCEL_ACCOUNT) {
+        Post<String>(Api.CANCEL_ACCOUNT) {
             body = CancelAccountBody.genCancelAccountBody()
         }.await().apply {
-           EventBus.getDefault().post(TokenInvalidateEvent())
+            cancelAccountLiveData.postValue(true)
         }
     }.catch {
-
+            Log.d("ddddd",it.message?:"")
     }
 }
 

+ 1 - 1
BusinessAuth/src/main/res/layout/fragment_member_profile.xml

@@ -75,7 +75,7 @@
         android:background="@drawable/bg_edit_input"
         android:gravity="center_vertical"
         android:paddingHorizontal="@dimen/convert_66px"
-        android:text="@string/male"
+        android:text="@string/none"
         android:textColor="#B1B2B2"
         android:textSize="@dimen/convert_30px"
         app:layout_constraintEnd_toStartOf="@+id/tv_choose_age"