From 34cb24fe34be97d30c4278b9e6ae183a56649fcb Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 24 Jan 2021 16:58:23 -0500 Subject: [PATCH] Update total number of chapters when refreshing MAL entries (fixes #4348) --- .../data/track/myanimelist/MyAnimeList.kt | 2 +- .../data/track/myanimelist/MyAnimeListApi.kt | 19 ++----------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt index cfbc252473..9c42e6987b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt @@ -102,7 +102,7 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) { } override suspend fun refresh(track: Track): Track { - return api.getListItem(track) + return api.findListItem(track) ?: api.addItemToList(track) } override suspend fun login(username: String, password: String) = login(password) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt index 592d350def..25e4621ff4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt @@ -111,22 +111,6 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI } } - suspend fun getListItem(track: Track): Track { - return withIOContext { - val formBody: RequestBody = FormBody.Builder() - .add("status", track.toMyAnimeListStatus() ?: "reading") - .build() - val request = Request.Builder() - .url(mangaUrl(track.media_id).toString()) - .put(formBody) - .build() - authClient.newCall(request) - .await() - .parseAs() - .let { parseMangaItem(it, track) } - } - } - suspend fun addItemToList(track: Track): Track { return withIOContext { val formBody: RequestBody = FormBody.Builder() @@ -174,12 +158,13 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI return withIOContext { val uri = "$baseApiUrl/manga".toUri().buildUpon() .appendPath(track.media_id.toString()) - .appendQueryParameter("fields", "my_list_status{start_date,finish_date}") + .appendQueryParameter("fields", "num_chapters,my_list_status{start_date,finish_date}") .build() authClient.newCall(GET(uri.toString())) .await() .parseAs() .let { obj -> + track.total_chapters = obj["num_chapters"]!!.jsonPrimitive.int obj.jsonObject["my_list_status"]?.jsonObject?.let { parseMangaItem(it, track) }