allow extensions to disable related mangas & catching exception when using search for related mangas
This commit is contained in:
parent
0cf256ccce
commit
28ebabffbc
1 changed files with 17 additions and 7 deletions
|
|
@ -20,12 +20,14 @@ import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.awaitAll
|
import kotlinx.coroutines.awaitAll
|
||||||
|
import logcat.LogPriority
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import tachiyomi.core.common.util.lang.awaitSingle
|
import tachiyomi.core.common.util.lang.awaitSingle
|
||||||
|
import tachiyomi.core.common.util.system.logcat
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
|
|
@ -287,6 +289,7 @@ abstract class HttpSource : CatalogueSource {
|
||||||
* @since extensions-lib 1.6
|
* @since extensions-lib 1.6
|
||||||
*/
|
*/
|
||||||
protected open val supportsRelatedMangas: Boolean get() = false
|
protected open val supportsRelatedMangas: Boolean get() = false
|
||||||
|
protected open val disableRelatedMangas: Boolean get() = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all the available related mangas for a manga.
|
* Get all the available related mangas for a manga.
|
||||||
|
|
@ -298,10 +301,18 @@ abstract class HttpSource : CatalogueSource {
|
||||||
*/
|
*/
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
override suspend fun getRelatedMangaList(manga: SManga): List<SManga> {
|
override suspend fun getRelatedMangaList(manga: SManga): List<SManga> {
|
||||||
return if (supportsRelatedMangas)
|
return when {
|
||||||
fetchRelatedMangaList(manga).awaitSingle()
|
supportsRelatedMangas -> fetchRelatedMangaList(manga).awaitSingle()
|
||||||
else
|
disableRelatedMangas -> emptyList()
|
||||||
return fetchRelatedMangaListBySearch(manga)
|
else -> {
|
||||||
|
try {
|
||||||
|
fetchRelatedMangaListBySearch(manga)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logcat(LogPriority.ERROR, e)
|
||||||
|
throw UnsupportedOperationException("Error getting related titles.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -330,7 +341,8 @@ abstract class HttpSource : CatalogueSource {
|
||||||
if (words.isEmpty()) {
|
if (words.isEmpty()) {
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
val results = words.map { keyword ->
|
|
||||||
|
return words.map { keyword ->
|
||||||
scope.async {
|
scope.async {
|
||||||
client.newCall(searchMangaRequest(0, keyword, FilterList()))
|
client.newCall(searchMangaRequest(0, keyword, FilterList()))
|
||||||
.execute()
|
.execute()
|
||||||
|
|
@ -344,8 +356,6 @@ abstract class HttpSource : CatalogueSource {
|
||||||
}
|
}
|
||||||
}.awaitAll()
|
}.awaitAll()
|
||||||
.minBy { if (it.isEmpty()) Int.MAX_VALUE else it.size }
|
.minBy { if (it.isEmpty()) Int.MAX_VALUE else it.size }
|
||||||
|
|
||||||
return results
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue