소스 검색

提交人:jtm
提交内容:优化

江天明 1 년 전
부모
커밋
6240eeb5d3

+ 10 - 0
BusinessCommon/src/main/java/com/develop/common/tag/CommonTag.kt

@@ -38,6 +38,16 @@ const val EN = "EN"
 const val ZH = "ZH"
 const val JA = "JA"
 const val FR = "FR"
+const val CZ = "CZ"
+const val ES = "ES"
+const val HU = "HU"
+const val SK = "SK"
+const val DE = "DE"
+const val IT = "IT"
+const val PL = "PL"
+const val NL = "NL"
+const val PT = "PT"
+const val RU = "RU"
 
 const val TURN_UP_KEY_CODE = 19
 const val TURN_DOWN_KEY_CODE = 20

+ 20 - 50
BusinessSetting/src/main/java/com/develop/setting/ui/LanguageActivity.kt

@@ -46,6 +46,7 @@ class LanguageActivity : BaseBindingActivity<ActivityLanguageBinding>() {
     private var selectedPosition = -1
     private var isLanguageTip = false
     private var isFromSetting = false
+    private var languageList = mutableListOf<ConfigUtils.Lang>()
 
     override fun createViewBinding(inflater: LayoutInflater): ActivityLanguageBinding {
         return ActivityLanguageBinding.inflate(inflater)
@@ -53,7 +54,7 @@ class LanguageActivity : BaseBindingActivity<ActivityLanguageBinding>() {
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
-
+        languageList = DataFactory.createLanguageDataV2(resources).toMutableList()
         if (isBrand036I()) {
             binding.ivLogo.setVisible()
             binding.ivBanner.setBackgroundResource(com.develop.common.R.drawable.guide_bg_036i)
@@ -100,14 +101,20 @@ class LanguageActivity : BaseBindingActivity<ActivityLanguageBinding>() {
                         cardView.setBackgroundResource(com.develop.common.R.drawable.shape_44pxffffff_stoke)
                     }
                     val model = getModel<ConfigUtils.Lang>()
-                    ivIcon.load(context.resources.getIdentifier(model.icon,"drawable","com.develop.foodcooking"))
+                    ivIcon.load(
+                        context.resources.getIdentifier(
+                            model.icon,
+                            "drawable",
+                            "com.develop.foodcooking"
+                        )
+                    )
                     model.showName?.let { it1 -> tvTitle.updateText(it1) }
                 }
                 R.id.content_layout.onClick {
                     updateSelectionPos(absoluteAdapterPosition)
                 }
             }
-        }.models = DataFactory.createLanguageDataV2(resources)
+        }.models = languageList
 
         selectedPosition = getSelectedPos()
 
@@ -150,7 +157,7 @@ class LanguageActivity : BaseBindingActivity<ActivityLanguageBinding>() {
             }
             if (isFromSetting) {
                 if (isNightTheme() || isBrand036I()) {
-                    if (binding.languageRecycle.models?.size!! > 1) {
+                    if (languageList[selectedPosition].value != MMkvUtils.getString(CURRENT_LANGUAGE)) {
                         isLanguageTip = true
                         cancelConfirmDialog.title =
                             getString(com.develop.common.R.string.change_lang_tips2)
@@ -159,7 +166,7 @@ class LanguageActivity : BaseBindingActivity<ActivityLanguageBinding>() {
                         finish()
                     }
                 } else {
-                    if (binding.languageRecycle.models?.size!! > 1) {
+                    if (languageList[selectedPosition].value != MMkvUtils.getString(CURRENT_LANGUAGE)) {
                         isLanguageTip = true
                         cancelConfirmDialog.title =
                             getString(com.develop.common.R.string.change_lang_tips2)
@@ -193,57 +200,20 @@ class LanguageActivity : BaseBindingActivity<ActivityLanguageBinding>() {
     }
 
     private fun updateLanguage() {
-        when (selectedPosition) {
-            0, -1 -> {
-                MMkvUtils.save(CURRENT_LANGUAGE, EN)
-                LanguageUtils.applyLanguage(Locale.ENGLISH)
-            }
-
-            1 -> {
-                MMkvUtils.save(CURRENT_LANGUAGE, FR)
-                LanguageUtils.applyLanguage(Locale.FRANCE)
-
-            }
-
-            2 -> {
-                MMkvUtils.save(CURRENT_LANGUAGE, ZH)
-                LanguageUtils.applyLanguage(Locale.CHINESE)
-            }
-
-            3 -> {
-                MMkvUtils.save(CURRENT_LANGUAGE, JA)
-                LanguageUtils.applyLanguage(Locale.JAPAN)
-            }
+        languageList[selectedPosition].apply {
+            MMkvUtils.save(CURRENT_LANGUAGE, this.value)
+            LanguageUtils.applyLanguage(Locale(this.value.lowercase(), this.value.uppercase()))
         }
     }
 
     private fun getSelectedPos(): Int {
-        return when (MMkvUtils.getString(CURRENT_LANGUAGE)) {
-            EN -> {
-                updateSelectionPos(0)
-                0
-            }
-
-            ZH -> {
-                updateSelectionPos(1)
-                1
-            }
-
-            FR -> {
-                updateSelectionPos(2)
-                2
-            }
-
-            JA -> {
-                updateSelectionPos(3)
-                3
-            }
-
-            else -> {
-                updateSelectionPos(0)
-                0
+        val language = MMkvUtils.getString(CURRENT_LANGUAGE)
+        for (i in languageList.indices) {
+            if (language == languageList[i].value) {
+                selectedPosition = i
             }
         }
+        return selectedPosition
     }
 
     @Subscribe