mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-29 11:08:53 +03:00
Remove ability to set in-app language differently from system's
This commit is contained in:
parent
664e5cfb59
commit
03980b2f27
8 changed files with 18 additions and 167 deletions
|
@ -232,11 +232,6 @@ object Migrations {
|
||||||
putString(PreferenceKeys.librarySortingDirection, newSortingDirection.name)
|
putString(PreferenceKeys.librarySortingDirection, newSortingDirection.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (oldVersion < 65) {
|
|
||||||
if (preferences.lang().get() in listOf("en-US", "en-GB")) {
|
|
||||||
preferences.lang().set("en")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -178,8 +178,6 @@ object PreferenceKeys {
|
||||||
|
|
||||||
const val libraryDisplayMode = "pref_display_mode_library"
|
const val libraryDisplayMode = "pref_display_mode_library"
|
||||||
|
|
||||||
const val lang = "app_language"
|
|
||||||
|
|
||||||
const val dateFormat = "app_date_format"
|
const val dateFormat = "app_date_format"
|
||||||
|
|
||||||
const val defaultCategory = "default_category"
|
const val defaultCategory = "default_category"
|
||||||
|
|
|
@ -280,8 +280,6 @@ class PreferencesHelper(val context: Context) {
|
||||||
fun downloadNewCategories() = flowPrefs.getStringSet(Keys.downloadNewCategories, emptySet())
|
fun downloadNewCategories() = flowPrefs.getStringSet(Keys.downloadNewCategories, emptySet())
|
||||||
fun downloadNewCategoriesExclude() = flowPrefs.getStringSet(Keys.downloadNewCategoriesExclude, emptySet())
|
fun downloadNewCategoriesExclude() = flowPrefs.getStringSet(Keys.downloadNewCategoriesExclude, emptySet())
|
||||||
|
|
||||||
fun lang() = flowPrefs.getString(Keys.lang, "")
|
|
||||||
|
|
||||||
fun defaultCategory() = prefs.getInt(Keys.defaultCategory, -1)
|
fun defaultCategory() = prefs.getInt(Keys.defaultCategory, -1)
|
||||||
|
|
||||||
fun categorisedDisplaySettings() = flowPrefs.getBoolean(Keys.categorizedDisplay, false)
|
fun categorisedDisplaySettings() = flowPrefs.getBoolean(Keys.categorizedDisplay, false)
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package eu.kanade.tachiyomi.ui.base.activity
|
package eu.kanade.tachiyomi.ui.base.activity
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||||
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
||||||
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
|
||||||
import nucleus.view.NucleusAppCompatActivity
|
import nucleus.view.NucleusAppCompatActivity
|
||||||
|
|
||||||
abstract class BaseRxActivity<VB : ViewBinding, P : BasePresenter<*>> : NucleusAppCompatActivity<P>() {
|
abstract class BaseRxActivity<VB : ViewBinding, P : BasePresenter<*>> : NucleusAppCompatActivity<P>() {
|
||||||
|
@ -15,10 +13,6 @@ abstract class BaseRxActivity<VB : ViewBinding, P : BasePresenter<*>> : NucleusA
|
||||||
|
|
||||||
lateinit var binding: VB
|
lateinit var binding: VB
|
||||||
|
|
||||||
override fun attachBaseContext(newBase: Context) {
|
|
||||||
super.attachBaseContext(LocaleHelper.createLocaleWrapper(newBase))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,16 @@
|
||||||
package eu.kanade.tachiyomi.ui.base.activity
|
package eu.kanade.tachiyomi.ui.base.activity
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues
|
import eu.kanade.tachiyomi.data.preference.PreferenceValues
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
abstract class BaseThemedActivity : AppCompatActivity() {
|
abstract class BaseThemedActivity : AppCompatActivity() {
|
||||||
|
|
||||||
val preferences: PreferencesHelper by injectLazy()
|
val preferences: PreferencesHelper by injectLazy()
|
||||||
|
|
||||||
override fun attachBaseContext(newBase: Context) {
|
|
||||||
super.attachBaseContext(LocaleHelper.createLocaleWrapper(newBase))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
applyAppTheme(preferences)
|
applyAppTheme(preferences)
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
|
@ -16,7 +16,6 @@ import eu.kanade.tachiyomi.util.preference.preference
|
||||||
import eu.kanade.tachiyomi.util.preference.preferenceCategory
|
import eu.kanade.tachiyomi.util.preference.preferenceCategory
|
||||||
import eu.kanade.tachiyomi.util.preference.switchPreference
|
import eu.kanade.tachiyomi.util.preference.switchPreference
|
||||||
import eu.kanade.tachiyomi.util.preference.titleRes
|
import eu.kanade.tachiyomi.util.preference.titleRes
|
||||||
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
|
||||||
import eu.kanade.tachiyomi.util.system.isTablet
|
import eu.kanade.tachiyomi.util.system.isTablet
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import java.util.Date
|
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 {
|
preferenceCategory {
|
||||||
titleRes = R.string.pref_category_theme
|
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<Pair<String, String>>()
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,9 @@
|
||||||
package eu.kanade.tachiyomi.util.system
|
package eu.kanade.tachiyomi.util.system
|
||||||
|
|
||||||
import android.content.Context
|
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 androidx.core.os.LocaleListCompat
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
|
||||||
import eu.kanade.tachiyomi.ui.browse.source.SourcePresenter
|
import eu.kanade.tachiyomi.ui.browse.source.SourcePresenter
|
||||||
import uy.kohesive.injekt.injectLazy
|
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,8 +11,6 @@ import java.util.Locale
|
||||||
*/
|
*/
|
||||||
object LocaleHelper {
|
object LocaleHelper {
|
||||||
|
|
||||||
private val preferences: PreferencesHelper by injectLazy()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns Display name of a string language code
|
* Returns Display name of a string language code
|
||||||
*/
|
*/
|
||||||
|
@ -50,21 +42,6 @@ object LocaleHelper {
|
||||||
return locale.getDisplayName(locale).replaceFirstChar { it.uppercase(locale) }
|
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
|
* Return Locale from string language code
|
||||||
*/
|
*/
|
||||||
|
@ -76,16 +53,4 @@ object LocaleHelper {
|
||||||
else -> Locale(lang)
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,6 @@
|
||||||
|
|
||||||
<!-- General section -->
|
<!-- General section -->
|
||||||
<string name="pref_category_theme">Theme</string>
|
<string name="pref_category_theme">Theme</string>
|
||||||
<string name="pref_category_locale">Locale</string>
|
|
||||||
<string name="pref_theme_mode">Dark mode</string>
|
<string name="pref_theme_mode">Dark mode</string>
|
||||||
<string name="theme_system">Follow system</string>
|
<string name="theme_system">Follow system</string>
|
||||||
<string name="theme_light">Off</string>
|
<string name="theme_light">Off</string>
|
||||||
|
@ -158,7 +157,6 @@
|
||||||
<string name="theme_yotsuba">Yotsuba</string>
|
<string name="theme_yotsuba">Yotsuba</string>
|
||||||
<string name="pref_dark_theme_pure_black">Pure black dark mode</string>
|
<string name="pref_dark_theme_pure_black">Pure black dark mode</string>
|
||||||
<string name="pref_start_screen">Start screen</string>
|
<string name="pref_start_screen">Start screen</string>
|
||||||
<string name="pref_language">Language</string>
|
|
||||||
<string name="system_default">Default</string>
|
<string name="system_default">Default</string>
|
||||||
<string name="pref_date_format">Date format</string>
|
<string name="pref_date_format">Date format</string>
|
||||||
<string name="pref_confirm_exit">Confirm exit</string>
|
<string name="pref_confirm_exit">Confirm exit</string>
|
||||||
|
|
Loading…
Reference in a new issue