commit d1c4b4febeb8300fa7fbf6adb762134ba415a8f5 parent 49bc15cf1bd0b204a2c232304059c2ea036594a0 Author: rhunk <101876869+rhunk@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:56:27 +0100 fix(app): two letters locale Diffstat:
4 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/home/HomeSection.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/home/HomeSection.kt @@ -211,7 +211,7 @@ class HomeSection : Section() { ) Text( - text = arrayOf("\u0020", "\u0065", "\u0063", "\u006e", "\u0061", "\u0068", "\u006e", "\u0045", "\u0070", "\u0061", "\u006e", "\u0053").reversed().joinToString(""), + text = remember { intArrayOf(101,99,110,97,104,110,69,112,97,110,83).map { it.toChar() }.joinToString("").reversed() }, fontSize = 30.sp, fontFamily = avenirNextFontFamily, modifier = Modifier.align(Alignment.CenterHorizontally), @@ -225,7 +225,7 @@ class HomeSection : Section() { ) Text( - text = "An Xposed module made to enhance your Snapchat experience", + text = "An xposed module made to enhance your Snapchat experience", modifier = Modifier .padding(16.dp) .fillMaxWidth(), @@ -245,7 +245,9 @@ class HomeSection : Section() { modifier = Modifier.size(32.dp).clickable { context.activity?.startActivity( Intent(Intent.ACTION_VIEW).apply { - data = Uri.parse("https://github.com/rhunk/SnapEnhance") + data = Uri.parse( + intArrayOf(101,99,110,97,104,110,69,112,97,110,83,47,107,110,117,104,114,47,109,111,99,46,98,117,104,116,105,103,47,47,58,115,112,116,116,104).map { it.toChar() }.joinToString("").reversed() + ) flags = Intent.FLAG_ACTIVITY_NEW_TASK } ) @@ -258,7 +260,9 @@ class HomeSection : Section() { modifier = Modifier.size(32.dp).clickable { context.activity?.startActivity( Intent(Intent.ACTION_VIEW).apply { - data = Uri.parse("https://t.me/snapenhance") + data = Uri.parse( + intArrayOf(101,99,110,97,104,110,101,112,97,110,115,47,101,109,46,116,47,47,58,115,112,116,116,104).map { it.toChar() }.joinToString("").reversed() + ) flags = Intent.FLAG_ACTIVITY_NEW_TASK } ) diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/setup/screens/impl/PickLanguageScreen.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/setup/screens/impl/PickLanguageScreen.kt @@ -40,6 +40,7 @@ class PickLanguageScreen : SetupScreen(){ private fun getLocaleDisplayName(locale: String): String { locale.split("_").let { + if (it.size != 2) return Locale(locale).getDisplayName(Locale.getDefault()) return Locale(it[0], it[1]).getDisplayName(Locale.getDefault()) } } @@ -105,7 +106,7 @@ class PickLanguageScreen : SetupScreen(){ contentAlignment = Alignment.Center ) { Text( - text = getLocaleDisplayName(locale), + text = remember(locale) { getLocaleDisplayName(locale) }, fontSize = 16.sp, fontWeight = FontWeight.Light, ) @@ -125,7 +126,7 @@ class PickLanguageScreen : SetupScreen(){ Button(onClick = { isDialog = true }) { - Text(text = getLocaleDisplayName(selectedLocale.value), fontSize = 16.sp, + Text(text = remember(selectedLocale.value) { getLocaleDisplayName(selectedLocale.value) }, fontSize = 16.sp, fontWeight = FontWeight.Normal) } } diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/bridge/types/LocalePair.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/bridge/types/LocalePair.kt @@ -1,6 +1,16 @@ package me.rhunk.snapenhance.common.bridge.types +import java.util.Locale + data class LocalePair( val locale: String, val content: String -)- \ No newline at end of file +) { + fun getLocale(): Locale { + if (locale.contains("_")) { + val split = locale.split("_") + return Locale(split[0], split[1]) + } + return Locale(locale) + } +}+ \ No newline at end of file diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/bridge/wrapper/LocaleWrapper.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/bridge/wrapper/LocaleWrapper.kt @@ -19,7 +19,7 @@ class LocaleWrapper { if (locale == DEFAULT_LOCALE) return locales - val compatibleLocale = context.resources.assets.list("lang")?.firstOrNull { it.startsWith(locale) }?.substring(0, 5) ?: return locales + val compatibleLocale = context.resources.assets.list("lang")?.firstOrNull { it.startsWith(locale) }?.substringBefore(".") ?: return locales context.resources.assets.open("lang/$compatibleLocale.json").use { inputStream -> locales.add(LocalePair(compatibleLocale, inputStream.bufferedReader().use { it.readText() })) @@ -29,7 +29,7 @@ class LocaleWrapper { } fun fetchAvailableLocales(context: Context): List<String> { - return context.resources.assets.list("lang")?.map { it.substring(0, 5) } ?: listOf() + return context.resources.assets.list("lang")?.map { it.substringBefore(".") }?.sorted() ?: listOf(DEFAULT_LOCALE) } } @@ -40,7 +40,7 @@ class LocaleWrapper { lateinit var loadedLocale: Locale private fun load(localePair: LocalePair) { - loadedLocale = localePair.locale.let { Locale(it.substring(0, 2), it.substring(3, 5)) } + loadedLocale = localePair.getLocale() val translations = JsonParser.parseString(localePair.content).asJsonObject if (translations == null || translations.isJsonNull) {