Update total number of chapters when refreshing MAL entries (fixes #4348)

This commit is contained in:
arkon 2021-01-24 16:58:23 -05:00
parent 1490112135
commit 34cb24fe34
2 changed files with 3 additions and 18 deletions

View File

@ -102,7 +102,7 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) {
} }
override suspend fun refresh(track: Track): Track { 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) override suspend fun login(username: String, password: String) = login(password)

View File

@ -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<JsonObject>()
.let { parseMangaItem(it, track) }
}
}
suspend fun addItemToList(track: Track): Track { suspend fun addItemToList(track: Track): Track {
return withIOContext { return withIOContext {
val formBody: RequestBody = FormBody.Builder() val formBody: RequestBody = FormBody.Builder()
@ -174,12 +158,13 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI
return withIOContext { return withIOContext {
val uri = "$baseApiUrl/manga".toUri().buildUpon() val uri = "$baseApiUrl/manga".toUri().buildUpon()
.appendPath(track.media_id.toString()) .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() .build()
authClient.newCall(GET(uri.toString())) authClient.newCall(GET(uri.toString()))
.await() .await()
.parseAs<JsonObject>() .parseAs<JsonObject>()
.let { obj -> .let { obj ->
track.total_chapters = obj["num_chapters"]!!.jsonPrimitive.int
obj.jsonObject["my_list_status"]?.jsonObject?.let { obj.jsonObject["my_list_status"]?.jsonObject?.let {
parseMangaItem(it, track) parseMangaItem(it, track)
} }