From cc6ae9d1a864bafdefb8f093505d068fa70a0da4 Mon Sep 17 00:00:00 2001 From: mutsumi <4182301+mutsumi63@users.noreply.github.com> Date: Sun, 28 Mar 2021 23:36:29 +0800 Subject: [PATCH] Fix Some Bangumi Track Bug (#4726) --- .../tachiyomi/data/track/bangumi/Bangumi.kt | 7 +++--- .../data/track/bangumi/BangumiApi.kt | 23 +++++++++++++++---- .../data/track/bangumi/Collection.kt | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt index 72ce189ed6..7b51d178d0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt @@ -45,8 +45,10 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) { return if (remoteTrack != null && statusTrack != null) { track.copyPersonalFrom(remoteTrack) track.library_id = remoteTrack.library_id - track.status = remoteTrack.status - track.last_chapter_read = remoteTrack.last_chapter_read + track.status = statusTrack.status + track.score = statusTrack.score + track.last_chapter_read = statusTrack.last_chapter_read + track.total_chapters = remoteTrack.total_chapters refresh(track) } else { // Set default fields if it's not found in the list @@ -66,7 +68,6 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) { track.copyPersonalFrom(remoteStatusTrack!!) api.findLibManga(track)?.let { remoteTrack -> track.total_chapters = remoteTrack.total_chapters - track.status = remoteTrack.status } return track } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt index ecf45fdfcd..3c958936df 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt @@ -47,6 +47,7 @@ class BangumiApi(private val client: OkHttpClient, interceptor: BangumiIntercept return withIOContext { // read status update val sbody = FormBody.Builder() + .add("rating", track.score.toInt().toString()) .add("status", track.toBangumiStatus()) .build() authClient.newCall(POST("$apiUrl/collection/${track.media_id}/update", body = sbody)) @@ -98,13 +99,18 @@ class BangumiApi(private val client: OkHttpClient, interceptor: BangumiIntercept // Sometimes JsonNull "" } - + val totalChapters = if (obj["eps_count"] != null) { + obj["eps_count"]!!.jsonPrimitive.int + } else { + 0 + } return TrackSearch.create(TrackManager.BANGUMI).apply { media_id = obj["id"]!!.jsonPrimitive.int title = obj["name_cn"]!!.jsonPrimitive.content cover_url = coverUrl summary = obj["name"]!!.jsonPrimitive.content tracking_url = obj["url"]!!.jsonPrimitive.content + total_chapters = totalChapters } } @@ -127,14 +133,21 @@ class BangumiApi(private val client: OkHttpClient, interceptor: BangumiIntercept .build() // TODO: get user readed chapter here - authClient.newCall(requestUserRead) - .await() - .parseAs() - .let { + var response = authClient.newCall(requestUserRead).await() + var responseBody = response.body?.string().orEmpty() + if (responseBody.isEmpty()) { + throw Exception("Null Response") + } + if (responseBody.contains("\"code\":400")) { + null + } else { + json.decodeFromString(responseBody).let { track.status = it.status?.id!! track.last_chapter_read = it.ep_status!! + track.score = it.rating!! track } + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Collection.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Collection.kt index 68aba86a37..297a012163 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Collection.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Collection.kt @@ -8,7 +8,7 @@ data class Collection( val comment: String? = "", val ep_status: Int? = 0, val lasttouch: Int? = 0, - val rating: Int? = 0, + val rating: Float? = 0f, val status: Status? = Status(), val tag: List? = listOf(), val user: User? = User(),