Refactor SourceManager/StubSource to domain module

This commit is contained in:
arkon
2023-03-05 12:38:31 -05:00
parent f96f0c5889
commit ad4912803b
41 changed files with 140 additions and 113 deletions

View File

@@ -1,4 +1,4 @@
package tachiyomi.domain.service
package tachiyomi.domain.backup.service
import tachiyomi.core.preference.PreferenceStore
import tachiyomi.core.provider.FolderProvider

View File

@@ -0,0 +1,50 @@
package tachiyomi.domain.source.model
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import rx.Observable
@Suppress("OverridingDeprecatedMember")
class StubSource(private val sourceData: SourceData) : Source {
override val id: Long = sourceData.id
override val name: String = sourceData.name.ifBlank { id.toString() }
override val lang: String = sourceData.lang
override suspend fun getMangaDetails(manga: SManga): SManga {
throw SourceNotInstalledException()
}
@Deprecated("Use the 1.x API instead", replaceWith = ReplaceWith("getMangaDetails"))
override fun fetchMangaDetails(manga: SManga): Observable<SManga> {
return Observable.error(SourceNotInstalledException())
}
override suspend fun getChapterList(manga: SManga): List<SChapter> {
throw SourceNotInstalledException()
}
@Deprecated("Use the 1.x API instead", replaceWith = ReplaceWith("getChapterList"))
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
return Observable.error(SourceNotInstalledException())
}
override suspend fun getPageList(chapter: SChapter): List<Page> {
throw SourceNotInstalledException()
}
@Deprecated("Use the 1.x API instead", replaceWith = ReplaceWith("getPageList"))
override fun fetchPageList(chapter: SChapter): Observable<List<Page>> {
return Observable.error(SourceNotInstalledException())
}
override fun toString(): String {
return if (sourceData.isMissingInfo.not()) "$name (${lang.uppercase()})" else id.toString()
}
}
class SourceNotInstalledException : Exception()

View File

@@ -0,0 +1,22 @@
package tachiyomi.domain.source.service
import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.online.HttpSource
import kotlinx.coroutines.flow.Flow
import tachiyomi.domain.source.model.StubSource
interface SourceManager {
val catalogueSources: Flow<List<CatalogueSource>>
fun get(sourceKey: Long): Source?
fun getOrStub(sourceKey: Long): Source
fun getOnlineSources(): List<HttpSource>
fun getCatalogueSources(): List<CatalogueSource>
fun getStubSources(): List<StubSource>
}