|
@@ -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
|