From 1a3a1db4ffbfcd91a6964c87ab9a922ec4608ea9 Mon Sep 17 00:00:00 2001 From: len Date: Mon, 26 Dec 2016 15:44:59 +0100 Subject: [PATCH] Remove Language class. App's language and hidden languages settings were reset --- .../data/preference/PreferencesHelper.kt | 4 +-- .../kanade/tachiyomi/data/source/Language.kt | 9 ------ .../data/source/online/OnlineSource.kt | 7 ++--- .../data/source/online/YamlOnlineSource.kt | 7 ++--- .../data/source/online/english/Batoto.kt | 4 +-- .../data/source/online/english/Kissmanga.kt | 5 +--- .../data/source/online/english/Mangafox.kt | 4 +-- .../data/source/online/english/Mangahere.kt | 4 +-- .../data/source/online/english/Mangasee.kt | 4 +-- .../source/online/english/Readmangatoday.kt | 5 +--- .../data/source/online/german/WieManga.kt | 5 +--- .../data/source/online/russian/Mangachan.kt | 4 +-- .../data/source/online/russian/Mintmanga.kt | 4 +-- .../data/source/online/russian/Readmanga.kt | 4 +-- .../ui/catalogue/CataloguePresenter.kt | 7 ++--- .../ui/setting/SettingsGeneralFragment.kt | 11 ++++++-- .../ui/setting/SettingsSourcesFragment.kt | 28 ++++++++++--------- .../eu/kanade/tachiyomi/util/LocaleHelper.kt | 27 ++++++++---------- app/src/main/res/values-it/strings.xml | 6 ---- app/src/main/res/values/arrays.xml | 18 ++++-------- app/src/main/res/values/keys.xml | 4 +-- app/src/main/res/values/strings.xml | 8 +----- app/src/main/res/xml/pref_general.xml | 5 ++-- 23 files changed, 66 insertions(+), 118 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/source/Language.kt 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 66740a4fa8..613fa05046 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 @@ -82,7 +82,7 @@ class PreferencesHelper(val context: Context) { fun catalogueAsList() = rxPrefs.getBoolean(keys.catalogueAsList, false) - fun enabledLanguages() = rxPrefs.getStringSet(keys.enabledLanguages, setOf("EN")) + fun enabledLanguages() = rxPrefs.getStringSet(keys.enabledLanguages, setOf("en")) fun sourceUsername(source: Source) = prefs.getString(keys.sourceUsername(source.id), "") @@ -142,6 +142,6 @@ class PreferencesHelper(val context: Context) { fun downloadNew() = prefs.getBoolean(keys.downloadNew, false) - fun lang() = prefs.getInt(keys.lang, 0) + fun lang() = prefs.getString(keys.lang, "") } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/Language.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/Language.kt deleted file mode 100644 index bbccebad96..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/Language.kt +++ /dev/null @@ -1,9 +0,0 @@ -package eu.kanade.tachiyomi.data.source - -class Language(val code: String, val lang: String) - -val DE = Language("DE", "German") -val EN = Language("EN", "English") -val RU = Language("RU", "Russian") - -fun getLanguages() = listOf(DE, EN, RU) \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt index 2746084477..611fcc06d3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt @@ -9,7 +9,6 @@ import eu.kanade.tachiyomi.data.network.NetworkHelper import eu.kanade.tachiyomi.data.network.asObservableSuccess import eu.kanade.tachiyomi.data.network.newCallWithProgress import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.source.Language import eu.kanade.tachiyomi.data.source.Source import eu.kanade.tachiyomi.data.source.model.MangasPage import eu.kanade.tachiyomi.data.source.model.Page @@ -47,9 +46,9 @@ abstract class OnlineSource() : Source { abstract val baseUrl: String /** - * Language of the source. + * An ISO 639-1 compliant language code (two characters in lower case). */ - abstract val lang: Language + abstract val lang: String /** * Whether the source has support for latest updates. @@ -82,7 +81,7 @@ abstract class OnlineSource() : Source { /** * Visible name of the source. */ - override fun toString() = "$name (${lang.code})" + override fun toString() = "$name (${lang.toUpperCase()})" /** * Returns an observable containing a page with a list of manga. Normally it's not needed to diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt index b10f0fe10b..4b2f3bcb2a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/YamlOnlineSource.kt @@ -4,7 +4,6 @@ import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.network.GET import eu.kanade.tachiyomi.data.network.POST -import eu.kanade.tachiyomi.data.source.getLanguages import eu.kanade.tachiyomi.data.source.model.MangasPage import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.util.asJsoup @@ -27,9 +26,7 @@ class YamlOnlineSource(mappings: Map<*, *>) : OnlineSource() { if (it.endsWith("/")) it.dropLast(1) else it } - override val lang = map.lang.toUpperCase().let { code -> - getLanguages().find { code == it.code }!! - } + override val lang = map.lang.toLowerCase() override val supportsLatest = map.latestupdates != null @@ -39,7 +36,7 @@ class YamlOnlineSource(mappings: Map<*, *>) : OnlineSource() { } override val id = map.id.let { - if (it is Int) it else (lang.code.hashCode() + 31 * it.hashCode()) and 0x7fffffff + if (it is Int) it else (lang.toUpperCase().hashCode() + 31 * it.hashCode()) and 0x7fffffff } override fun popularMangaRequest(page: MangasPage): Request { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt index 028e24fda0..19c678087c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.kt @@ -7,8 +7,6 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.network.GET import eu.kanade.tachiyomi.data.network.POST import eu.kanade.tachiyomi.data.network.asObservable -import eu.kanade.tachiyomi.data.source.EN -import eu.kanade.tachiyomi.data.source.Language import eu.kanade.tachiyomi.data.source.model.MangasPage import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.online.LoginSource @@ -33,7 +31,7 @@ class Batoto(override val id: Int) : ParsedOnlineSource(), LoginSource { override val baseUrl = "http://bato.to" - override val lang: Language get() = EN + override val lang = "en" override val supportsLatest = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt index c8c45b0c1f..767ae01372 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Kissmanga.kt @@ -1,12 +1,9 @@ package eu.kanade.tachiyomi.data.source.online.english -import android.content.Context import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.network.GET import eu.kanade.tachiyomi.data.network.POST -import eu.kanade.tachiyomi.data.source.EN -import eu.kanade.tachiyomi.data.source.Language import eu.kanade.tachiyomi.data.source.model.MangasPage import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource @@ -25,7 +22,7 @@ class Kissmanga(override val id: Int) : ParsedOnlineSource() { override val baseUrl = "http://kissmanga.com" - override val lang: Language get() = EN + override val lang = "en" override val supportsLatest = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt index dda9f62d1e..31b580c7a2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangafox.kt @@ -2,8 +2,6 @@ package eu.kanade.tachiyomi.data.source.online.english import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.source.EN -import eu.kanade.tachiyomi.data.source.Language import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource import eu.kanade.tachiyomi.util.asJsoup @@ -20,7 +18,7 @@ class Mangafox(override val id: Int) : ParsedOnlineSource() { override val baseUrl = "http://mangafox.me" - override val lang: Language get() = EN + override val lang = "en" override val supportsLatest = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt index a2d83e4832..b5d8c9989a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt @@ -2,8 +2,6 @@ package eu.kanade.tachiyomi.data.source.online.english import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.source.EN -import eu.kanade.tachiyomi.data.source.Language import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource import org.jsoup.nodes.Document @@ -18,7 +16,7 @@ class Mangahere(override val id: Int) : ParsedOnlineSource() { override val baseUrl = "http://www.mangahere.co" - override val lang: Language get() = EN + override val lang = "en" override val supportsLatest = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangasee.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangasee.kt index 7d2eea2cba..6e29363bd5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangasee.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangasee.kt @@ -3,8 +3,6 @@ package eu.kanade.tachiyomi.data.source.online.english import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.network.POST -import eu.kanade.tachiyomi.data.source.EN -import eu.kanade.tachiyomi.data.source.Language import eu.kanade.tachiyomi.data.source.model.MangasPage import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource @@ -24,7 +22,7 @@ class Mangasee(override val id: Int) : ParsedOnlineSource() { override val baseUrl = "http://mangaseeonline.net" - override val lang: Language get() = EN + override val lang = "en" override val supportsLatest = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt index 6f74f3768d..5422c7ddb0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Readmangatoday.kt @@ -1,11 +1,8 @@ package eu.kanade.tachiyomi.data.source.online.english -import android.content.Context import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.network.POST -import eu.kanade.tachiyomi.data.source.EN -import eu.kanade.tachiyomi.data.source.Language import eu.kanade.tachiyomi.data.source.model.MangasPage import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.online.OnlineSource @@ -23,7 +20,7 @@ class Readmangatoday(override val id: Int) : ParsedOnlineSource() { override val baseUrl = "http://www.readmanga.today" - override val lang: Language get() = EN + override val lang = "en" override val supportsLatest = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/german/WieManga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/german/WieManga.kt index b33fbe45c0..9958792dc5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/german/WieManga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/german/WieManga.kt @@ -1,10 +1,7 @@ package eu.kanade.tachiyomi.data.source.online.german -import android.content.Context import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.source.DE -import eu.kanade.tachiyomi.data.source.Language import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource import eu.kanade.tachiyomi.util.asJsoup @@ -19,7 +16,7 @@ class WieManga(override val id: Int) : ParsedOnlineSource() { override val baseUrl = "http://www.wiemanga.com" - override val lang: Language get() = DE + override val lang = "de" override val supportsLatest = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mangachan.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mangachan.kt index b9f561cab6..9075fa6f8c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mangachan.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mangachan.kt @@ -2,8 +2,6 @@ package eu.kanade.tachiyomi.data.source.online.russian import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.source.Language -import eu.kanade.tachiyomi.data.source.RU import eu.kanade.tachiyomi.data.source.model.MangasPage import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource @@ -20,7 +18,7 @@ class Mangachan(override val id: Int) : ParsedOnlineSource() { override val baseUrl = "http://mangachan.me" - override val lang: Language get() = RU + override val lang = "ru" override val supportsLatest = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mintmanga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mintmanga.kt index f7a7da7685..2e1755676f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mintmanga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mintmanga.kt @@ -2,8 +2,6 @@ package eu.kanade.tachiyomi.data.source.online.russian import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.source.Language -import eu.kanade.tachiyomi.data.source.RU import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource import okhttp3.Response @@ -19,7 +17,7 @@ class Mintmanga(override val id: Int) : ParsedOnlineSource() { override val baseUrl = "http://mintmanga.com" - override val lang: Language get() = RU + override val lang = "ru" override val supportsLatest = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Readmanga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Readmanga.kt index 0f57c4ef06..f3005a502d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Readmanga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Readmanga.kt @@ -2,8 +2,6 @@ package eu.kanade.tachiyomi.data.source.online.russian import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.source.Language -import eu.kanade.tachiyomi.data.source.RU import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource import okhttp3.Response @@ -19,7 +17,7 @@ class Readmanga(override val id: Int) : ParsedOnlineSource() { override val baseUrl = "http://readmanga.me" - override val lang: Language get() = RU + override val lang = "ru" override val supportsLatest = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CataloguePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CataloguePresenter.kt index df0d3ebbd3..a355073768 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CataloguePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CataloguePresenter.kt @@ -6,7 +6,6 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault -import eu.kanade.tachiyomi.data.source.EN import eu.kanade.tachiyomi.data.source.Source import eu.kanade.tachiyomi.data.source.SourceManager import eu.kanade.tachiyomi.data.source.model.MangasPage @@ -333,13 +332,13 @@ open class CataloguePresenter : BasePresenter() { // Ensure at least one language if (languages.isEmpty()) { - languages.add(EN.code) + languages.add("en") } return sourceManager.getOnlineSources() - .filter { it.lang.code in languages } + .filter { it.lang in languages } .filterNot { it.id.toString() in hiddenCatalogues } - .sortedBy { "(${it.lang.code}) ${it.name}" } + .sortedBy { "(${it.lang}) ${it.name}" } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralFragment.kt index 120938bffe..78fddd26f7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralFragment.kt @@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.util.plusAssign import eu.kanade.tachiyomi.widget.preference.IntListPreference import eu.kanade.tachiyomi.widget.preference.LibraryColumnsDialog import eu.kanade.tachiyomi.widget.preference.SimpleDialogPreference +import net.xpece.android.support.preference.ListPreference import net.xpece.android.support.preference.MultiSelectListPreference import rx.Observable import rx.android.schedulers.AndroidSchedulers @@ -45,7 +46,7 @@ class SettingsGeneralFragment : SettingsFragment(), val categoryUpdate: MultiSelectListPreference by bindPref(R.string.pref_library_update_categories_key) - val langPreference: IntListPreference by bindPref(R.string.pref_language_key) + val langPreference: ListPreference by bindPref(R.string.pref_language_key) override fun onViewCreated(view: View, savedState: Bundle?) { super.onViewCreated(view, savedState) @@ -105,9 +106,15 @@ class SettingsGeneralFragment : SettingsFragment(), true } + val langValues = langPreference.entryValues.map { value -> + val locale = LocaleHelper.getLocaleFromString(value.toString()) + locale?.getDisplayName(locale)?.capitalize() ?: context.getString(R.string.system_default) + } + + langPreference.entries = langValues.toTypedArray() langPreference.setOnPreferenceChangeListener { preference, newValue -> (activity as SettingsActivity).parentFlags = SettingsActivity.FLAG_LANG_CHANGED - LocaleHelper.changeLocale(newValue.toString().toInt()) + LocaleHelper.changeLocale(newValue.toString()) LocaleHelper.updateCfg(activity.application, activity.baseContext.resources.configuration) activity.recreate() true diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesFragment.kt index e29c5369d1..4e25168eba 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSourcesFragment.kt @@ -8,13 +8,14 @@ import android.view.View import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.source.SourceManager -import eu.kanade.tachiyomi.data.source.getLanguages +import eu.kanade.tachiyomi.data.source.online.OnlineSource import eu.kanade.tachiyomi.widget.preference.LoginCheckBoxPreference import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog import eu.kanade.tachiyomi.widget.preference.SwitchPreferenceCategory import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy +import java.util.* class SettingsSourcesFragment : SettingsFragment() { @@ -45,33 +46,35 @@ class SettingsSourcesFragment : SettingsFragment() { // Get the list of active language codes. val activeLangsCodes = preferences.enabledLanguages().getOrDefault() - // Get the list of languages ordered by name. - val langs = getLanguages().sortedBy { it.lang } + // Get a map of sources grouped by language. + val sourcesByLang = onlineSources.groupByTo(TreeMap(), { it.lang }) // Order first by active languages, then inactive ones - val orderedLangs = langs.filter { it.code in activeLangsCodes } + - langs.filterNot { it.code in activeLangsCodes } + val orderedLangs = sourcesByLang.keys.filter { it in activeLangsCodes } + + sourcesByLang.keys.filterNot { it in activeLangsCodes } orderedLangs.forEach { lang -> + val sources = sourcesByLang[lang].orEmpty().sortedBy { it.name } + // Create a preference group and set initial state and change listener SwitchPreferenceCategory(context).apply { preferenceScreen.addPreference(this) - title = lang.lang + title = Locale(lang).let { it.getDisplayLanguage(it).capitalize() } isPersistent = false - if (lang.code in activeLangsCodes) { + if (lang in activeLangsCodes) { setChecked(true) - addLanguageSources(this) + addLanguageSources(this, sources) } setOnPreferenceChangeListener { preference, any -> val checked = any as Boolean val current = preferences.enabledLanguages().getOrDefault() if (!checked) { - preferences.enabledLanguages().set(current - lang.code) + preferences.enabledLanguages().set(current - lang) removeAll() } else { - preferences.enabledLanguages().set(current + lang.code) - addLanguageSources(this) + preferences.enabledLanguages().set(current + lang) + addLanguageSources(this, sources) } true } @@ -84,8 +87,7 @@ class SettingsSourcesFragment : SettingsFragment() { * * @param group the language category. */ - private fun addLanguageSources(group: SwitchPreferenceCategory) { - val sources = onlineSources.filter { it.lang.lang == group.title }.sortedBy { it.name } + private fun addLanguageSources(group: SwitchPreferenceCategory, sources: List) { val hiddenCatalogues = preferences.hiddenCatalogues().getOrDefault() sources.forEach { source -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/LocaleHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/util/LocaleHelper.kt index 763de98a2c..e96e566695 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/LocaleHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/LocaleHelper.kt @@ -30,24 +30,21 @@ object LocaleHelper { /** * The application's locale. When it's null, the system locale is used. */ - private var appLocale = getLocaleFromCode(preferences.lang()) + private var appLocale = getLocaleFromString(preferences.lang()) /** - * Returns the locale for the value stored in preferences, or null if system language or unknown - * value is selected. + * Returns the locale for the value stored in preferences, or null if it's system language. * - * @param pref the int value stored in preferences. + * @param pref the string value stored in preferences. */ - private fun getLocaleFromCode(pref: Int): Locale? { - val code = when(pref) { - 1 -> "en" - 2 -> "es" - 3 -> "it" - 4 -> "pt" - else -> return null + fun getLocaleFromString(pref: String): Locale? { + if (pref.isNullOrEmpty()) { + return null } - - return Locale(code) + val parts = pref.split("_", "-") + val lang = parts[0] + val country = parts.getOrNull(1) ?: "" + return Locale(lang, country) } /** @@ -55,8 +52,8 @@ object LocaleHelper { * * @param pref the new value stored in preferences. */ - fun changeLocale(pref: Int) { - appLocale = getLocaleFromCode(pref) + fun changeLocale(pref: String) { + appLocale = getLocaleFromString(pref) } /** diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 2055b12826..a46f7c8494 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -112,13 +112,7 @@ Tema scuro Schermata iniziale Lingua - - Predefinita di sistema - Inglese - Spagnolo - Italiano - Portoghese Schermo intero diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index db8a510e71..46f50d96ce 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -188,20 +188,12 @@ 2 - - @string/system_default - @string/english - @string/spanish - @string/italian - @string/portuguese - - - 0 - 1 - 2 - 3 - 4 + + en + es + it + pt \ No newline at end of file diff --git a/app/src/main/res/values/keys.xml b/app/src/main/res/values/keys.xml index 5ea2c173f6..1ce6054a8f 100644 --- a/app/src/main/res/values/keys.xml +++ b/app/src/main/res/values/keys.xml @@ -21,7 +21,7 @@ pref_theme_key library_update_restriction start_screen - language + app_language pref_default_viewer_key pref_image_scale_type_key @@ -51,7 +51,7 @@ pref_remove_after_marked_as_read_key last_used_category - pref_source_languages + source_languages category_tracking_accounts pref_clear_chapter_cache_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 52397a9f02..4a1746d1e2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -112,13 +112,7 @@ Dark theme Start screen Language - - - System Default - English - Spanish - Italian - Portuguese + System default Fullscreen diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 2987841363..23285b8adc 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -10,9 +10,8 @@ android:title="@string/pref_category_general" app:asp_tintEnabled="true"> -