Move sourceMapper to data module

This commit is contained in:
arkon 2023-03-05 12:05:48 -05:00
parent 9caa0d147b
commit 2b9acadc5b
4 changed files with 31 additions and 26 deletions

View file

@ -1,19 +0,0 @@
package eu.kanade.data.source
import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.SourceManager
import tachiyomi.domain.source.model.Source
val sourceMapper: (eu.kanade.tachiyomi.source.Source) -> Source = { source ->
Source(
source.id,
source.lang,
source.name,
supportsLatest = false,
isStub = source is SourceManager.StubSource,
)
}
val catalogueSourceMapper: (CatalogueSource) -> Source = { source ->
sourceMapper(source).copy(supportsLatest = source.supportsLatest)
}

View file

@ -4,6 +4,7 @@ import eu.kanade.domain.source.repository.SourceRepository
import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.online.HttpSource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import tachiyomi.data.DatabaseHandler
@ -11,6 +12,7 @@ import tachiyomi.data.source.SourceLatestPagingSource
import tachiyomi.data.source.SourcePagingSourceType
import tachiyomi.data.source.SourcePopularPagingSource
import tachiyomi.data.source.SourceSearchPagingSource
import tachiyomi.data.source.sourceMapper
import tachiyomi.domain.source.model.Source
import tachiyomi.domain.source.model.SourceWithCount
import tachiyomi.source.local.LocalSource
@ -22,13 +24,19 @@ class SourceRepositoryImpl(
override fun getSources(): Flow<List<Source>> {
return sourceManager.catalogueSources.map { sources ->
sources.map(catalogueSourceMapper)
sources.map {
sourceMapper(it).copy(
supportsLatest = it.supportsLatest,
)
}
}
}
override fun getOnlineSources(): Flow<List<Source>> {
return sourceManager.onlineSources.map { sources ->
sources.map(sourceMapper)
return sourceManager.catalogueSources.map { sources ->
sources
.filterIsInstance<HttpSource>()
.map(sourceMapper)
}
}
@ -38,8 +46,11 @@ class SourceRepositoryImpl(
sourceIdsWithCount
.filterNot { it.source == LocalSource.ID }
.map { (sourceId, count) ->
val source = sourceMapper(sourceManager.getOrStub(sourceId))
source to count
val source = sourceManager.getOrStub(sourceId)
val domainSource = sourceMapper(source).copy(
isStub = source is SourceManager.StubSource,
)
domainSource to count
}
}
}
@ -49,7 +60,10 @@ class SourceRepositoryImpl(
return sourceIdWithNonLibraryManga.map { sourceId ->
sourceId.map { (sourceId, count) ->
val source = sourceManager.getOrStub(sourceId)
SourceWithCount(sourceMapper(source), count)
val domainSource = sourceMapper(source).copy(
isStub = source is SourceManager.StubSource,
)
SourceWithCount(domainSource, count)
}
}
}

View file

@ -40,7 +40,6 @@ class SourceManager(
private val stubSourcesMap = ConcurrentHashMap<Long, StubSource>()
val catalogueSources: Flow<List<CatalogueSource>> = sourcesMapFlow.map { it.values.filterIsInstance<CatalogueSource>() }
val onlineSources: Flow<List<HttpSource>> = catalogueSources.map { it.filterIsInstance<HttpSource>() }
init {
scope.launch {

View file

@ -1,7 +1,18 @@
package tachiyomi.data.source
import tachiyomi.domain.source.model.Source
import tachiyomi.domain.source.model.SourceData
val sourceMapper: (eu.kanade.tachiyomi.source.Source) -> Source = { source ->
Source(
source.id,
source.lang,
source.name,
supportsLatest = false,
isStub = false,
)
}
val sourceDataMapper: (Long, String, String) -> SourceData = { id, lang, name ->
SourceData(id, lang, name)
}