From 2d690a09b37a55e87ce4365102ee818c5d9d1ba0 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sun, 14 Aug 2022 22:52:46 +0700 Subject: [PATCH] Reinstate in-app language picker (#7493) Also add required config for android 13 system picker --- app/src/main/AndroidManifest.xml | 11 ++++- .../ui/setting/SettingsGeneralController.kt | 45 +++++++++++++++++++ gradle/androidx.versions.toml | 2 +- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b3368ade78..7d9c7049b4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -27,8 +27,8 @@ android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" - android:localeConfig="@xml/locales_config" android:largeHeap="true" + android:localeConfig="@xml/locales_config" android:requestLegacyExternalStorage="true" android:roundIcon="@mipmap/ic_launcher_round" android:theme="@style/Theme.Tachiyomi" @@ -201,6 +201,15 @@ + + + + >() + + val parser = context.resources.getXml(R.xml.locales_config) + var eventType = parser.eventType + while (eventType != XmlPullParser.END_DOCUMENT) { + if (eventType == XmlPullParser.START_TAG && parser.name == "locale") { + for (i in 0 until parser.attributeCount) { + if (parser.getAttributeName(i) == "name") { + val langTag = parser.getAttributeValue(i) + langs.add(Pair(langTag, LocaleHelper.getDisplayName(langTag))) + } + } + } + eventType = parser.next() + } + + langs.sortBy { it.second } + langs.add(0, Pair("", context.getString(R.string.label_default))) + + entryValues = langs.map { it.first }.toTypedArray() + entries = langs.map { it.second }.toTypedArray() + summary = "%s" + value = AppCompatDelegate.getApplicationLocales().get(0)?.toLanguageTag() ?: "" + + onChange { newValue -> + val locale = if ((newValue as String).isEmpty()) { + LocaleListCompat.getEmptyLocaleList() + } else { + LocaleListCompat.forLanguageTags(newValue) + } + AppCompatDelegate.setApplicationLocales(locale) + true + } + } } } diff --git a/gradle/androidx.versions.toml b/gradle/androidx.versions.toml index 8727e7b7f5..91da357268 100644 --- a/gradle/androidx.versions.toml +++ b/gradle/androidx.versions.toml @@ -4,7 +4,7 @@ lifecycle_version = "2.5.1" [libraries] annotation = "androidx.annotation:annotation:1.4.0" -appcompat = "androidx.appcompat:appcompat:1.5.0" +appcompat = "androidx.appcompat:appcompat:1.6.0-beta01" biometricktx = "androidx.biometric:biometric-ktx:1.2.0-alpha04" constraintlayout = "androidx.constraintlayout:constraintlayout:2.1.4" coordinatorlayout = "androidx.coordinatorlayout:coordinatorlayout:1.2.0"