Remove Language class. App's language and hidden languages settings were reset

This commit is contained in:
len 2016-12-26 15:44:59 +01:00
parent 97fa659283
commit 1a3a1db4ff
23 changed files with 66 additions and 118 deletions

View file

@ -82,7 +82,7 @@ class PreferencesHelper(val context: Context) {
fun catalogueAsList() = rxPrefs.getBoolean(keys.catalogueAsList, false) 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), "") 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 downloadNew() = prefs.getBoolean(keys.downloadNew, false)
fun lang() = prefs.getInt(keys.lang, 0) fun lang() = prefs.getString(keys.lang, "")
} }

View file

@ -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)

View file

@ -9,7 +9,6 @@ import eu.kanade.tachiyomi.data.network.NetworkHelper
import eu.kanade.tachiyomi.data.network.asObservableSuccess import eu.kanade.tachiyomi.data.network.asObservableSuccess
import eu.kanade.tachiyomi.data.network.newCallWithProgress import eu.kanade.tachiyomi.data.network.newCallWithProgress
import eu.kanade.tachiyomi.data.preference.PreferencesHelper 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.Source
import eu.kanade.tachiyomi.data.source.model.MangasPage import eu.kanade.tachiyomi.data.source.model.MangasPage
import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.model.Page
@ -47,9 +46,9 @@ abstract class OnlineSource() : Source {
abstract val baseUrl: String 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. * Whether the source has support for latest updates.
@ -82,7 +81,7 @@ abstract class OnlineSource() : Source {
/** /**
* Visible name of the 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 * Returns an observable containing a page with a list of manga. Normally it's not needed to

View file

@ -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.database.models.Manga
import eu.kanade.tachiyomi.data.network.GET import eu.kanade.tachiyomi.data.network.GET
import eu.kanade.tachiyomi.data.network.POST 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.MangasPage
import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.model.Page
import eu.kanade.tachiyomi.util.asJsoup import eu.kanade.tachiyomi.util.asJsoup
@ -27,9 +26,7 @@ class YamlOnlineSource(mappings: Map<*, *>) : OnlineSource() {
if (it.endsWith("/")) it.dropLast(1) else it if (it.endsWith("/")) it.dropLast(1) else it
} }
override val lang = map.lang.toUpperCase().let { code -> override val lang = map.lang.toLowerCase()
getLanguages().find { code == it.code }!!
}
override val supportsLatest = map.latestupdates != null override val supportsLatest = map.latestupdates != null
@ -39,7 +36,7 @@ class YamlOnlineSource(mappings: Map<*, *>) : OnlineSource() {
} }
override val id = map.id.let { 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 { override fun popularMangaRequest(page: MangasPage): Request {

View file

@ -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.GET
import eu.kanade.tachiyomi.data.network.POST import eu.kanade.tachiyomi.data.network.POST
import eu.kanade.tachiyomi.data.network.asObservable 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.MangasPage
import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.model.Page
import eu.kanade.tachiyomi.data.source.online.LoginSource 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 baseUrl = "http://bato.to"
override val lang: Language get() = EN override val lang = "en"
override val supportsLatest = true override val supportsLatest = true

View file

@ -1,12 +1,9 @@
package eu.kanade.tachiyomi.data.source.online.english 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.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.network.GET import eu.kanade.tachiyomi.data.network.GET
import eu.kanade.tachiyomi.data.network.POST 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.MangasPage
import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.model.Page
import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource 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 baseUrl = "http://kissmanga.com"
override val lang: Language get() = EN override val lang = "en"
override val supportsLatest = true override val supportsLatest = true

View file

@ -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.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga 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.model.Page
import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource
import eu.kanade.tachiyomi.util.asJsoup 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 baseUrl = "http://mangafox.me"
override val lang: Language get() = EN override val lang = "en"
override val supportsLatest = true override val supportsLatest = true

View file

@ -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.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga 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.model.Page
import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource
import org.jsoup.nodes.Document 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 baseUrl = "http://www.mangahere.co"
override val lang: Language get() = EN override val lang = "en"
override val supportsLatest = true override val supportsLatest = true

View file

@ -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.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.network.POST 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.MangasPage
import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.model.Page
import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource 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 baseUrl = "http://mangaseeonline.net"
override val lang: Language get() = EN override val lang = "en"
override val supportsLatest = true override val supportsLatest = true

View file

@ -1,11 +1,8 @@
package eu.kanade.tachiyomi.data.source.online.english 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.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.network.POST 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.MangasPage
import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.model.Page
import eu.kanade.tachiyomi.data.source.online.OnlineSource 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 baseUrl = "http://www.readmanga.today"
override val lang: Language get() = EN override val lang = "en"
override val supportsLatest = true override val supportsLatest = true

View file

@ -1,10 +1,7 @@
package eu.kanade.tachiyomi.data.source.online.german 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.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga 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.model.Page
import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource
import eu.kanade.tachiyomi.util.asJsoup 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 baseUrl = "http://www.wiemanga.com"
override val lang: Language get() = DE override val lang = "de"
override val supportsLatest = true override val supportsLatest = true

View file

@ -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.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga 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.MangasPage
import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.model.Page
import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource 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 baseUrl = "http://mangachan.me"
override val lang: Language get() = RU override val lang = "ru"
override val supportsLatest = true override val supportsLatest = true

View file

@ -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.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga 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.model.Page
import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource
import okhttp3.Response import okhttp3.Response
@ -19,7 +17,7 @@ class Mintmanga(override val id: Int) : ParsedOnlineSource() {
override val baseUrl = "http://mintmanga.com" override val baseUrl = "http://mintmanga.com"
override val lang: Language get() = RU override val lang = "ru"
override val supportsLatest = true override val supportsLatest = true

View file

@ -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.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga 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.model.Page
import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource import eu.kanade.tachiyomi.data.source.online.ParsedOnlineSource
import okhttp3.Response import okhttp3.Response
@ -19,7 +17,7 @@ class Readmanga(override val id: Int) : ParsedOnlineSource() {
override val baseUrl = "http://readmanga.me" override val baseUrl = "http://readmanga.me"
override val lang: Language get() = RU override val lang = "ru"
override val supportsLatest = true override val supportsLatest = true

View file

@ -6,7 +6,6 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault 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.Source
import eu.kanade.tachiyomi.data.source.SourceManager import eu.kanade.tachiyomi.data.source.SourceManager
import eu.kanade.tachiyomi.data.source.model.MangasPage import eu.kanade.tachiyomi.data.source.model.MangasPage
@ -333,13 +332,13 @@ open class CataloguePresenter : BasePresenter<CatalogueFragment>() {
// Ensure at least one language // Ensure at least one language
if (languages.isEmpty()) { if (languages.isEmpty()) {
languages.add(EN.code) languages.add("en")
} }
return sourceManager.getOnlineSources() return sourceManager.getOnlineSources()
.filter { it.lang.code in languages } .filter { it.lang in languages }
.filterNot { it.id.toString() in hiddenCatalogues } .filterNot { it.id.toString() in hiddenCatalogues }
.sortedBy { "(${it.lang.code}) ${it.name}" } .sortedBy { "(${it.lang}) ${it.name}" }
} }
/** /**

View file

@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.util.plusAssign
import eu.kanade.tachiyomi.widget.preference.IntListPreference import eu.kanade.tachiyomi.widget.preference.IntListPreference
import eu.kanade.tachiyomi.widget.preference.LibraryColumnsDialog import eu.kanade.tachiyomi.widget.preference.LibraryColumnsDialog
import eu.kanade.tachiyomi.widget.preference.SimpleDialogPreference import eu.kanade.tachiyomi.widget.preference.SimpleDialogPreference
import net.xpece.android.support.preference.ListPreference
import net.xpece.android.support.preference.MultiSelectListPreference import net.xpece.android.support.preference.MultiSelectListPreference
import rx.Observable import rx.Observable
import rx.android.schedulers.AndroidSchedulers 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 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?) { override fun onViewCreated(view: View, savedState: Bundle?) {
super.onViewCreated(view, savedState) super.onViewCreated(view, savedState)
@ -105,9 +106,15 @@ class SettingsGeneralFragment : SettingsFragment(),
true 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 -> langPreference.setOnPreferenceChangeListener { preference, newValue ->
(activity as SettingsActivity).parentFlags = SettingsActivity.FLAG_LANG_CHANGED (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) LocaleHelper.updateCfg(activity.application, activity.baseContext.resources.configuration)
activity.recreate() activity.recreate()
true true

View file

@ -8,13 +8,14 @@ import android.view.View
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.data.source.SourceManager 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.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
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.util.*
class SettingsSourcesFragment : SettingsFragment() { class SettingsSourcesFragment : SettingsFragment() {
@ -45,33 +46,35 @@ class SettingsSourcesFragment : SettingsFragment() {
// Get the list of active language codes. // Get the list of active language codes.
val activeLangsCodes = preferences.enabledLanguages().getOrDefault() val activeLangsCodes = preferences.enabledLanguages().getOrDefault()
// Get the list of languages ordered by name. // Get a map of sources grouped by language.
val langs = getLanguages().sortedBy { it.lang } val sourcesByLang = onlineSources.groupByTo(TreeMap(), { it.lang })
// Order first by active languages, then inactive ones // Order first by active languages, then inactive ones
val orderedLangs = langs.filter { it.code in activeLangsCodes } + val orderedLangs = sourcesByLang.keys.filter { it in activeLangsCodes } +
langs.filterNot { it.code in activeLangsCodes } sourcesByLang.keys.filterNot { it in activeLangsCodes }
orderedLangs.forEach { lang -> orderedLangs.forEach { lang ->
val sources = sourcesByLang[lang].orEmpty().sortedBy { it.name }
// 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 = lang.lang title = Locale(lang).let { it.getDisplayLanguage(it).capitalize() }
isPersistent = false isPersistent = false
if (lang.code in activeLangsCodes) { if (lang in activeLangsCodes) {
setChecked(true) setChecked(true)
addLanguageSources(this) addLanguageSources(this, sources)
} }
setOnPreferenceChangeListener { preference, any -> setOnPreferenceChangeListener { preference, any ->
val checked = any as Boolean val checked = any as Boolean
val current = preferences.enabledLanguages().getOrDefault() val current = preferences.enabledLanguages().getOrDefault()
if (!checked) { if (!checked) {
preferences.enabledLanguages().set(current - lang.code) preferences.enabledLanguages().set(current - lang)
removeAll() removeAll()
} else { } else {
preferences.enabledLanguages().set(current + lang.code) preferences.enabledLanguages().set(current + lang)
addLanguageSources(this) addLanguageSources(this, sources)
} }
true true
} }
@ -84,8 +87,7 @@ class SettingsSourcesFragment : SettingsFragment() {
* *
* @param group the language category. * @param group the language category.
*/ */
private fun addLanguageSources(group: SwitchPreferenceCategory) { private fun addLanguageSources(group: SwitchPreferenceCategory, sources: List<OnlineSource>) {
val sources = onlineSources.filter { it.lang.lang == group.title }.sortedBy { it.name }
val hiddenCatalogues = preferences.hiddenCatalogues().getOrDefault() val hiddenCatalogues = preferences.hiddenCatalogues().getOrDefault()
sources.forEach { source -> sources.forEach { source ->

View file

@ -30,24 +30,21 @@ object LocaleHelper {
/** /**
* The application's locale. When it's null, the system locale is used. * 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 * Returns the locale for the value stored in preferences, or null if it's system language.
* value is selected.
* *
* @param pref the int value stored in preferences. * @param pref the string value stored in preferences.
*/ */
private fun getLocaleFromCode(pref: Int): Locale? { fun getLocaleFromString(pref: String): Locale? {
val code = when(pref) { if (pref.isNullOrEmpty()) {
1 -> "en" return null
2 -> "es"
3 -> "it"
4 -> "pt"
else -> return null
} }
val parts = pref.split("_", "-")
return Locale(code) 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. * @param pref the new value stored in preferences.
*/ */
fun changeLocale(pref: Int) { fun changeLocale(pref: String) {
appLocale = getLocaleFromCode(pref) appLocale = getLocaleFromString(pref)
} }
/** /**

View file

@ -112,13 +112,7 @@
<string name="dark_theme">Tema scuro</string> <string name="dark_theme">Tema scuro</string>
<string name="pref_start_screen">Schermata iniziale</string> <string name="pref_start_screen">Schermata iniziale</string>
<string name="pref_language">Lingua</string> <string name="pref_language">Lingua</string>
<!-- Languages -->
<string name="system_default">Predefinita di sistema</string> <string name="system_default">Predefinita di sistema</string>
<string name="english">Inglese</string>
<string name="spanish">Spagnolo</string>
<string name="italian">Italiano</string>
<string name="portuguese">Portoghese</string>
<!-- Reader section --> <!-- Reader section -->
<string name="pref_fullscreen">Schermo intero</string> <string name="pref_fullscreen">Schermo intero</string>

View file

@ -188,20 +188,12 @@
<item>2</item> <item>2</item>
</string-array> </string-array>
<string-array name="languages">
<item>@string/system_default</item>
<item>@string/english</item>
<item>@string/spanish</item>
<item>@string/italian</item>
<item>@string/portuguese</item>
</string-array>
<string-array name="languages_values"> <string-array name="languages_values">
<item>0</item> <item></item>
<item>1</item> <item>en</item>
<item>2</item> <item>es</item>
<item>3</item> <item>it</item>
<item>4</item> <item>pt</item>
</string-array> </string-array>
</resources> </resources>

View file

@ -21,7 +21,7 @@
<string name="pref_theme_key">pref_theme_key</string> <string name="pref_theme_key">pref_theme_key</string>
<string name="pref_library_update_restriction_key">library_update_restriction</string> <string name="pref_library_update_restriction_key">library_update_restriction</string>
<string name="pref_start_screen_key">start_screen</string> <string name="pref_start_screen_key">start_screen</string>
<string name="pref_language_key">language</string> <string name="pref_language_key">app_language</string>
<string name="pref_default_viewer_key">pref_default_viewer_key</string> <string name="pref_default_viewer_key">pref_default_viewer_key</string>
<string name="pref_image_scale_type_key">pref_image_scale_type_key</string> <string name="pref_image_scale_type_key">pref_image_scale_type_key</string>
@ -51,7 +51,7 @@
<string name="pref_remove_after_marked_as_read_key">pref_remove_after_marked_as_read_key</string> <string name="pref_remove_after_marked_as_read_key">pref_remove_after_marked_as_read_key</string>
<string name="pref_last_used_category_key">last_used_category</string> <string name="pref_last_used_category_key">last_used_category</string>
<string name="pref_source_languages">pref_source_languages</string> <string name="pref_source_languages">source_languages</string>
<string name="pref_category_tracking_accounts_key">category_tracking_accounts</string> <string name="pref_category_tracking_accounts_key">category_tracking_accounts</string>
<string name="pref_clear_chapter_cache_key">pref_clear_chapter_cache_key</string> <string name="pref_clear_chapter_cache_key">pref_clear_chapter_cache_key</string>

View file

@ -112,13 +112,7 @@
<string name="dark_theme">Dark theme</string> <string name="dark_theme">Dark theme</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>
<!-- Languages -->
<string name="system_default">System Default</string>
<string name="english">English</string>
<string name="spanish">Spanish</string>
<string name="italian">Italian</string>
<string name="portuguese">Portuguese</string>
<!-- Reader section --> <!-- Reader section -->
<string name="pref_fullscreen">Fullscreen</string> <string name="pref_fullscreen">Fullscreen</string>

View file

@ -10,9 +10,8 @@
android:title="@string/pref_category_general" android:title="@string/pref_category_general"
app:asp_tintEnabled="true"> app:asp_tintEnabled="true">
<eu.kanade.tachiyomi.widget.preference.IntListPreference <ListPreference
android:defaultValue="0" android:defaultValue=""
android:entries="@array/languages"
android:entryValues="@array/languages_values" android:entryValues="@array/languages_values"
android:key="@string/pref_language_key" android:key="@string/pref_language_key"
android:summary="%s" android:summary="%s"