mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-29 21:03:14 -05:00
Added country/region support for locale when displayed for sources (#1240)
* Added country support for locale when displayed for sources * code review changes/comments fix
This commit is contained in:
parent
50e0cb65d9
commit
1b7a0de745
6 changed files with 40 additions and 32 deletions
|
@ -2,21 +2,14 @@ package eu.kanade.tachiyomi.ui.catalogue
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.kanade.tachiyomi.R
|
|
||||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||||
|
import eu.kanade.tachiyomi.util.LocaleHelper
|
||||||
import kotlinx.android.synthetic.main.catalogue_main_controller_card.*
|
import kotlinx.android.synthetic.main.catalogue_main_controller_card.*
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class LangHolder(view: View, adapter: FlexibleAdapter<*>) :
|
class LangHolder(view: View, adapter: FlexibleAdapter<*>) :
|
||||||
BaseFlexibleViewHolder(view, adapter, true) {
|
BaseFlexibleViewHolder(view, adapter, true) {
|
||||||
|
|
||||||
fun bind(item: LangItem) {
|
fun bind(item: LangItem) {
|
||||||
title.text = when {
|
title.text = LocaleHelper.getDisplayName(item.code, itemView.context)
|
||||||
item.code == "" -> itemView.context.getString(R.string.other_source)
|
|
||||||
else -> {
|
|
||||||
val locale = Locale(item.code)
|
|
||||||
locale.getDisplayName(locale).capitalize()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -22,6 +22,7 @@ import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.online.LoginSource
|
import eu.kanade.tachiyomi.source.online.LoginSource
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||||
import eu.kanade.tachiyomi.ui.setting.preferenceCategory
|
import eu.kanade.tachiyomi.ui.setting.preferenceCategory
|
||||||
|
import eu.kanade.tachiyomi.util.LocaleHelper
|
||||||
import eu.kanade.tachiyomi.widget.preference.LoginPreference
|
import eu.kanade.tachiyomi.widget.preference.LoginPreference
|
||||||
import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog
|
import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog
|
||||||
import kotlinx.android.synthetic.main.extension_detail_controller.*
|
import kotlinx.android.synthetic.main.extension_detail_controller.*
|
||||||
|
@ -62,7 +63,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
|
||||||
|
|
||||||
extension_title.text = extension.name
|
extension_title.text = extension.name
|
||||||
extension_version.text = context.getString(R.string.ext_version_info, extension.versionName)
|
extension_version.text = context.getString(R.string.ext_version_info, extension.versionName)
|
||||||
extension_lang.text = context.getString(R.string.ext_language_info, extension.getLocalizedLang(context))
|
extension_lang.text = context.getString(R.string.ext_language_info, LocaleHelper.getDisplayName(extension.lang, context))
|
||||||
extension_pkg.text = extension.pkgName
|
extension_pkg.text = extension.pkgName
|
||||||
extension.getApplicationIcon(context)?.let { extension_icon.setImageDrawable(it) }
|
extension.getApplicationIcon(context)?.let { extension_icon.setImageDrawable(it) }
|
||||||
extension_uninstall_button.clicks().subscribeUntilDestroy {
|
extension_uninstall_button.clicks().subscribeUntilDestroy {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.extension.model.Extension
|
||||||
import eu.kanade.tachiyomi.extension.model.InstallStep
|
import eu.kanade.tachiyomi.extension.model.InstallStep
|
||||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||||
import eu.kanade.tachiyomi.ui.base.holder.SlicedHolder
|
import eu.kanade.tachiyomi.ui.base.holder.SlicedHolder
|
||||||
|
import eu.kanade.tachiyomi.util.LocaleHelper
|
||||||
import io.github.mthli.slice.Slice
|
import io.github.mthli.slice.Slice
|
||||||
import kotlinx.android.synthetic.main.extension_card_item.*
|
import kotlinx.android.synthetic.main.extension_card_item.*
|
||||||
|
|
||||||
|
@ -35,7 +36,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) {
|
||||||
extension.getLocalizedLang(itemView.context)
|
LocaleHelper.getDisplayName(extension.lang, itemView.context)
|
||||||
} else {
|
} else {
|
||||||
itemView.context.getString(R.string.ext_untrusted).toUpperCase()
|
itemView.context.getString(R.string.ext_untrusted).toUpperCase()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,21 +3,7 @@ package eu.kanade.tachiyomi.ui.extension
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import eu.kanade.tachiyomi.R
|
|
||||||
import eu.kanade.tachiyomi.extension.model.Extension
|
import eu.kanade.tachiyomi.extension.model.Extension
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
fun Extension.getLocalizedLang(context: Context): String {
|
|
||||||
return when (lang) {
|
|
||||||
null -> ""
|
|
||||||
"" -> context.getString(R.string.other_source)
|
|
||||||
"all" -> context.getString(R.string.all_lang)
|
|
||||||
else -> {
|
|
||||||
val locale = Locale(lang)
|
|
||||||
locale.getDisplayName(locale).capitalize()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Extension.getApplicationIcon(context: Context): Drawable? {
|
fun Extension.getApplicationIcon(context: Context): Drawable? {
|
||||||
return try {
|
return try {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
import eu.kanade.tachiyomi.source.online.LoginSource
|
import eu.kanade.tachiyomi.source.online.LoginSource
|
||||||
|
import eu.kanade.tachiyomi.util.LocaleHelper
|
||||||
import eu.kanade.tachiyomi.widget.preference.LoginCheckBoxPreference
|
import eu.kanade.tachiyomi.widget.preference.LoginCheckBoxPreference
|
||||||
import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog
|
import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog
|
||||||
import eu.kanade.tachiyomi.widget.preference.SwitchPreferenceCategory
|
import eu.kanade.tachiyomi.widget.preference.SwitchPreferenceCategory
|
||||||
|
@ -39,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(context).apply {
|
SwitchPreferenceCategory(context).apply {
|
||||||
preferenceScreen.addPreference(this)
|
preferenceScreen.addPreference(this)
|
||||||
title = Locale(lang).let { it.getDisplayLanguage(it).capitalize() }
|
title = LocaleHelper.getDisplayName(lang, context)
|
||||||
isPersistent = false
|
isPersistent = false
|
||||||
if (lang in activeLangsCodes) {
|
if (lang in activeLangsCodes) {
|
||||||
setChecked(true)
|
setChecked(true)
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package eu.kanade.tachiyomi.util
|
package eu.kanade.tachiyomi.util
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.content.Context
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.LocaleList
|
import android.os.LocaleList
|
||||||
import android.view.ContextThemeWrapper
|
import android.view.ContextThemeWrapper
|
||||||
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -45,10 +47,34 @@ object LocaleHelper {
|
||||||
if (pref.isNullOrEmpty()) {
|
if (pref.isNullOrEmpty()) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
val parts = pref.split("_", "-")
|
return getLocale(pref)
|
||||||
val lang = parts[0]
|
}
|
||||||
val country = parts.getOrNull(1) ?: ""
|
|
||||||
return Locale(lang, country)
|
/**
|
||||||
|
* Returns Display name of a string language code
|
||||||
|
*/
|
||||||
|
fun getDisplayName(lang: String?, context: Context): String {
|
||||||
|
return when (lang) {
|
||||||
|
null -> ""
|
||||||
|
"" -> context.getString(R.string.other_source)
|
||||||
|
"all" -> context.getString(R.string.all_lang)
|
||||||
|
else -> {
|
||||||
|
val locale = getLocale(lang)
|
||||||
|
locale.getDisplayName(locale).capitalize()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Return Locale from string language code
|
||||||
|
|
||||||
|
*/
|
||||||
|
private fun getLocale(lang: String): Locale {
|
||||||
|
val sp = lang.split("_", "-")
|
||||||
|
return when (sp.size) {
|
||||||
|
2 -> Locale(sp[0], sp[1])
|
||||||
|
3 -> Locale(sp[0], sp[1], sp[2])
|
||||||
|
else -> Locale(lang)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue