mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 05:41:51 +01:00
Merge GetExtensions and GetExtensionUpdates (#7646)
This commit is contained in:
parent
e513487caa
commit
7d74b174e0
@ -27,8 +27,7 @@ import eu.kanade.domain.chapter.repository.ChapterRepository
|
|||||||
import eu.kanade.domain.download.interactor.DeleteDownload
|
import eu.kanade.domain.download.interactor.DeleteDownload
|
||||||
import eu.kanade.domain.extension.interactor.GetExtensionLanguages
|
import eu.kanade.domain.extension.interactor.GetExtensionLanguages
|
||||||
import eu.kanade.domain.extension.interactor.GetExtensionSources
|
import eu.kanade.domain.extension.interactor.GetExtensionSources
|
||||||
import eu.kanade.domain.extension.interactor.GetExtensionUpdates
|
import eu.kanade.domain.extension.interactor.GetExtensionsByType
|
||||||
import eu.kanade.domain.extension.interactor.GetExtensions
|
|
||||||
import eu.kanade.domain.history.interactor.DeleteHistoryTable
|
import eu.kanade.domain.history.interactor.DeleteHistoryTable
|
||||||
import eu.kanade.domain.history.interactor.GetHistory
|
import eu.kanade.domain.history.interactor.GetHistory
|
||||||
import eu.kanade.domain.history.interactor.GetNextChapter
|
import eu.kanade.domain.history.interactor.GetNextChapter
|
||||||
@ -117,9 +116,8 @@ class DomainModule : InjektModule {
|
|||||||
|
|
||||||
addFactory { DeleteDownload(get(), get()) }
|
addFactory { DeleteDownload(get(), get()) }
|
||||||
|
|
||||||
addFactory { GetExtensions(get(), get()) }
|
addFactory { GetExtensionsByType(get(), get()) }
|
||||||
addFactory { GetExtensionSources(get()) }
|
addFactory { GetExtensionSources(get()) }
|
||||||
addFactory { GetExtensionUpdates(get(), get()) }
|
|
||||||
addFactory { GetExtensionLanguages(get(), get()) }
|
addFactory { GetExtensionLanguages(get(), get()) }
|
||||||
|
|
||||||
addSingletonFactory<UpdatesRepository> { UpdatesRepositoryImpl(get()) }
|
addSingletonFactory<UpdatesRepository> { UpdatesRepositoryImpl(get()) }
|
||||||
|
@ -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 })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +1,18 @@
|
|||||||
package eu.kanade.domain.extension.interactor
|
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.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.extension.ExtensionManager
|
import eu.kanade.tachiyomi.extension.ExtensionManager
|
||||||
import eu.kanade.tachiyomi.extension.model.Extension
|
import eu.kanade.tachiyomi.extension.model.Extension
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
|
|
||||||
typealias ExtensionSegregation = Triple<List<Extension.Installed>, List<Extension.Untrusted>, List<Extension.Available>>
|
class GetExtensionsByType(
|
||||||
|
|
||||||
class GetExtensions(
|
|
||||||
private val preferences: PreferencesHelper,
|
private val preferences: PreferencesHelper,
|
||||||
private val extensionManager: ExtensionManager,
|
private val extensionManager: ExtensionManager,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun subscribe(): Flow<ExtensionSegregation> {
|
fun subscribe(): Flow<Extensions> {
|
||||||
val showNsfwSources = preferences.showNsfwSource().get()
|
val showNsfwSources = preferences.showNsfwSource().get()
|
||||||
|
|
||||||
return combine(
|
return combine(
|
||||||
@ -23,13 +21,13 @@ class GetExtensions(
|
|||||||
extensionManager.getUntrustedExtensionsFlow(),
|
extensionManager.getUntrustedExtensionsFlow(),
|
||||||
extensionManager.getAvailableExtensionsFlow(),
|
extensionManager.getAvailableExtensionsFlow(),
|
||||||
) { _activeLanguages, _installed, _untrusted, _available ->
|
) { _activeLanguages, _installed, _untrusted, _available ->
|
||||||
|
val (updates, installed) = _installed
|
||||||
val installed = _installed
|
.filter { (showNsfwSources || it.isNsfw.not()) }
|
||||||
.filter { it.hasUpdate.not() && (showNsfwSources || it.isNsfw.not()) }
|
|
||||||
.sortedWith(
|
.sortedWith(
|
||||||
compareBy<Extension.Installed> { it.isObsolete.not() }
|
compareBy<Extension.Installed> { it.isObsolete.not() }
|
||||||
.thenBy(String.CASE_INSENSITIVE_ORDER) { it.name },
|
.thenBy(String.CASE_INSENSITIVE_ORDER) { it.name },
|
||||||
)
|
)
|
||||||
|
.partition { it.hasUpdate }
|
||||||
|
|
||||||
val untrusted = _untrusted
|
val untrusted = _untrusted
|
||||||
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.name })
|
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.name })
|
||||||
@ -42,7 +40,7 @@ class GetExtensions(
|
|||||||
(showNsfwSources || extension.isNsfw.not())
|
(showNsfwSources || extension.isNsfw.not())
|
||||||
}
|
}
|
||||||
|
|
||||||
Triple(installed, untrusted, available)
|
Extensions(updates, installed, available, untrusted)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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>,
|
||||||
|
)
|
@ -3,8 +3,7 @@ package eu.kanade.tachiyomi.ui.browse.extension
|
|||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import eu.kanade.domain.extension.interactor.GetExtensionUpdates
|
import eu.kanade.domain.extension.interactor.GetExtensionsByType
|
||||||
import eu.kanade.domain.extension.interactor.GetExtensions
|
|
||||||
import eu.kanade.presentation.browse.ExtensionState
|
import eu.kanade.presentation.browse.ExtensionState
|
||||||
import eu.kanade.presentation.browse.ExtensionsState
|
import eu.kanade.presentation.browse.ExtensionsState
|
||||||
import eu.kanade.presentation.browse.ExtensionsStateImpl
|
import eu.kanade.presentation.browse.ExtensionsStateImpl
|
||||||
@ -27,8 +26,7 @@ import uy.kohesive.injekt.api.get
|
|||||||
class ExtensionsPresenter(
|
class ExtensionsPresenter(
|
||||||
private val state: ExtensionsStateImpl = ExtensionState() as ExtensionsStateImpl,
|
private val state: ExtensionsStateImpl = ExtensionState() as ExtensionsStateImpl,
|
||||||
private val extensionManager: ExtensionManager = Injekt.get(),
|
private val extensionManager: ExtensionManager = Injekt.get(),
|
||||||
private val getExtensionUpdates: GetExtensionUpdates = Injekt.get(),
|
private val getExtensions: GetExtensionsByType = Injekt.get(),
|
||||||
private val getExtensions: GetExtensions = Injekt.get(),
|
|
||||||
) : BasePresenter<ExtensionsController>(), ExtensionsState by state {
|
) : BasePresenter<ExtensionsController>(), ExtensionsState by state {
|
||||||
|
|
||||||
private val _query: MutableStateFlow<String> = MutableStateFlow("")
|
private val _query: MutableStateFlow<String> = MutableStateFlow("")
|
||||||
@ -77,9 +75,8 @@ class ExtensionsPresenter(
|
|||||||
combine(
|
combine(
|
||||||
_query,
|
_query,
|
||||||
getExtensions.subscribe(),
|
getExtensions.subscribe(),
|
||||||
getExtensionUpdates.subscribe(),
|
|
||||||
_currentDownloads,
|
_currentDownloads,
|
||||||
) { query, (installed, untrusted, available), updates, downloads ->
|
) { query, (updates, installed, available, untrusted), downloads ->
|
||||||
val languagesWithExtensions = available
|
val languagesWithExtensions = available
|
||||||
.filter(queryFilter(query))
|
.filter(queryFilter(query))
|
||||||
.groupBy { LocaleHelper.getSourceDisplayName(it.lang, context) }
|
.groupBy { LocaleHelper.getSourceDisplayName(it.lang, context) }
|
||||||
|
Loading…
Reference in New Issue
Block a user