Browse Source

提交人:jtm
提交内容:部分bug fix

380474035@qq.com 2 years ago
parent
commit
6fe3987e22

+ 7 - 1
BusinessAuth/src/main/java/com/develop/auth/ui/MemberProfileFragment.kt

@@ -72,8 +72,14 @@ class MemberProfileFragment : CommonBVMFragment<FragmentMemberProfileBinding, Me
                 val saveToken: String? = null
                 MMkvUtils.save(API_TOKEN, saveToken)
                 MMkvUtils.save(LOGIN_TAG, false)
+                FoodDataProvider.getUserDatabase().userInfoDao().deleteAllUserInfo()
+                parentFragmentManager
+                    .beginTransaction()
+                    .replace(R.id.fl_container, MemberLoginFragment())
+                    .commitAllowingStateLoss()
+            } else {
+                navigateTo(Screens.Main.ENTRANCE_CHOSEN)
             }
-            navigateTo(Screens.Main.ENTRANCE_CHOSEN)
         }
         if (viewModel.enterFromHome) {
             binding.tvSkipForNow.text = "Sign out"

+ 3 - 0
BusinessCommon/src/main/java/com/develop/common/data_repo/db/dao/UserInfoDao.kt

@@ -15,6 +15,9 @@ interface UserInfoDao {
     @Query("select * from user_info")
     fun queryUserInfo(): List<UserInfo>
 
+    @Query("delete from user_info")
+    fun deleteAllUserInfo()
+
     @Query("select * from user_info where userId =:userId")
     fun queryUserInfoByUserId(userId: Long): UserInfo?
 

+ 4 - 0
BusinessCommon/src/main/java/com/develop/common/widget/HomeFunctionTopBar.kt

@@ -95,6 +95,10 @@ class HomeFunctionTopBar : RelativeLayout, View.OnClickListener {
         binding.tvTitle.updateText(title)
     }
 
+    fun setUserName(userName: String) {
+        binding.tvState.text = userName
+    }
+
     private fun updateIconSize(isLocal: Boolean) {
         val param = binding.ivFunction.layoutParams as LayoutParams
         if (isLocal) {

+ 39 - 1
BusinessMain/src/main/java/com/develop/main/ui/HomeActivity.kt

@@ -13,9 +13,11 @@ import com.develop.base.ext.navigateTo
 import com.develop.base.ext.resId2Dimension
 import com.develop.base.manager.WifiHelp
 import com.develop.base.widgets.CommonPopupWindow
+import com.develop.common.data_repo.FoodDataProvider
 import com.develop.common.data_repo.db.DataFactory
 import com.develop.common.data_repo.db.FunType
 import com.develop.common.data_repo.db.RecipesType
+import com.develop.common.data_repo.db.entity.UserInfo
 import com.develop.common.router.Screens
 import com.develop.common.tag.*
 import com.develop.common.ui.CommonBVMActivity
@@ -193,7 +195,6 @@ class HomeActivity : CommonBVMActivity<ActivityHomeBinding, HomeViewModel>() {
         }
 
         binding.policyLayout.setOnClickListener {
-
             val bundle = Bundle()
             bundle.putBoolean(POLICY_FROM_MAIN_SETTING, true)
             navigateTo(Screens.Setting.POLICY) {
@@ -209,6 +210,38 @@ class HomeActivity : CommonBVMActivity<ActivityHomeBinding, HomeViewModel>() {
         }
     }
 
+    private fun updateUserInfoUi(userInfo: UserInfo?) {
+        if (userInfo?.userName != null) {
+            binding.functionTopBar.setUserName(userInfo.userName ?: "")
+            binding.tvUserName.text = userInfo.userName ?: ""
+            val icon = when (userInfo.userAvatar?.toInt() ?: 0) {
+                0 -> {
+                    com.develop.common.R.drawable.ic_icon1
+                }
+                1 -> {
+                    com.develop.common.R.drawable.ic_icon2
+                }
+                2 -> {
+                    com.develop.common.R.drawable.ic_icon3
+                }
+                3 -> {
+                    com.develop.common.R.drawable.ic_icon4
+                }
+                4 -> {
+                    com.develop.common.R.drawable.ic_icon5
+                }
+                else -> {
+                    com.develop.common.R.drawable.ic_icon6
+                }
+            }
+            binding.ivAvatar.setImageResource(icon)
+        } else {
+            binding.ivAvatar.setImageResource(com.develop.common.R.drawable.ic_icon1)
+            binding.functionTopBar.setUserName(getString(com.develop.common.R.string.login))
+            binding.tvUserName.text = getString(com.develop.common.R.string.login)
+        }
+    }
+
     companion object {
         var dp1080 = (com.develop.base.R.dimen.convert_1080px).resId2Dimension().toInt()
         var dp160 = (com.develop.base.R.dimen.convert_160px).resId2Dimension().toInt()
@@ -218,6 +251,11 @@ class HomeActivity : CommonBVMActivity<ActivityHomeBinding, HomeViewModel>() {
     override fun onResume() {
         super.onResume()
         wifiHelp.scan()
+        val userInfo = FoodDataProvider
+            .getUserDatabase()
+            .userInfoDao()
+            .queryUserInfoByUserId(CURRENT_USER_ID)
+        updateUserInfoUi(userInfo)
     }
 
     override fun onDestroy() {