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 cfbc25247..9c42e6987 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 592d350de..25e4621ff 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) }