From 359d4dc1b2306fc778101e021827b54c95f56690 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 18 Apr 2020 22:48:52 -0400 Subject: [PATCH] Show locale name in system default locale --- .../ui/extension/ExtensionDetailsController.kt | 2 +- .../ui/extension/ExtensionFilterController.kt | 2 +- .../tachiyomi/ui/extension/ExtensionHolder.kt | 2 +- .../tachiyomi/ui/extension/ExtensionPresenter.kt | 2 +- .../ui/setting/SettingsGeneralController.kt | 5 ++--- .../ui/setting/SettingsSourcesController.kt | 2 +- .../eu/kanade/tachiyomi/ui/source/LangHolder.kt | 2 +- .../kanade/tachiyomi/util/system/LocaleHelper.kt | 16 ++++++++++++++-- app/src/main/res/values/strings.xml | 2 +- 9 files changed, 23 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt index 8936b6222..8e57c716c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt @@ -73,7 +73,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) : binding.extensionTitle.text = extension.name binding.extensionVersion.text = context.getString(R.string.ext_version_info, extension.versionName) - binding.extensionLang.text = context.getString(R.string.ext_language_info, LocaleHelper.getDisplayName(extension.lang, context)) + binding.extensionLang.text = context.getString(R.string.ext_language_info, LocaleHelper.getSourceDisplayName(extension.lang, context)) binding.extensionPkg.text = extension.pkgName extension.getApplicationIcon(context)?.let { binding.extensionIcon.setImageDrawable(it) } binding.extensionUninstallButton.clicks() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionFilterController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionFilterController.kt index 4dbba8918..81f85c13b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionFilterController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionFilterController.kt @@ -31,7 +31,7 @@ class ExtensionFilterController : SettingsController() { availableLangs.forEach { switchPreference { preferenceScreen.addPreference(this) - title = LocaleHelper.getDisplayName(it, context) + title = LocaleHelper.getSourceDisplayName(it, context) isPersistent = false isChecked = it in activeLangs diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt index 5fe0037a2..6e3d66766 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt @@ -42,7 +42,7 @@ class ExtensionHolder(view: View, override val adapter: ExtensionAdapter) : ext_title.text = extension.name version.text = extension.versionName lang.text = if (extension !is Extension.Untrusted) { - LocaleHelper.getDisplayName(extension.lang, itemView.context) + LocaleHelper.getSourceDisplayName(extension.lang, itemView.context) } else { itemView.context.getString(R.string.ext_untrusted).toUpperCase() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionPresenter.kt index e66f40b10..cf493bc69 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionPresenter.kt @@ -90,7 +90,7 @@ open class ExtensionPresenter( } if (availableSorted.isNotEmpty()) { val availableGroupedByLang = availableSorted - .groupBy { LocaleHelper.getDisplayName(it.lang, context) } + .groupBy { LocaleHelper.getSourceDisplayName(it.lang, context) } .toSortedMap() availableGroupedByLang 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 b5875a982..96b60c6b6 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 @@ -62,15 +62,14 @@ class SettingsGeneralController : SettingsController() { titleRes = R.string.pref_language val langs = mutableListOf>() - langs += Pair("", context.getString(R.string.system_default)) + langs += Pair("", "${context.getString(R.string.system_default)} (${LocaleHelper.getDisplayName("")})") langs += arrayOf( "ar", "bg", "bn", "ca", "cs", "de", "el", "en-US", "en-GB", "es", "fr", "he", "hi", "hu", "in", "it", "ja", "ko", "lv", "ms", "nb-rNO", "nl", "pl", "pt", "pt-BR", "ro", "ru", "sc", "sr", "sv", "th", "tl", "tr", "uk", "vi", "zh-rCN" ) .map { - val locale = LocaleHelper.getLocaleFromString(it) - Pair(it, locale!!.getDisplayName(locale).capitalize()) + Pair(it, LocaleHelper.getDisplayName(it)) } .sortedBy { it.second } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt index 3a456522a..3ba9d1b00 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesController.kt @@ -40,7 +40,7 @@ class SettingsSourcesController : SettingsController() { // Create a preference group and set initial state and change listener switchPreferenceCategory { preferenceScreen.addPreference(this) - title = LocaleHelper.getDisplayName(lang, context) + title = LocaleHelper.getSourceDisplayName(lang, context) isPersistent = false if (lang in activeLangsCodes) { setChecked(true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/LangHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/LangHolder.kt index df2d07f23..08c10d197 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/LangHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/LangHolder.kt @@ -10,6 +10,6 @@ class LangHolder(view: View, adapter: FlexibleAdapter<*>) : BaseFlexibleViewHolder(view, adapter) { fun bind(item: LangItem) { - title.text = LocaleHelper.getDisplayName(item.code, itemView.context) + title.text = LocaleHelper.getSourceDisplayName(item.code, itemView.context) } } 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 343630e11..22d42881e 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 @@ -47,12 +47,24 @@ object LocaleHelper { /** * Returns Display name of a string language code */ - fun getDisplayName(lang: String?, context: Context): String { + fun getSourceDisplayName(lang: String?, context: Context): String { return when (lang) { - null -> "" "" -> context.getString(R.string.other_source) SourcePresenter.PINNED_KEY -> context.getString(R.string.pinned_sources) "all" -> context.getString(R.string.all_lang) + else -> getDisplayName(lang) + } + } + + /** + * Returns Display name of a string language code + */ + fun getDisplayName(lang: String?): String { + return when (lang) { + null -> "" + "" -> { + systemLocale!!.getDisplayName(systemLocale).capitalize() + } else -> { val locale = getLocale(lang) locale.getDisplayName(locale).capitalize() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 94309ace7..dcfc4e3f4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -142,7 +142,7 @@ AMOLED black Start screen Language - System default + Default Date format Confirm exit Manage notifications