Merge GetExtensions and GetExtensionUpdates (#7646)

This commit is contained in:
Andreas 2022-07-29 21:09:49 +02:00 committed by GitHub
parent e513487caa
commit 7d74b174e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 43 deletions

View File

@ -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<UpdatesRepository> { UpdatesRepositoryImpl(get()) }

View File

@ -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<List<Extension.Installed>> {
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 })
}
}
}

View File

@ -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<Extension.Installed>, List<Extension.Untrusted>, List<Extension.Available>>
class GetExtensions(
class GetExtensionsByType(
private val preferences: PreferencesHelper,
private val extensionManager: ExtensionManager,
) {
fun subscribe(): Flow<ExtensionSegregation> {
fun subscribe(): Flow<Extensions> {
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<Extension.Installed> { 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)
}
}
}

View File

@ -0,0 +1,10 @@
package eu.kanade.domain.extension.model
import eu.kanade.tachiyomi.extension.model.Extension
data class Extensions(
val updates: List<Extension.Installed>,
val installed: List<Extension.Installed>,
val available: List<Extension.Available>,
val untrusted: List<Extension.Untrusted>,
)

View File

@ -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<ExtensionsController>(), ExtensionsState by state {
private val _query: MutableStateFlow<String> = 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) }