From c63ef3dda2e8406b0c5edecbe9e387a1d7dc9450 Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 2 Aug 2018 21:37:45 -0400 Subject: [PATCH] fix status not showing completed, when cancelled status on mangadex. (#426) fix status not showing completed, when last chapter was not selected language --- .../tachiyomi/extension/all/mangadex/Mangadex.kt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt index 36a167eb0..c123ba133 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt @@ -225,6 +225,7 @@ open class Mangadex(override val lang: String, private val internalLang: String, var jsonData = response.body()!!.string() val json = JsonParser().parse(jsonData).asJsonObject val mangaJson = json.getAsJsonObject("manga") + val chapterJson = json.getAsJsonObject("chapter") manga.title = baseUrl + mangaJson.get("title").string manga.thumbnail_url = baseUrl + mangaJson.get("cover_url").string manga.description = cleanString(mangaJson.get("description").string) @@ -232,7 +233,7 @@ open class Mangadex(override val lang: String, private val internalLang: String, manga.artist = mangaJson.get("artist").string val status = mangaJson.get("status").int val finalChapterNumber = getFinalChapter(mangaJson) - if (status == 2 && json.getAsJsonObject("chapter") != null && isMangaCompleted(finalChapterNumber, json.getAsJsonObject("chapter"))) { + if ((status == 2 || status == 3) && chapterJson != null && isMangaCompleted(finalChapterNumber, chapterJson)) { manga.status = SManga.COMPLETED } else { manga.status = parseStatus(status) @@ -271,17 +272,13 @@ open class Mangadex(override val lang: String, private val internalLang: String, private fun getFinalChapter(jsonObj: JsonObject) = jsonObj.get("last_chapter").string.trim() private fun isMangaCompleted(finalChapterNumber: String, chapterJson: JsonObject): Boolean { - - val count = chapterJson?.toMap().values.filter { it -> - val chapterElement = it.asJsonObject - return chapterElement.get("lang_code").string == internalLang && doesFinalChapterExist(finalChapterNumber, it) - }?.count() - + val count = chapterJson.entrySet() + .filter { it -> it.value.asJsonObject.get("lang_code").string == internalLang } + .filter { it -> doesFinalChapterExist(finalChapterNumber, it.value) }?.count() return when (count) { 0 -> false else -> true } - } private fun doesFinalChapterExist(finalChapterNumber: String, chapterJson: JsonElement) = finalChapterNumber.isNotEmpty() && finalChapterNumber == chapterJson.get("chapter").string.trim() @@ -326,7 +323,7 @@ open class Mangadex(override val lang: String, private val internalLang: String, } chapterName.add(chapterJson.get("title").string) } - if (status == 2 && doesFinalChapterExist(finalChapterNumber, chapterJson)) { + if ((status == 2 || status == 3) && doesFinalChapterExist(finalChapterNumber, chapterJson)) { chapterName.add("[END]") }