Fix NSFW sources showing in extensions list while setting is off

This commit is contained in:
Jays2Kings 2021-04-28 14:48:48 -04:00
parent fcb9445f02
commit 62c4ee22a4

View File

@ -146,19 +146,22 @@ class ExtensionBottomPresenter(
private fun toItems(tuple: ExtensionTuple): List<ExtensionItem> {
val context = bottomSheet.context
val activeLangs = preferences.enabledLanguages().get()
val showNsfwExtensions = preferences.showNsfwExtension().get()
val (installed, untrusted, available) = tuple
val items = mutableListOf<ExtensionItem>()
val installedSorted = installed.sortedWith(compareBy({ !it.hasUpdate }, { !it.isObsolete }, { it.pkgName }))
val installedSorted = installed.filter { showNsfwExtensions || !it.isNsfw }
.sortedWith(compareBy({ !it.hasUpdate }, { !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") &&
(showNsfwExtensions || !avail.isNsfw)
}
.sortedBy { it.pkgName }