Fix dynamic sources

This commit is contained in:
Koitharu
2024-07-15 15:46:48 +03:00
parent 287861f5d7
commit 05b05be0bd
5 changed files with 14 additions and 16 deletions

View File

@@ -44,7 +44,6 @@ import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.exceptions.TooManyRequestExceptions import org.koitharu.kotatsu.core.exceptions.TooManyRequestExceptions
import org.koitharu.kotatsu.core.model.ids import org.koitharu.kotatsu.core.model.ids
import org.koitharu.kotatsu.core.model.isLocal 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.MangaHttpClient
import org.koitharu.kotatsu.core.network.imageproxy.ImageProxyInterceptor import org.koitharu.kotatsu.core.network.imageproxy.ImageProxyInterceptor
import org.koitharu.kotatsu.core.parser.MangaDataRepository import org.koitharu.kotatsu.core.parser.MangaDataRepository

View File

@@ -79,7 +79,7 @@ class MangaSourcesRepository @Inject constructor(
return result return result
} }
suspend fun getAvailableSources( suspend fun queryParserSources(
isDisabledOnly: Boolean, isDisabledOnly: Boolean,
isNewOnly: Boolean, isNewOnly: Boolean,
excludeBroken: Boolean, excludeBroken: Boolean,
@@ -87,7 +87,7 @@ class MangaSourcesRepository @Inject constructor(
query: String?, query: String?,
locale: String?, locale: String?,
sortOrder: SourcesSortOrder?, sortOrder: SourcesSortOrder?,
): List<MangaSource> { ): List<MangaParserSource> {
assimilateNewSources() assimilateNewSources()
val entities = dao.findAll().toMutableList() val entities = dao.findAll().toMutableList()
if (isDisabledOnly) { if (isDisabledOnly) {
@@ -99,15 +99,17 @@ class MangaSourcesRepository @Inject constructor(
val sources = entities.toSources( val sources = entities.toSources(
skipNsfwSources = settings.isNsfwContentDisabled, skipNsfwSources = settings.isNsfwContentDisabled,
sortOrder = sortOrder, sortOrder = sortOrder,
) ).run {
filterIsInstanceTo(ArrayList<MangaParserSource>(size))
}
if (locale != null) { if (locale != null) {
sources.retainAll { it is MangaParserSource && it.locale == locale } sources.retainAll { it.locale == locale }
} }
if (excludeBroken) { if (excludeBroken) {
sources.removeAll { it is MangaParserSource && it.isBroken } sources.removeAll { it.isBroken }
} }
if (types.isNotEmpty()) { if (types.isNotEmpty()) {
sources.retainAll { it is MangaParserSource && it.contentType in types } sources.retainAll { it.contentType in types }
} }
if (!query.isNullOrEmpty()) { if (!query.isNullOrEmpty()) {
sources.retainAll { sources.retainAll {

View File

@@ -24,6 +24,7 @@ import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.plus import kotlinx.coroutines.plus
import org.koitharu.kotatsu.R 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.MangaDataRepository
import org.koitharu.kotatsu.core.parser.MangaRepository import org.koitharu.kotatsu.core.parser.MangaRepository
import org.koitharu.kotatsu.core.ui.widgets.ChipsView 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.asArrayList
import org.koitharu.kotatsu.core.util.ext.lifecycleScope import org.koitharu.kotatsu.core.util.ext.lifecycleScope
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug 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.FilterHeaderModel
import org.koitharu.kotatsu.filter.ui.model.FilterProperty import org.koitharu.kotatsu.filter.ui.model.FilterProperty
import org.koitharu.kotatsu.filter.ui.model.TagCatalogItem import org.koitharu.kotatsu.filter.ui.model.TagCatalogItem
@@ -67,7 +67,7 @@ class FilterCoordinator @Inject constructor(
) : MangaFilter { ) : MangaFilter {
private val coroutineScope = lifecycle.lifecycleScope 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( private val currentState = MutableStateFlow(
MangaListFilter.Advanced( MangaListFilter.Advanced(
sortOrder = repository.defaultSortOrder, sortOrder = repository.defaultSortOrder,

View File

@@ -18,6 +18,7 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.plus import kotlinx.coroutines.plus
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.model.MangaSource
import org.koitharu.kotatsu.core.model.distinctById import org.koitharu.kotatsu.core.model.distinctById
import org.koitharu.kotatsu.core.parser.MangaRepository import org.koitharu.kotatsu.core.parser.MangaRepository
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository 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.MutableEventFlow
import org.koitharu.kotatsu.core.util.ext.call import org.koitharu.kotatsu.core.util.ext.call
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug 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.core.util.ext.sizeOrZero
import org.koitharu.kotatsu.download.ui.worker.DownloadWorker import org.koitharu.kotatsu.download.ui.worker.DownloadWorker
import org.koitharu.kotatsu.explore.data.MangaSourcesRepository 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.exception.NotFoundException
import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.model.MangaListFilter import org.koitharu.kotatsu.parsers.model.MangaListFilter
import org.koitharu.kotatsu.parsers.model.MangaSource
import org.koitharu.kotatsu.parsers.model.MangaTag import org.koitharu.kotatsu.parsers.model.MangaTag
import javax.inject.Inject import javax.inject.Inject
@@ -62,7 +61,7 @@ open class RemoteListViewModel @Inject constructor(
sourcesRepository: MangaSourcesRepository, sourcesRepository: MangaSourcesRepository,
) : MangaListViewModel(settings, downloadScheduler), MangaFilter by filter { ) : MangaListViewModel(settings, downloadScheduler), MangaFilter by filter {
val source = savedStateHandle.require<MangaSource>(RemoteListFragment.ARG_SOURCE) val source = MangaSource(savedStateHandle[RemoteListFragment.ARG_SOURCE])
val isRandomLoading = MutableStateFlow(false) val isRandomLoading = MutableStateFlow(false)
val onOpenManga = MutableEventFlow<Manga>() val onOpenManga = MutableEventFlow<Manga>()

View File

@@ -98,7 +98,7 @@ class SourcesCatalogViewModel @Inject constructor(
} }
private suspend fun buildSourcesList(filter: SourcesCatalogFilter, query: String?): List<SourceCatalogItem> { private suspend fun buildSourcesList(filter: SourcesCatalogFilter, query: String?): List<SourceCatalogItem> {
val sources = repository.getAvailableSources( val sources = repository.queryParserSources(
isDisabledOnly = true, isDisabledOnly = true,
isNewOnly = filter.isNewOnly, isNewOnly = filter.isNewOnly,
excludeBroken = false, excludeBroken = false,
@@ -124,9 +124,7 @@ class SourcesCatalogViewModel @Inject constructor(
}, },
) )
} else { } else {
sources.sortedBy { sources.map {
it.isBroken
}.map {
SourceCatalogItem.Source(source = it) SourceCatalogItem.Source(source = it)
} }
} }