Do a bit of cleanup
This commit is contained in:
parent
fccf609c81
commit
46998d81f4
@ -5,6 +5,7 @@ import eu.kanade.tachiyomi.network.await
|
|||||||
import eu.kanade.tachiyomi.source.model.MangasPage
|
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||||
import eu.kanade.tachiyomi.source.model.SMangaImpl
|
import eu.kanade.tachiyomi.source.model.SMangaImpl
|
||||||
import eu.kanade.tachiyomi.ui.browse.source.browse.Pager
|
import eu.kanade.tachiyomi.ui.browse.source.browse.Pager
|
||||||
|
import exh.log.maybeInjectEHLogger
|
||||||
import exh.util.MangaType
|
import exh.util.MangaType
|
||||||
import exh.util.mangaType
|
import exh.util.mangaType
|
||||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
@ -31,7 +32,9 @@ import timber.log.Timber
|
|||||||
|
|
||||||
abstract class API(_endpoint: String) {
|
abstract class API(_endpoint: String) {
|
||||||
var endpoint: String = _endpoint
|
var endpoint: String = _endpoint
|
||||||
val client = OkHttpClient.Builder().build()
|
val client = OkHttpClient.Builder()
|
||||||
|
.maybeInjectEHLogger()
|
||||||
|
.build()
|
||||||
val scope = CoroutineScope(Job() + Dispatchers.Default)
|
val scope = CoroutineScope(Job() + Dispatchers.Default)
|
||||||
|
|
||||||
abstract fun getRecsBySearch(
|
abstract fun getRecsBySearch(
|
||||||
@ -40,13 +43,12 @@ abstract class API(_endpoint: String) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyAnimeList() : API("https://api.jikan.moe/v3/") {
|
class MyAnimeList : API("https://api.jikan.moe/v3/") {
|
||||||
fun getRecsById(
|
private fun getRecsById(
|
||||||
id: String,
|
id: String,
|
||||||
callback: (resolve: List<SMangaImpl>?, reject: Throwable?) -> Unit
|
callback: (resolve: List<SMangaImpl>?, reject: Throwable?) -> Unit
|
||||||
) {
|
) {
|
||||||
val httpUrl =
|
val httpUrl = endpoint.toHttpUrlOrNull()
|
||||||
endpoint.toHttpUrlOrNull()
|
|
||||||
if (httpUrl == null) {
|
if (httpUrl == null) {
|
||||||
callback.invoke(null, Exception("Could not convert endpoint url"))
|
callback.invoke(null, Exception("Could not convert endpoint url"))
|
||||||
return
|
return
|
||||||
@ -135,7 +137,7 @@ class MyAnimeList() : API("https://api.jikan.moe/v3/") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Anilist() : API("https://graphql.anilist.co/") {
|
class Anilist : API("https://graphql.anilist.co/") {
|
||||||
private fun countOccurrence(arr: JsonArray, search: String): Int {
|
private fun countOccurrence(arr: JsonArray, search: String): Int {
|
||||||
return arr.count {
|
return arr.count {
|
||||||
val synonym = it.jsonPrimitive.content
|
val synonym = it.jsonPrimitive.content
|
||||||
@ -250,9 +252,9 @@ class Anilist() : API("https://graphql.anilist.co/") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
open class RecommendsPager(
|
open class RecommendsPager(
|
||||||
val manga: Manga,
|
private val manga: Manga,
|
||||||
val smart: Boolean = true,
|
private val smart: Boolean = true,
|
||||||
var preferredApi: API = API.MYANIMELIST
|
private var preferredApi: API = API.MYANIMELIST
|
||||||
) : Pager() {
|
) : Pager() {
|
||||||
private val apiList = API_MAP.toMutableMap()
|
private val apiList = API_MAP.toMutableMap()
|
||||||
private var currentApi: API? = null
|
private var currentApi: API? = null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user