mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 23:41:50 +01:00
parent
09f0ac866f
commit
c6d4e4c15f
@ -11,7 +11,6 @@ import android.view.MenuItem
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.view.ContextThemeWrapper
|
import androidx.appcompat.view.ContextThemeWrapper
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.preference.Preference
|
|
||||||
import androidx.preference.PreferenceGroupAdapter
|
import androidx.preference.PreferenceGroupAdapter
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
@ -103,22 +102,54 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
|
|||||||
val isMultiLangSingleSource = isMultiSource && extension.sources.map { it.name }.distinct().size == 1
|
val isMultiLangSingleSource = isMultiSource && extension.sources.map { it.name }.distinct().size == 1
|
||||||
|
|
||||||
with(screen) {
|
with(screen) {
|
||||||
extension.sources
|
if (isMultiSource && isMultiLangSingleSource.not()) {
|
||||||
|
multiLanguagePreference(context, extension.sources)
|
||||||
|
} else {
|
||||||
|
singleLanguagePreference(context, extension.sources)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return PreferenceGroupAdapter(screen)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun PreferenceScreen.singleLanguagePreference(context: Context, sources: List<Source>) {
|
||||||
|
sources
|
||||||
|
.map { source -> LocaleHelper.getSourceDisplayName(source.lang, context) to source }
|
||||||
|
.sortedWith(compareBy({ (_, source) -> !source.isEnabled() }, { (lang, _) -> lang.lowercase() }))
|
||||||
|
.forEach { (lang, source) ->
|
||||||
|
val preferenceBlock = {
|
||||||
|
sourceSwitchPreference(source, LocaleHelper.getSourceDisplayName(lang, context))
|
||||||
|
}
|
||||||
|
|
||||||
|
preferenceBlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun PreferenceScreen.multiLanguagePreference(context: Context, sources: List<Source>) {
|
||||||
|
sources
|
||||||
.groupBy { (it as CatalogueSource).lang }
|
.groupBy { (it as CatalogueSource).lang }
|
||||||
.toSortedMap(compareBy { LocaleHelper.getSourceDisplayName(it, context) })
|
.toSortedMap(compareBy { LocaleHelper.getSourceDisplayName(it, context) })
|
||||||
.forEach {
|
.forEach { entry ->
|
||||||
val preferenceBlock = {
|
val preferenceBlock = {
|
||||||
it.value
|
entry.value
|
||||||
.sortedWith(compareBy({ !it.isEnabled() }, { it.name.lowercase() }))
|
.sortedWith(compareBy({ source -> !source.isEnabled() }, { source -> source.name.lowercase() }))
|
||||||
.forEach { source ->
|
.forEach { source ->
|
||||||
val sourcePrefs = mutableListOf<Preference>()
|
sourceSwitchPreference(source, source.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
preferenceCategory {
|
||||||
|
title = LocaleHelper.getSourceDisplayName(entry.key, context)
|
||||||
|
|
||||||
|
preferenceBlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun PreferenceScreen.sourceSwitchPreference(source: Source, name: String) {
|
||||||
val block: (@DSL SwitchPreferenceCompat).() -> Unit = {
|
val block: (@DSL SwitchPreferenceCompat).() -> Unit = {
|
||||||
key = source.getPreferenceKey()
|
key = source.getPreferenceKey()
|
||||||
title = when {
|
title = name
|
||||||
isMultiSource && !isMultiLangSingleSource -> source.toString()
|
|
||||||
else -> LocaleHelper.getSourceDisplayName(it.key, context)
|
|
||||||
}
|
|
||||||
isPersistent = false
|
isPersistent = false
|
||||||
isChecked = source.isEnabled()
|
isChecked = source.isEnabled()
|
||||||
|
|
||||||
@ -133,7 +164,6 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
|
|||||||
.onEach {
|
.onEach {
|
||||||
val enabled = source.isEnabled()
|
val enabled = source.isEnabled()
|
||||||
isChecked = enabled
|
isChecked = enabled
|
||||||
sourcePrefs.forEach { pref -> pref.isVisible = enabled }
|
|
||||||
}
|
}
|
||||||
.launchIn(viewScope)
|
.launchIn(viewScope)
|
||||||
}
|
}
|
||||||
@ -152,22 +182,6 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
|
|||||||
switchPreference(block)
|
switchPreference(block)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (isMultiSource && !isMultiLangSingleSource) {
|
|
||||||
preferenceCategory {
|
|
||||||
title = LocaleHelper.getSourceDisplayName(it.key, context)
|
|
||||||
|
|
||||||
preferenceBlock()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
preferenceBlock()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return PreferenceGroupAdapter(screen)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroyView(view: View) {
|
override fun onDestroyView(view: View) {
|
||||||
preferenceScreen = null
|
preferenceScreen = null
|
||||||
|
Loading…
Reference in New Issue
Block a user