From 7d74b174e024f2dee84debec1a9826b942e093e4 Mon Sep 17 00:00:00 2001 From: Andreas Date: Fri, 29 Jul 2022 21:09:49 +0200 Subject: [PATCH] Merge GetExtensions and GetExtensionUpdates (#7646) --- .../java/eu/kanade/domain/DomainModule.kt | 6 ++--- .../interactor/GetExtensionUpdates.kt | 24 ------------------- ...etExtensions.kt => GetExtensionsByType.kt} | 16 ++++++------- .../domain/extension/model/Extensions.kt | 10 ++++++++ .../browse/extension/ExtensionsPresenter.kt | 9 +++---- 5 files changed, 22 insertions(+), 43 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionUpdates.kt rename app/src/main/java/eu/kanade/domain/extension/interactor/{GetExtensions.kt => GetExtensionsByType.kt} (78%) create mode 100644 app/src/main/java/eu/kanade/domain/extension/model/Extensions.kt diff --git a/app/src/main/java/eu/kanade/domain/DomainModule.kt b/app/src/main/java/eu/kanade/domain/DomainModule.kt index 4c0858bfb5..6c6b1a7634 100644 --- a/app/src/main/java/eu/kanade/domain/DomainModule.kt +++ b/app/src/main/java/eu/kanade/domain/DomainModule.kt @@ -27,8 +27,7 @@ import eu.kanade.domain.chapter.repository.ChapterRepository import eu.kanade.domain.download.interactor.DeleteDownload import eu.kanade.domain.extension.interactor.GetExtensionLanguages import eu.kanade.domain.extension.interactor.GetExtensionSources -import eu.kanade.domain.extension.interactor.GetExtensionUpdates -import eu.kanade.domain.extension.interactor.GetExtensions +import eu.kanade.domain.extension.interactor.GetExtensionsByType import eu.kanade.domain.history.interactor.DeleteHistoryTable import eu.kanade.domain.history.interactor.GetHistory import eu.kanade.domain.history.interactor.GetNextChapter @@ -117,9 +116,8 @@ class DomainModule : InjektModule { addFactory { DeleteDownload(get(), get()) } - addFactory { GetExtensions(get(), get()) } + addFactory { GetExtensionsByType(get(), get()) } addFactory { GetExtensionSources(get()) } - addFactory { GetExtensionUpdates(get(), get()) } addFactory { GetExtensionLanguages(get(), get()) } addSingletonFactory { UpdatesRepositoryImpl(get()) } diff --git a/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionUpdates.kt b/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionUpdates.kt deleted file mode 100644 index 63a27d89eb..0000000000 --- a/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionUpdates.kt +++ /dev/null @@ -1,24 +0,0 @@ -package eu.kanade.domain.extension.interactor - -import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.extension.ExtensionManager -import eu.kanade.tachiyomi.extension.model.Extension -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.map - -class GetExtensionUpdates( - private val preferences: PreferencesHelper, - private val extensionManager: ExtensionManager, -) { - - fun subscribe(): Flow> { - val showNsfwSources = preferences.showNsfwSource().get() - - return extensionManager.getInstalledExtensionsFlow() - .map { installed -> - installed - .filter { it.hasUpdate && (showNsfwSources || it.isNsfw.not()) } - .sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.name }) - } - } -} diff --git a/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensions.kt b/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionsByType.kt similarity index 78% rename from app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensions.kt rename to app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionsByType.kt index 8187eb93f9..71dddd63e1 100644 --- a/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensions.kt +++ b/app/src/main/java/eu/kanade/domain/extension/interactor/GetExtensionsByType.kt @@ -1,20 +1,18 @@ package eu.kanade.domain.extension.interactor -import eu.kanade.core.util.asFlow +import eu.kanade.domain.extension.model.Extensions import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.extension.model.Extension import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine -typealias ExtensionSegregation = Triple, List, List> - -class GetExtensions( +class GetExtensionsByType( private val preferences: PreferencesHelper, private val extensionManager: ExtensionManager, ) { - fun subscribe(): Flow { + fun subscribe(): Flow { val showNsfwSources = preferences.showNsfwSource().get() return combine( @@ -23,13 +21,13 @@ class GetExtensions( extensionManager.getUntrustedExtensionsFlow(), extensionManager.getAvailableExtensionsFlow(), ) { _activeLanguages, _installed, _untrusted, _available -> - - val installed = _installed - .filter { it.hasUpdate.not() && (showNsfwSources || it.isNsfw.not()) } + val (updates, installed) = _installed + .filter { (showNsfwSources || it.isNsfw.not()) } .sortedWith( compareBy { it.isObsolete.not() } .thenBy(String.CASE_INSENSITIVE_ORDER) { it.name }, ) + .partition { it.hasUpdate } val untrusted = _untrusted .sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.name }) @@ -42,7 +40,7 @@ class GetExtensions( (showNsfwSources || extension.isNsfw.not()) } - Triple(installed, untrusted, available) + Extensions(updates, installed, available, untrusted) } } } diff --git a/app/src/main/java/eu/kanade/domain/extension/model/Extensions.kt b/app/src/main/java/eu/kanade/domain/extension/model/Extensions.kt new file mode 100644 index 0000000000..2e8dbcd990 --- /dev/null +++ b/app/src/main/java/eu/kanade/domain/extension/model/Extensions.kt @@ -0,0 +1,10 @@ +package eu.kanade.domain.extension.model + +import eu.kanade.tachiyomi.extension.model.Extension + +data class Extensions( + val updates: List, + val installed: List, + val available: List, + val untrusted: List, +) 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 b47f61b9d9..099d1a7ae2 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 @@ -3,8 +3,7 @@ package eu.kanade.tachiyomi.ui.browse.extension import android.app.Application import android.os.Bundle import androidx.annotation.StringRes -import eu.kanade.domain.extension.interactor.GetExtensionUpdates -import eu.kanade.domain.extension.interactor.GetExtensions +import eu.kanade.domain.extension.interactor.GetExtensionsByType import eu.kanade.presentation.browse.ExtensionState import eu.kanade.presentation.browse.ExtensionsState import eu.kanade.presentation.browse.ExtensionsStateImpl @@ -27,8 +26,7 @@ import uy.kohesive.injekt.api.get class ExtensionsPresenter( private val state: ExtensionsStateImpl = ExtensionState() as ExtensionsStateImpl, private val extensionManager: ExtensionManager = Injekt.get(), - private val getExtensionUpdates: GetExtensionUpdates = Injekt.get(), - private val getExtensions: GetExtensions = Injekt.get(), + private val getExtensions: GetExtensionsByType = Injekt.get(), ) : BasePresenter(), ExtensionsState by state { private val _query: MutableStateFlow = MutableStateFlow("") @@ -77,9 +75,8 @@ class ExtensionsPresenter( combine( _query, getExtensions.subscribe(), - getExtensionUpdates.subscribe(), _currentDownloads, - ) { query, (installed, untrusted, available), updates, downloads -> + ) { query, (updates, installed, available, untrusted), downloads -> val languagesWithExtensions = available .filter(queryFilter(query)) .groupBy { LocaleHelper.getSourceDisplayName(it.lang, context) }