mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2026-01-20 09:43:58 +00:00
fix(locales): use buildconfig instead of generating kt file
This commit is contained in:
@@ -1,21 +1,22 @@
|
||||
package app.revanced.manager.util
|
||||
|
||||
import android.app.LocaleConfig
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.LocaleList
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import app.revanced.manager.BuildConfig
|
||||
import java.util.Locale
|
||||
|
||||
object SupportedLocales {
|
||||
fun getSupportedLocales(context: Context): List<Locale> {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
runCatching {
|
||||
android.app.LocaleConfig(context).supportedLocales?.toList()
|
||||
}.getOrNull() ?: GeneratedLocales.SUPPORTED_LOCALES
|
||||
} else {
|
||||
GeneratedLocales.SUPPORTED_LOCALES
|
||||
}
|
||||
var result: List<Locale>? = null
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) result = runCatching {
|
||||
LocaleConfig(context).supportedLocales?.toList()
|
||||
}.getOrNull()
|
||||
|
||||
return result ?: generated
|
||||
}
|
||||
|
||||
fun getCurrentLocale(): Locale? =
|
||||
@@ -29,4 +30,11 @@ object SupportedLocales {
|
||||
locale.getDisplayName(locale).replaceFirstChar { it.uppercase(locale) }
|
||||
|
||||
private fun LocaleList.toList() = (0 until size()).map { get(it) }
|
||||
|
||||
private val generated by lazy {
|
||||
listOf(
|
||||
Locale.ENGLISH,
|
||||
*BuildConfig.SUPPORTED_LOCALES.map(Locale::forLanguageTag).toTypedArray()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user