From c51e83c048b9575b322690fdadddba0001690d4d Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Mon, 12 Sep 2022 04:05:46 +0600 Subject: [PATCH] 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 --- .../interactor/GetExtensionLanguages.kt | 6 ++++-- .../extension/interactor/GetExtensionsByType.kt | 16 +++++++++++++++- .../ui/browse/extension/ExtensionsPresenter.kt | 6 +++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionLanguages.kt b/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionLanguages.kt index a0d61da56a..d89b13bfe2 100644 --- a/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionLanguages.kt +++ b/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionLanguages.kt @@ -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( diff --git a/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionsByType.kt b/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionsByType.kt index 71dddd63e1..b884e5f180 100644 --- a/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionsByType.kt +++ b/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionsByType.kt @@ -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) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsPresenter.kt index 063c72f3cd..1416a372a2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsPresenter.kt @@ -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(), ) }