From 03980b2f27bc80bc578808f86a1e114a72a3559e Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 6 Aug 2021 16:45:40 -0400 Subject: [PATCH] Remove ability to set in-app language differently from system's --- .../java/eu/kanade/tachiyomi/Migrations.kt | 5 - .../data/preference/PreferenceKeys.kt | 2 - .../data/preference/PreferencesHelper.kt | 2 - .../ui/base/activity/BaseRxActivity.kt | 6 - .../ui/base/activity/BaseThemedActivity.kt | 6 - .../ui/setting/SettingsGeneralController.kt | 127 +++--------------- .../tachiyomi/util/system/LocaleHelper.kt | 35 ----- app/src/main/res/values/strings.xml | 2 - 8 files changed, 18 insertions(+), 167 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index 21de124a81..afdcd30c8e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -232,11 +232,6 @@ object Migrations { putString(PreferenceKeys.librarySortingDirection, newSortingDirection.name) } } - if (oldVersion < 65) { - if (preferences.lang().get() in listOf("en-US", "en-GB")) { - preferences.lang().set("en") - } - } return true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 4e56cb3715..404d760c7a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -178,8 +178,6 @@ object PreferenceKeys { const val libraryDisplayMode = "pref_display_mode_library" - const val lang = "app_language" - const val dateFormat = "app_date_format" const val defaultCategory = "default_category" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index bfa5a1e94a..fd2fd47e40 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -280,8 +280,6 @@ class PreferencesHelper(val context: Context) { fun downloadNewCategories() = flowPrefs.getStringSet(Keys.downloadNewCategories, emptySet()) fun downloadNewCategoriesExclude() = flowPrefs.getStringSet(Keys.downloadNewCategoriesExclude, emptySet()) - fun lang() = flowPrefs.getString(Keys.lang, "") - fun defaultCategory() = prefs.getInt(Keys.defaultCategory, -1) fun categorisedDisplaySettings() = flowPrefs.getBoolean(Keys.categorizedDisplay, false) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt index 8cfac8084a..f7ab4f104a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt @@ -1,11 +1,9 @@ package eu.kanade.tachiyomi.ui.base.activity -import android.content.Context import android.os.Bundle import androidx.viewbinding.ViewBinding import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate -import eu.kanade.tachiyomi.util.system.LocaleHelper import nucleus.view.NucleusAppCompatActivity abstract class BaseRxActivity> : NucleusAppCompatActivity

