mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 08:09:21 +01:00
Fixed Anilist start/end date not being set when starting to read/completing manga
This commit is contained in:
parent
c06c93a002
commit
c884963672
@ -35,10 +35,14 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
|
|||||||
val variables = jsonObject(
|
val variables = jsonObject(
|
||||||
"mangaId" to track.media_id,
|
"mangaId" to track.media_id,
|
||||||
"progress" to track.last_chapter_read,
|
"progress" to track.last_chapter_read,
|
||||||
"status" to track.toAnilistStatus(),
|
"status" to track.toAnilistStatus()
|
||||||
"startedAt" to createDate(track.started_reading_date),
|
|
||||||
"completedAt" to createDate(track.finished_reading_date)
|
|
||||||
)
|
)
|
||||||
|
createDate(track.started_reading_date)?.let {
|
||||||
|
variables.add("startedAt", it)
|
||||||
|
}
|
||||||
|
createDate(track.finished_reading_date)?.let {
|
||||||
|
variables.add("completedAt", it)
|
||||||
|
}
|
||||||
val payload = jsonObject(
|
val payload = jsonObject(
|
||||||
"query" to addToLibraryQuery(),
|
"query" to addToLibraryQuery(),
|
||||||
"variables" to variables
|
"variables" to variables
|
||||||
@ -65,18 +69,32 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
|
|||||||
"listId" to track.library_id,
|
"listId" to track.library_id,
|
||||||
"progress" to track.last_chapter_read,
|
"progress" to track.last_chapter_read,
|
||||||
"status" to track.toAnilistStatus(),
|
"status" to track.toAnilistStatus(),
|
||||||
"score" to track.score.toInt(),
|
"score" to track.score.toInt()
|
||||||
"startedAt" to createDate(track.started_reading_date),
|
|
||||||
"completedAt" to createDate(track.finished_reading_date)
|
|
||||||
)
|
)
|
||||||
|
createDate(track.started_reading_date)?.let {
|
||||||
|
variables.add("startedAt", it)
|
||||||
|
}
|
||||||
|
createDate(track.finished_reading_date)?.let {
|
||||||
|
variables.add("completedAt", it)
|
||||||
|
}
|
||||||
val payload = jsonObject(
|
val payload = jsonObject(
|
||||||
"query" to updateInLibraryQuery(),
|
"query" to updateInLibraryQuery(),
|
||||||
"variables" to variables
|
"variables" to variables
|
||||||
)
|
)
|
||||||
val body = payload.toString().toRequestBody(jsonMime)
|
val body = payload.toString().toRequestBody(jsonMime)
|
||||||
val request = Request.Builder().url(apiUrl).post(body).build()
|
val request = Request.Builder().url(apiUrl).post(body).build()
|
||||||
val response = authClient.newCall(request).await()
|
val netResponse = authClient.newCall(request).await()
|
||||||
|
val response = responseToJson(netResponse)
|
||||||
|
try {
|
||||||
|
val media = response["data"]["SaveMediaListEntry"].asJsonObject
|
||||||
|
if (track.started_reading_date == 0L) {
|
||||||
|
track.started_reading_date = parseDate(media, "startedAt")
|
||||||
|
}
|
||||||
|
if (track.finished_reading_date == 0L) {
|
||||||
|
track.finished_reading_date = parseDate(media, "completedAt")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
track
|
track
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,12 +235,8 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createDate(dateValue: Long): JsonObject {
|
private fun createDate(dateValue: Long): JsonObject? {
|
||||||
if (dateValue == 0L) return jsonObject(
|
if (dateValue == 0L) return null
|
||||||
"year" to null,
|
|
||||||
"month" to null,
|
|
||||||
"day" to null,
|
|
||||||
)
|
|
||||||
val calendar = Calendar.getInstance()
|
val calendar = Calendar.getInstance()
|
||||||
calendar.timeInMillis = dateValue
|
calendar.timeInMillis = dateValue
|
||||||
return jsonObject(
|
return jsonObject(
|
||||||
@ -285,6 +299,16 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
|
|||||||
|id
|
|id
|
||||||
|status
|
|status
|
||||||
|progress
|
|progress
|
||||||
|
|startedAt {
|
||||||
|
|year
|
||||||
|
|month
|
||||||
|
|day
|
||||||
|
|}
|
||||||
|
|completedAt {
|
||||||
|
|year
|
||||||
|
|month
|
||||||
|
|day
|
||||||
|
|}
|
||||||
|}
|
|}
|
||||||
|}
|
|}
|
||||||
|""".trimMargin()
|
|""".trimMargin()
|
||||||
|
Loading…
Reference in New Issue
Block a user