Flatten available extensions with its source (#7956)

* Flatten available extensions with it's source

We should also do something similar for installed extensions

Supersedes #7200

* Dedupe sources
This commit is contained in:
AntsyLich 2022-09-12 04:05:46 +06:00 committed by GitHub
parent 52fa28c16a
commit c51e83c048
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 6 deletions

View File

@ -1,6 +1,5 @@
package eu.kanade.domain.extension.interactor
import eu.kanade.core.util.asFlow
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.extension.ExtensionManager
import eu.kanade.tachiyomi.util.system.LocaleHelper
@ -17,7 +16,10 @@ class GetExtensionLanguages(
extensionManager.getAvailableExtensionsFlow(),
) { enabledLanguage, availableExtensions ->
availableExtensions
.map { it.lang }
.flatMap { ext ->
if (ext.sources.isEmpty()) listOf(ext.lang)
else ext.sources.map { it.lang }
}
.distinct()
.sortedWith(
compareBy(

View File

@ -36,9 +36,23 @@ class GetExtensionsByType(
.filter { extension ->
_installed.none { it.pkgName == extension.pkgName } &&
_untrusted.none { it.pkgName == extension.pkgName } &&
extension.lang in _activeLanguages &&
(showNsfwSources || extension.isNsfw.not())
}
.flatMap { ext ->
if (ext.sources.isEmpty()) {
return@flatMap if (ext.lang in _activeLanguages) listOf(ext) else emptyList()
}
ext.sources.filter { it.lang in _activeLanguages }
.map {
ext.copy(
name = it.name,
lang = it.lang,
pkgName = "${ext.pkgName}-${it.id}",
sources = listOf(it),
)
}
}
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.name })
Extensions(updates, installed, available, untrusted)
}

View File

@ -86,10 +86,10 @@ class ExtensionsPresenter(
.filter(queryFilter(searchQuery))
.groupBy { LocaleHelper.getSourceDisplayName(it.lang, context) }
.toSortedMap()
.flatMap { (key, value) ->
.flatMap { (lang, exts) ->
listOf(
ExtensionUiModel.Header.Text(key),
*value.map(extensionMapper(downloads)).toTypedArray(),
ExtensionUiModel.Header.Text(lang),
*exts.map(extensionMapper(downloads)).toTypedArray(),
)
}