XiaodongLin 1 год назад
Родитель
Сommit
1ecf134d10

+ 1 - 0
app/src/main/java/com/adealink/weparty/module/profile/IProfileService.kt

@@ -61,6 +61,7 @@ interface IProfileService : IService<IProfileService> {
 
     fun getUserTagsViewModel(owner: ViewModelStoreOwner): IUserTagsViewModel?
 
+    fun getCountryFlag(countryCode: String): String
     fun getCountryName(countryCode: String): String
 
     suspend fun getUserSelectTags(uid: Long): Rlt<List<UserLabel>>

+ 7 - 0
app/src/main/java/com/adealink/weparty/module/profile/ProfileModule.kt

@@ -96,6 +96,9 @@ object ProfileModule : BaseDynamicModule<IProfileService>(IProfileService::class
                 return null
             }
 
+            override fun getCountryFlag(countryCode: String): String {
+                return ""
+            }
             override fun getCountryName(countryCode: String): String {
                 return ""
             }
@@ -331,4 +334,8 @@ object ProfileModule : BaseDynamicModule<IProfileService>(IProfileService::class
     override fun updateCacheUserInfo(userInfo: UserInfo) {
         getService().updateCacheUserInfo(userInfo)
     }
+
+    override fun getCountryFlag(countryCode: String): String {
+        return getService().getCountryFlag(countryCode)
+    }
 }

+ 2 - 2
app/src/main/java/com/adealink/weparty/module/profile/view/UserCountryView.kt

@@ -5,7 +5,7 @@ import android.util.AttributeSet
 import com.adealink.frame.image.view.NetworkImageView
 import com.adealink.weparty.commonui.ext.gone
 import com.adealink.weparty.commonui.ext.show
-import com.adealink.weparty.module.account.AccountModule
+import com.adealink.weparty.module.profile.ProfileModule
 import com.adealink.weparty.module.profile.data.UserInfo
 import com.facebook.drawee.drawable.ScalingUtils
 
@@ -50,7 +50,7 @@ class UserCountryView @JvmOverloads constructor(
             gone()
             return
         }
-        val countryUrl = AccountModule.getCountryByCountryCode(countryCode)?.flag
+        val countryUrl = ProfileModule.getCountryFlag(countryCode)
         setCountryUrl(countryUrl)
     }
 

+ 3 - 0
module/profile/src/main/java/com/adealink/weparty/profile/ProfileServiceImpl.kt

@@ -107,6 +107,9 @@ class ProfileServiceImpl : IProfileService {
         return ViewModelProvider(owner, ProfileViewModelFactory())[UserTagsViewModel::class.java]
     }
 
+    override fun getCountryFlag(countryCode: String): String {
+        return countryManager.getCountryFlag(countryCode)
+    }
     override fun getCountryName(countryCode: String): String {
         return countryManager.getCountryName(countryCode)
     }

+ 12 - 4
module/profile/src/main/java/com/adealink/weparty/profile/country/manager/CountryManager.kt

@@ -20,8 +20,6 @@ import com.adealink.weparty.profile.country.datasource.CountryLocalService
 import com.adealink.weparty.profile.country.listener.ICountryListener
 import com.adealink.weparty.profile.data.CountryLocalCountriesEmptyError
 import com.adealink.weparty.profile.datasource.ProfileHttpService
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.SupervisorJob
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.withContext
 
@@ -35,8 +33,16 @@ class CountryManager : BaseFrame<ICountryListener>(), ICountryManager {
     private var countries = arrayListOf<CountryResource>()
     private val codeToCountryResMap = hashMapOf<String, CountryResource>()
 
+    override fun getCountryFlag(countryCode: String): String {
+        return countries.filter { it.code == countryCode }.firstOrNull()?.iconUrl ?: ""
+    }
+
     override fun getCountryName(countryCode: String): String {
-        val identifier = AppUtil.appContext.resources.getIdentifier(countryCode, "string", "${AppUtil.appContext.packageName}.profile")
+        val identifier = AppUtil.appContext.resources.getIdentifier(
+            countryCode,
+            "string",
+            "${AppUtil.appContext.packageName}.profile"
+        )
         if (identifier == 0) {
             return countryCode
         }
@@ -100,6 +106,7 @@ class CountryManager : BaseFrame<ICountryListener>(), ICountryManager {
                         Rlt.Success(res.countryList)
                     }
                 }
+
                 is Rlt.Failed -> result
                 else -> Rlt.Failed(IError())
             }
@@ -150,7 +157,8 @@ class CountryManager : BaseFrame<ICountryListener>(), ICountryManager {
 
     private suspend fun loadLocalCountries(): Rlt<List<CountryResource>> {
         return withContext(this.coroutineContext) {
-            val localCountries: List<CountryResource>? = froJsonErrorNull(CountryLocalService.countries)
+            val localCountries: List<CountryResource>? =
+                froJsonErrorNull(CountryLocalService.countries)
             if (localCountries.isNullOrEmpty()) {
                 return@withContext Rlt.Failed(CountryLocalCountriesEmptyError())
             }

+ 2 - 0
module/profile/src/main/java/com/adealink/weparty/profile/country/manager/ICountryManager.kt

@@ -1,9 +1,11 @@
 package com.adealink.weparty.profile.country.manager
 
 import com.adealink.frame.frame.IBaseFrame
+import com.adealink.weparty.module.profile.data.CountryResource
 import com.adealink.weparty.profile.country.listener.ICountryListener
 
 interface ICountryManager : IBaseFrame<ICountryListener> {
+    fun getCountryFlag(countryCode: String): String
     fun getCountryName(countryCode: String): String
     fun getCountryConfig(forceNet: Boolean)
     fun onCountrySelect(countryCode: String)