From 42026b49bfdfd0cc0683be4d7fd11305ed8e74d2 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 11 Oct 2021 10:29:08 -0400 Subject: [PATCH] Allow hiding "All" section in extensions list (closes #6081) --- .../extension/ExtensionFilterController.kt | 30 ++++++++----------- .../ui/browse/extension/ExtensionPresenter.kt | 2 +- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt index 8a5b3abf87..c33984b1af 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt @@ -2,28 +2,27 @@ 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().availableExtensions.groupBy { - it.lang - }.keys - .minus("all") - .sortedWith(compareBy({ it !in activeLangs }, { LocaleHelper.getSourceDisplayName(it, context) })) + val availableLangs = extensionManager.availableExtensions.groupBy { it.lang }.keys + .sortedWith(compareBy({ it !in activeLangs }, { LocaleHelper.getSourceDisplayName(it, context) })) availableLangs.forEach { switchPreference { @@ -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 - } else { - currentActiveLangs - it - } - ) + if (newValue as Boolean) { + preferences.enabledLanguages() += it + } else { + preferences.enabledLanguages() -= it + } true } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPresenter.kt index b9ac17b738..4c174ea6b6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPresenter.kt @@ -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 }