() { @@ -15,10 +13,6 @@ abstract class BaseRxActivity> : NucleusA lateinit var binding: VB - override fun attachBaseContext(newBase: Context) { - super.attachBaseContext(LocaleHelper.createLocaleWrapper(newBase)) - } - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt index 20cc552902..0926ae1834 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt @@ -1,22 +1,16 @@ package eu.kanade.tachiyomi.ui.base.activity -import android.content.Context import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.util.system.LocaleHelper import uy.kohesive.injekt.injectLazy abstract class BaseThemedActivity : AppCompatActivity() { val preferences: PreferencesHelper by injectLazy() - override fun attachBaseContext(newBase: Context) { - super.attachBaseContext(LocaleHelper.createLocaleWrapper(newBase)) - } - override fun onCreate(savedInstanceState: Bundle?) { applyAppTheme(preferences) super.onCreate(savedInstanceState) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index 6fab558adb..1747223b24 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -16,7 +16,6 @@ import eu.kanade.tachiyomi.util.preference.preference import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.titleRes -import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.isTablet import kotlinx.coroutines.flow.launchIn import java.util.Date @@ -79,6 +78,24 @@ class SettingsGeneralController : SettingsController() { } } } + listPreference { + key = Keys.dateFormat + titleRes = R.string.pref_date_format + entryValues = arrayOf("", "MM/dd/yy", "dd/MM/yy", "yyyy-MM-dd", "dd MMM yyyy", "MMM dd, yyyy") + + val now = Date().time + entries = entryValues.map { value -> + val formattedDate = preferences.dateFormat(value.toString()).format(now) + if (value == "") { + "${context.getString(R.string.system_default)} ($formattedDate)" + } else { + "$value ($formattedDate)" + } + }.toTypedArray() + + defaultValue = "" + summary = "%s" + } preferenceCategory { titleRes = R.string.pref_category_theme @@ -149,113 +166,5 @@ class SettingsGeneralController : SettingsController() { } } } - - preferenceCategory { - titleRes = R.string.pref_category_locale - - listPreference { - key = Keys.lang - titleRes = R.string.pref_language - - val langs = mutableListOf>() - langs += Pair( - "", - "${context.getString(R.string.system_default)} (${LocaleHelper.getDisplayName("")})" - ) - // Due to compatibility issues: - // - Hebrew: `he` is copied into `iw` at build time - langs += arrayOf( - "am", - "ar", - "be", - "bg", - "bn", - "ca", - "cs", - "cv", - "de", - "el", - "eo", - "es", - "es-419", - "en", - "fa", - "fi", - "fil", - "fr", - "gl", - "he", - "hi", - "hr", - "hu", - "in", - "it", - "ja", - "jv", - "ka-rGE", - "kn", - "ko", - "lt", - "lv", - "mr", - "ms", - "my", - "nb-rNO", - "ne", - "nl", - "pl", - "pt", - "pt-BR", - "ro", - "ru", - "sah", - "sc", - "sk", - "sr", - "sv", - "te", - "th", - "tr", - "uk", - "ur-rPK", - "vi", - "uz", - "zh-rCN", - "zh-rTW" - ) - .map { - Pair(it, LocaleHelper.getDisplayName(it)) - } - .sortedBy { it.second } - - entryValues = langs.map { it.first }.toTypedArray() - entries = langs.map { it.second }.toTypedArray() - defaultValue = "" - summary = "%s" - - onChange { newValue -> - activity?.recreate() - true - } - } - listPreference { - key = Keys.dateFormat - titleRes = R.string.pref_date_format - entryValues = arrayOf("", "MM/dd/yy", "dd/MM/yy", "yyyy-MM-dd", "dd MMM yyyy", "MMM dd, yyyy") - - val now = Date().time - entries = entryValues.map { value -> - val formattedDate = preferences.dateFormat(value.toString()).format(now) - if (value == "") { - "${context.getString(R.string.system_default)} ($formattedDate)" - } else { - "$value ($formattedDate)" - } - }.toTypedArray() - - defaultValue = "" - summary = "%s" - } - } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt index d072e48e61..c4580bbcd4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt @@ -1,15 +1,9 @@ package eu.kanade.tachiyomi.util.system import android.content.Context -import android.content.ContextWrapper -import android.content.res.Configuration -import android.os.Build -import android.os.LocaleList import androidx.core.os.LocaleListCompat import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.browse.source.SourcePresenter -import uy.kohesive.injekt.injectLazy import java.util.Locale /** @@ -17,8 +11,6 @@ import java.util.Locale */ object LocaleHelper { - private val preferences: PreferencesHelper by injectLazy() - /** * Returns Display name of a string language code */ @@ -50,21 +42,6 @@ object LocaleHelper { return locale.getDisplayName(locale).replaceFirstChar { it.uppercase(locale) } } - /** - * Creates a ContextWrapper using selected Locale - */ - fun createLocaleWrapper(context: Context): ContextWrapper { - val appLocale = getLocaleFromString(preferences.lang().get()) - val newConfiguration = Configuration(context.resources.configuration) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - val localeList = LocaleList(appLocale) - newConfiguration.setLocales(localeList) - } else { - newConfiguration.setLocale(appLocale) - } - return ContextWrapper(context.createConfigurationContext(newConfiguration)) - } - /** * Return Locale from string language code */ @@ -76,16 +53,4 @@ object LocaleHelper { else -> Locale(lang) } } - - /** - * Returns the locale for the value stored in preferences, defaults to main system language. - * - * @param pref the string value stored in preferences. - */ - private fun getLocaleFromString(pref: String?): Locale { - if (pref.isNullOrEmpty()) { - return LocaleListCompat.getDefault()[0] - } - return getLocale(pref) - } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9c284216a0..8e9745f348 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -141,7 +141,6 @@ Theme - Locale Dark mode Follow system Off @@ -158,7 +157,6 @@ Yotsuba Pure black dark mode Start screen - Language Default Date format Confirm exit