|
|
@@ -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())
|
|
|
}
|