Option to hide NSFW extensions (closes #1312)

This commit is contained in:
arkon
2020-08-08 16:27:55 -04:00
parent 8bab1d9798
commit abaca6e676
8 changed files with 34 additions and 10 deletions

View File

@@ -55,20 +55,22 @@ open class ExtensionPresenter(
private fun toItems(tuple: ExtensionTuple): List<ExtensionItem> {
val context = Injekt.get<Application>()
val activeLangs = preferences.enabledLanguages().get()
val allowNsfw = preferences.allowNsfwSources()
val (installed, untrusted, available) = tuple
val items = mutableListOf<ExtensionItem>()
val updatesSorted = installed.filter { it.hasUpdate }.sortedBy { it.pkgName }
val installedSorted = installed.filter { !it.hasUpdate }.sortedWith(compareBy({ !it.isObsolete }, { it.pkgName }))
val updatesSorted = installed.filter { it.hasUpdate && (allowNsfw || !it.isNsfw) }.sortedBy { it.pkgName }
val installedSorted = installed.filter { !it.hasUpdate && (allowNsfw || !it.isNsfw) }.sortedWith(compareBy({ !it.isObsolete }, { it.pkgName }))
val untrustedSorted = untrusted.sortedBy { it.pkgName }
val availableSorted = available
// Filter out already installed extensions and disabled languages
.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 || avail.lang == "all") &&
(allowNsfw || !avail.isNsfw)
}
.sortedBy { it.pkgName }

View File

@@ -29,6 +29,11 @@ class SettingsBrowseController : SettingsController() {
true
}
}
switchPreference {
key = Keys.allowNsfwSources
titleRes = R.string.pref_allow_nsfw_sources
defaultValue = true
}
}
preferenceCategory {