From 05b05be0bd1f0e896c5cceb35399cdb2d31e51c8 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Mon, 15 Jul 2024 15:46:48 +0300 Subject: [PATCH] Fix dynamic sources --- .../kotatsu/download/ui/worker/DownloadWorker.kt | 1 - .../kotatsu/explore/data/MangaSourcesRepository.kt | 14 ++++++++------ .../kotatsu/filter/ui/FilterCoordinator.kt | 4 ++-- .../kotatsu/remotelist/ui/RemoteListViewModel.kt | 5 ++--- .../sources/catalog/SourcesCatalogViewModel.kt | 6 ++---- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadWorker.kt b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadWorker.kt index eeb507b59..4a30fa7b8 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadWorker.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadWorker.kt @@ -44,7 +44,6 @@ import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.exceptions.TooManyRequestExceptions import org.koitharu.kotatsu.core.model.ids import org.koitharu.kotatsu.core.model.isLocal -import org.koitharu.kotatsu.core.network.CommonHeaders import org.koitharu.kotatsu.core.network.MangaHttpClient import org.koitharu.kotatsu.core.network.imageproxy.ImageProxyInterceptor import org.koitharu.kotatsu.core.parser.MangaDataRepository diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt b/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt index 31ecdc995..f31327dc6 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt @@ -79,7 +79,7 @@ class MangaSourcesRepository @Inject constructor( return result } - suspend fun getAvailableSources( + suspend fun queryParserSources( isDisabledOnly: Boolean, isNewOnly: Boolean, excludeBroken: Boolean, @@ -87,7 +87,7 @@ class MangaSourcesRepository @Inject constructor( query: String?, locale: String?, sortOrder: SourcesSortOrder?, - ): List { + ): List { assimilateNewSources() val entities = dao.findAll().toMutableList() if (isDisabledOnly) { @@ -99,15 +99,17 @@ class MangaSourcesRepository @Inject constructor( val sources = entities.toSources( skipNsfwSources = settings.isNsfwContentDisabled, sortOrder = sortOrder, - ) + ).run { + filterIsInstanceTo(ArrayList(size)) + } if (locale != null) { - sources.retainAll { it is MangaParserSource && it.locale == locale } + sources.retainAll { it.locale == locale } } if (excludeBroken) { - sources.removeAll { it is MangaParserSource && it.isBroken } + sources.removeAll { it.isBroken } } if (types.isNotEmpty()) { - sources.retainAll { it is MangaParserSource && it.contentType in types } + sources.retainAll { it.contentType in types } } if (!query.isNullOrEmpty()) { sources.retainAll { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/FilterCoordinator.kt b/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/FilterCoordinator.kt index c5a75289d..304a0be28 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/FilterCoordinator.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/FilterCoordinator.kt @@ -24,6 +24,7 @@ import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import kotlinx.coroutines.plus import org.koitharu.kotatsu.R +import org.koitharu.kotatsu.core.model.MangaSource import org.koitharu.kotatsu.core.parser.MangaDataRepository import org.koitharu.kotatsu.core.parser.MangaRepository import org.koitharu.kotatsu.core.ui.widgets.ChipsView @@ -31,7 +32,6 @@ import org.koitharu.kotatsu.core.util.LocaleComparator import org.koitharu.kotatsu.core.util.ext.asArrayList import org.koitharu.kotatsu.core.util.ext.lifecycleScope import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug -import org.koitharu.kotatsu.core.util.ext.require import org.koitharu.kotatsu.filter.ui.model.FilterHeaderModel import org.koitharu.kotatsu.filter.ui.model.FilterProperty import org.koitharu.kotatsu.filter.ui.model.TagCatalogItem @@ -67,7 +67,7 @@ class FilterCoordinator @Inject constructor( ) : MangaFilter { private val coroutineScope = lifecycle.lifecycleScope - private val repository = mangaRepositoryFactory.create(savedStateHandle.require(RemoteListFragment.ARG_SOURCE)) + private val repository = mangaRepositoryFactory.create(MangaSource(savedStateHandle[RemoteListFragment.ARG_SOURCE])) private val currentState = MutableStateFlow( MangaListFilter.Advanced( sortOrder = repository.defaultSortOrder, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListViewModel.kt index 05653b7fc..cef84a201 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListViewModel.kt @@ -18,6 +18,7 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.plus import org.koitharu.kotatsu.R +import org.koitharu.kotatsu.core.model.MangaSource import org.koitharu.kotatsu.core.model.distinctById import org.koitharu.kotatsu.core.parser.MangaRepository import org.koitharu.kotatsu.core.parser.RemoteMangaRepository @@ -25,7 +26,6 @@ import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.util.ext.MutableEventFlow import org.koitharu.kotatsu.core.util.ext.call import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug -import org.koitharu.kotatsu.core.util.ext.require import org.koitharu.kotatsu.core.util.ext.sizeOrZero import org.koitharu.kotatsu.download.ui.worker.DownloadWorker import org.koitharu.kotatsu.explore.data.MangaSourcesRepository @@ -44,7 +44,6 @@ import org.koitharu.kotatsu.list.ui.model.toUi import org.koitharu.kotatsu.parsers.exception.NotFoundException import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.MangaListFilter -import org.koitharu.kotatsu.parsers.model.MangaSource import org.koitharu.kotatsu.parsers.model.MangaTag import javax.inject.Inject @@ -62,7 +61,7 @@ open class RemoteListViewModel @Inject constructor( sourcesRepository: MangaSourcesRepository, ) : MangaListViewModel(settings, downloadScheduler), MangaFilter by filter { - val source = savedStateHandle.require(RemoteListFragment.ARG_SOURCE) + val source = MangaSource(savedStateHandle[RemoteListFragment.ARG_SOURCE]) val isRandomLoading = MutableStateFlow(false) val onOpenManga = MutableEventFlow() diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/catalog/SourcesCatalogViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/catalog/SourcesCatalogViewModel.kt index 227e70412..a924dfc5b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/catalog/SourcesCatalogViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/catalog/SourcesCatalogViewModel.kt @@ -98,7 +98,7 @@ class SourcesCatalogViewModel @Inject constructor( } private suspend fun buildSourcesList(filter: SourcesCatalogFilter, query: String?): List { - val sources = repository.getAvailableSources( + val sources = repository.queryParserSources( isDisabledOnly = true, isNewOnly = filter.isNewOnly, excludeBroken = false, @@ -124,9 +124,7 @@ class SourcesCatalogViewModel @Inject constructor( }, ) } else { - sources.sortedBy { - it.isBroken - }.map { + sources.map { SourceCatalogItem.Source(source = it) } }