Fix recommendations throwing to early (#16)
* Fix recommendations throwing to early Co-authored-by: she11sh0cked <she11sh0cked@users.noreply.github.com>
This commit is contained in:
parent
bcfe5af135
commit
ef2241e0cb
@ -38,7 +38,7 @@ open class RecommendsPager(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun myAnimeList(): Observable<List<SMangaImpl>>? {
|
private fun myAnimeList(): Observable<List<SMangaImpl>>? {
|
||||||
fun getId(): Observable<String> {
|
fun getId(): Observable<String?> {
|
||||||
val endpoint =
|
val endpoint =
|
||||||
myAnimeListEndpoint.toHttpUrlOrNull()
|
myAnimeListEndpoint.toHttpUrlOrNull()
|
||||||
?: throw Exception("Could not convert endpoint url")
|
?: throw Exception("Could not convert endpoint url")
|
||||||
@ -69,17 +69,16 @@ open class RecommendsPager(
|
|||||||
val result = results.last()
|
val result = results.last()
|
||||||
val title = result["title"].string
|
val title = result["title"].string
|
||||||
if (!title.contains(manga.title, true)) {
|
if (!title.contains(manga.title, true)) {
|
||||||
throw Exception("Not found")
|
return@map null
|
||||||
}
|
}
|
||||||
val id = result["mal_id"].string
|
result["mal_id"].string
|
||||||
if (id.isEmpty()) {
|
|
||||||
throw Exception("Not found")
|
|
||||||
}
|
|
||||||
id
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return getId().map { id ->
|
return getId().map { id ->
|
||||||
|
if (id == null) {
|
||||||
|
return@map listOf<SMangaImpl>()
|
||||||
|
}
|
||||||
val endpoint =
|
val endpoint =
|
||||||
myAnimeListEndpoint.toHttpUrlOrNull()
|
myAnimeListEndpoint.toHttpUrlOrNull()
|
||||||
?: throw Exception("Could not convert endpoint url")
|
?: throw Exception("Could not convert endpoint url")
|
||||||
@ -184,7 +183,7 @@ open class RecommendsPager(
|
|||||||
title["native"].nullString?.contains("", true) != true &&
|
title["native"].nullString?.contains("", true) != true &&
|
||||||
countOccurrence(synonyms, manga.title) <= 0
|
countOccurrence(synonyms, manga.title) <= 0
|
||||||
) {
|
) {
|
||||||
throw Exception("Not found")
|
return@map listOf<SMangaImpl>()
|
||||||
}
|
}
|
||||||
val recommendations = result["recommendations"].obj
|
val recommendations = result["recommendations"].obj
|
||||||
val edges = recommendations["edges"].array
|
val edges = recommendations["edges"].array
|
||||||
@ -215,19 +214,24 @@ open class RecommendsPager(
|
|||||||
|
|
||||||
var recommendations: Observable<List<SMangaImpl>>? = null
|
var recommendations: Observable<List<SMangaImpl>>? = null
|
||||||
for (api in apiList) {
|
for (api in apiList) {
|
||||||
recommendations = when (api) {
|
val currentRecommendations = when (api) {
|
||||||
API.MYANIMELIST -> myAnimeList()
|
API.MYANIMELIST -> myAnimeList()
|
||||||
API.ANILIST -> anilist()
|
API.ANILIST -> anilist()
|
||||||
}
|
}
|
||||||
?: throw Exception("Could not get recommendations")
|
|
||||||
|
|
||||||
val recommendationsBlocking = recommendations.toBlocking().first()
|
if (currentRecommendations != null &&
|
||||||
if (recommendationsBlocking.isNotEmpty()) {
|
currentRecommendations.toBlocking().first().isNotEmpty()
|
||||||
|
) {
|
||||||
|
recommendations = currentRecommendations
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return recommendations!!.map {
|
if (recommendations == null) {
|
||||||
|
throw Exception("No recommendations found")
|
||||||
|
}
|
||||||
|
|
||||||
|
return recommendations.map {
|
||||||
MangasPage(it, false)
|
MangasPage(it, false)
|
||||||
}.doOnNext {
|
}.doOnNext {
|
||||||
onPageReceived(it)
|
onPageReceived(it)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user