Allow hiding "All" section in extensions list (closes #6081)

This commit is contained in:
arkon 2021-10-11 10:29:08 -04:00
parent 151193c4c3
commit 42026b49bf
2 changed files with 13 additions and 19 deletions

View File

@ -2,27 +2,26 @@ package eu.kanade.tachiyomi.ui.browse.extension
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.minusAssign
import eu.kanade.tachiyomi.data.preference.plusAssign
import eu.kanade.tachiyomi.extension.ExtensionManager
import eu.kanade.tachiyomi.ui.setting.SettingsController
import eu.kanade.tachiyomi.util.preference.onChange
import eu.kanade.tachiyomi.util.preference.switchPreference
import eu.kanade.tachiyomi.util.preference.titleRes
import eu.kanade.tachiyomi.util.system.LocaleHelper
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
class ExtensionFilterController : SettingsController() {
private val extensionManager: ExtensionManager by injectLazy()
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
titleRes = R.string.label_extensions
val activeLangs = preferences.enabledLanguages().get()
val availableLangs =
Injekt.get<ExtensionManager>().availableExtensions.groupBy {
it.lang
}.keys
.minus("all")
val availableLangs = extensionManager.availableExtensions.groupBy { it.lang }.keys
.sortedWith(compareBy({ it !in activeLangs }, { LocaleHelper.getSourceDisplayName(it, context) }))
availableLangs.forEach {
@ -33,16 +32,11 @@ class ExtensionFilterController : SettingsController() {
isChecked = it in activeLangs
onChange { newValue ->
val checked = newValue as Boolean
val currentActiveLangs = preferences.enabledLanguages().get()
preferences.enabledLanguages().set(
if (checked) {
currentActiveLangs + it
if (newValue as Boolean) {
preferences.enabledLanguages() += it
} else {
currentActiveLangs - it
preferences.enabledLanguages() -= it
}
)
true
}
}

View File

@ -69,7 +69,7 @@ open class ExtensionPresenter(
.filter { avail ->
installed.none { it.pkgName == avail.pkgName } &&
untrusted.none { it.pkgName == avail.pkgName } &&
(avail.lang in activeLangs || avail.lang == "all") &&
avail.lang in activeLangs &&
(showNsfwSources || !avail.isNsfw)
}
.sortedBy { it.name }