2020-01-05 20:43:07 +01:00
|
|
|
package eu.kanade.tachiyomi.source
|
|
|
|
|
2020-03-20 06:52:03 +01:00
|
|
|
import android.graphics.drawable.Drawable
|
|
|
|
import eu.kanade.tachiyomi.extension.ExtensionManager
|
2020-01-05 20:43:07 +01:00
|
|
|
import eu.kanade.tachiyomi.source.model.Page
|
|
|
|
import eu.kanade.tachiyomi.source.model.SChapter
|
|
|
|
import eu.kanade.tachiyomi.source.model.SManga
|
2020-10-26 15:52:28 +01:00
|
|
|
import eu.kanade.tachiyomi.source.model.toChapterInfo
|
|
|
|
import eu.kanade.tachiyomi.source.model.toMangaInfo
|
2020-11-08 01:22:01 +01:00
|
|
|
import eu.kanade.tachiyomi.source.model.toPageUrl
|
2020-10-26 15:52:28 +01:00
|
|
|
import eu.kanade.tachiyomi.source.model.toSChapter
|
|
|
|
import eu.kanade.tachiyomi.source.model.toSManga
|
|
|
|
import eu.kanade.tachiyomi.util.lang.awaitSingle
|
2020-01-05 20:43:07 +01:00
|
|
|
import rx.Observable
|
2020-10-26 15:52:28 +01:00
|
|
|
import tachiyomi.source.model.ChapterInfo
|
|
|
|
import tachiyomi.source.model.MangaInfo
|
2020-03-20 06:52:03 +01:00
|
|
|
import uy.kohesive.injekt.Injekt
|
|
|
|
import uy.kohesive.injekt.api.get
|
2020-01-05 20:43:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A basic interface for creating a source. It could be an online source, a local source, etc...
|
|
|
|
*/
|
2020-10-26 15:52:28 +01:00
|
|
|
interface Source : tachiyomi.source.Source {
|
2020-01-05 20:43:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Id for the source. Must be unique.
|
|
|
|
*/
|
2020-10-26 15:52:28 +01:00
|
|
|
override val id: Long
|
2020-01-05 20:43:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of the source.
|
|
|
|
*/
|
2020-10-26 15:52:28 +01:00
|
|
|
override val name: String
|
|
|
|
|
|
|
|
override val lang: String
|
|
|
|
get() = ""
|
2020-01-05 20:43:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an observable with the updated details for a manga.
|
|
|
|
*
|
|
|
|
* @param manga the manga to update.
|
|
|
|
*/
|
2021-11-28 21:27:21 +01:00
|
|
|
@Deprecated(
|
|
|
|
"Use the 1.x API instead",
|
|
|
|
ReplaceWith("getMangaDetails")
|
|
|
|
)
|
|
|
|
fun fetchMangaDetails(manga: SManga): Observable<SManga> = throw IllegalStateException("Not used")
|
2020-01-05 20:43:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an observable with all the available chapters for a manga.
|
|
|
|
*
|
|
|
|
* @param manga the manga to update.
|
|
|
|
*/
|
2021-11-28 21:27:21 +01:00
|
|
|
@Deprecated(
|
|
|
|
"Use the 1.x API instead",
|
|
|
|
ReplaceWith("getChapterList")
|
|
|
|
)
|
|
|
|
fun fetchChapterList(manga: SManga): Observable<List<SChapter>> = throw IllegalStateException("Not used")
|
2020-01-05 20:43:07 +01:00
|
|
|
|
2021-11-28 21:27:21 +01:00
|
|
|
// TODO: remove direct usages on this method
|
2020-01-05 20:43:07 +01:00
|
|
|
/**
|
|
|
|
* Returns an observable with the list of pages a chapter has.
|
|
|
|
*
|
|
|
|
* @param chapter the chapter.
|
|
|
|
*/
|
2021-11-28 21:27:21 +01:00
|
|
|
@Deprecated(
|
|
|
|
"Use the 1.x API instead",
|
|
|
|
ReplaceWith("getPageList")
|
|
|
|
)
|
2021-11-19 22:42:19 +01:00
|
|
|
fun fetchPageList(chapter: SChapter): Observable<List<Page>> = Observable.empty()
|
2020-10-26 15:52:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [1.x API] Get the updated details for a manga.
|
|
|
|
*/
|
2020-12-13 05:50:28 +01:00
|
|
|
@Suppress("DEPRECATION")
|
2020-10-26 15:52:28 +01:00
|
|
|
override suspend fun getMangaDetails(manga: MangaInfo): MangaInfo {
|
2020-12-14 02:47:48 +01:00
|
|
|
val sManga = manga.toSManga()
|
|
|
|
val networkManga = fetchMangaDetails(sManga).awaitSingle()
|
|
|
|
sManga.copyFrom(networkManga)
|
|
|
|
return sManga.toMangaInfo()
|
2020-10-26 15:52:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [1.x API] Get all the available chapters for a manga.
|
|
|
|
*/
|
2020-12-13 05:50:28 +01:00
|
|
|
@Suppress("DEPRECATION")
|
2020-10-26 15:52:28 +01:00
|
|
|
override suspend fun getChapterList(manga: MangaInfo): List<ChapterInfo> {
|
|
|
|
return fetchChapterList(manga.toSManga()).awaitSingle()
|
|
|
|
.map { it.toChapterInfo() }
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [1.x API] Get the list of pages a chapter has.
|
|
|
|
*/
|
2020-12-13 05:50:28 +01:00
|
|
|
@Suppress("DEPRECATION")
|
2020-10-26 15:52:28 +01:00
|
|
|
override suspend fun getPageList(chapter: ChapterInfo): List<tachiyomi.source.model.Page> {
|
|
|
|
return fetchPageList(chapter.toSChapter()).awaitSingle()
|
2020-11-08 01:22:01 +01:00
|
|
|
.map { it.toPageUrl() }
|
2020-10-26 15:52:28 +01:00
|
|
|
}
|
2020-02-27 00:03:34 +01:00
|
|
|
}
|
2020-03-20 06:52:03 +01:00
|
|
|
|
|
|
|
fun Source.icon(): Drawable? = Injekt.get<ExtensionManager>().getAppIconForSource(this)
|
2020-06-18 04:09:48 +02:00
|
|
|
|
|
|
|
fun Source.getPreferenceKey(): String = "source_$id"
|