Show locale name in system default locale

This commit is contained in:
arkon 2020-04-18 22:48:52 -04:00
parent ca47446b46
commit 359d4dc1b2
9 changed files with 23 additions and 12 deletions

View file

@ -73,7 +73,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
binding.extensionTitle.text = extension.name binding.extensionTitle.text = extension.name
binding.extensionVersion.text = context.getString(R.string.ext_version_info, extension.versionName) 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 binding.extensionPkg.text = extension.pkgName
extension.getApplicationIcon(context)?.let { binding.extensionIcon.setImageDrawable(it) } extension.getApplicationIcon(context)?.let { binding.extensionIcon.setImageDrawable(it) }
binding.extensionUninstallButton.clicks() binding.extensionUninstallButton.clicks()

View file

@ -31,7 +31,7 @@ class ExtensionFilterController : SettingsController() {
availableLangs.forEach { availableLangs.forEach {
switchPreference { switchPreference {
preferenceScreen.addPreference(this) preferenceScreen.addPreference(this)
title = LocaleHelper.getDisplayName(it, context) title = LocaleHelper.getSourceDisplayName(it, context)
isPersistent = false isPersistent = false
isChecked = it in activeLangs isChecked = it in activeLangs

View file

@ -42,7 +42,7 @@ class ExtensionHolder(view: View, override val adapter: ExtensionAdapter) :
ext_title.text = extension.name ext_title.text = extension.name
version.text = extension.versionName version.text = extension.versionName
lang.text = if (extension !is Extension.Untrusted) { lang.text = if (extension !is Extension.Untrusted) {
LocaleHelper.getDisplayName(extension.lang, itemView.context) LocaleHelper.getSourceDisplayName(extension.lang, itemView.context)
} else { } else {
itemView.context.getString(R.string.ext_untrusted).toUpperCase() itemView.context.getString(R.string.ext_untrusted).toUpperCase()
} }

View file

@ -90,7 +90,7 @@ open class ExtensionPresenter(
} }
if (availableSorted.isNotEmpty()) { if (availableSorted.isNotEmpty()) {
val availableGroupedByLang = availableSorted val availableGroupedByLang = availableSorted
.groupBy { LocaleHelper.getDisplayName(it.lang, context) } .groupBy { LocaleHelper.getSourceDisplayName(it.lang, context) }
.toSortedMap() .toSortedMap()
availableGroupedByLang availableGroupedByLang

View file

@ -62,15 +62,14 @@ class SettingsGeneralController : SettingsController() {
titleRes = R.string.pref_language titleRes = R.string.pref_language
val langs = mutableListOf<Pair<String, String>>() val langs = mutableListOf<Pair<String, String>>()
langs += Pair("", context.getString(R.string.system_default)) langs += Pair("", "${context.getString(R.string.system_default)} (${LocaleHelper.getDisplayName("")})")
langs += arrayOf( langs += arrayOf(
"ar", "bg", "bn", "ca", "cs", "de", "el", "en-US", "en-GB", "es", "fr", "he", "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", "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" "pt-BR", "ro", "ru", "sc", "sr", "sv", "th", "tl", "tr", "uk", "vi", "zh-rCN"
) )
.map { .map {
val locale = LocaleHelper.getLocaleFromString(it) Pair(it, LocaleHelper.getDisplayName(it))
Pair(it, locale!!.getDisplayName(locale).capitalize())
} }
.sortedBy { it.second } .sortedBy { it.second }

View file

@ -40,7 +40,7 @@ class SettingsSourcesController : SettingsController() {
// Create a preference group and set initial state and change listener // Create a preference group and set initial state and change listener
switchPreferenceCategory { switchPreferenceCategory {
preferenceScreen.addPreference(this) preferenceScreen.addPreference(this)
title = LocaleHelper.getDisplayName(lang, context) title = LocaleHelper.getSourceDisplayName(lang, context)
isPersistent = false isPersistent = false
if (lang in activeLangsCodes) { if (lang in activeLangsCodes) {
setChecked(true) setChecked(true)

View file

@ -10,6 +10,6 @@ class LangHolder(view: View, adapter: FlexibleAdapter<*>) :
BaseFlexibleViewHolder(view, adapter) { BaseFlexibleViewHolder(view, adapter) {
fun bind(item: LangItem) { fun bind(item: LangItem) {
title.text = LocaleHelper.getDisplayName(item.code, itemView.context) title.text = LocaleHelper.getSourceDisplayName(item.code, itemView.context)
} }
} }

View file

@ -47,12 +47,24 @@ object LocaleHelper {
/** /**
* Returns Display name of a string language code * 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) { return when (lang) {
null -> ""
"" -> context.getString(R.string.other_source) "" -> context.getString(R.string.other_source)
SourcePresenter.PINNED_KEY -> context.getString(R.string.pinned_sources) SourcePresenter.PINNED_KEY -> context.getString(R.string.pinned_sources)
"all" -> context.getString(R.string.all_lang) "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 -> { else -> {
val locale = getLocale(lang) val locale = getLocale(lang)
locale.getDisplayName(locale).capitalize() locale.getDisplayName(locale).capitalize()

View file

@ -142,7 +142,7 @@
<string name="theme_dark_amoled">AMOLED black</string> <string name="theme_dark_amoled">AMOLED black</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="pref_language">Language</string>
<string name="system_default">System 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>
<string name="pref_manage_notifications">Manage notifications</string> <string name="pref_manage_notifications">Manage notifications</string>