Add support for start/end fields for Kitsu (#5573)

This commit is contained in:
Andreas 2021-07-18 18:47:40 +02:00 committed by GitHub
parent 3cd6382795
commit 447ee4bd09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 0 deletions

View File

@ -26,6 +26,8 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) {
@StringRes @StringRes
override fun nameRes() = R.string.tracker_kitsu override fun nameRes() = R.string.tracker_kitsu
override val supportsReadingDates: Boolean = true
private val json: Json by injectLazy() private val json: Json by injectLazy()
private val interceptor by lazy { KitsuInterceptor(this) } private val interceptor by lazy { KitsuInterceptor(this) }

View File

@ -84,6 +84,8 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
put("status", track.toKitsuStatus()) put("status", track.toKitsuStatus())
put("progress", track.last_chapter_read) put("progress", track.last_chapter_read)
put("ratingTwenty", track.toKitsuScore()) put("ratingTwenty", track.toKitsuScore())
put("startedAt", KitsuDateHelper.convert(track.started_reading_date))
put("finishedAt", KitsuDateHelper.convert(track.finished_reading_date))
} }
} }
} }

View File

@ -0,0 +1,25 @@
package eu.kanade.tachiyomi.data.track.kitsu
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
object KitsuDateHelper {
private const val pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
private val formatter = SimpleDateFormat(pattern, Locale.ENGLISH)
fun convert(dateValue: Long): String? {
if (dateValue == 0L) return null
return formatter.format(Date(dateValue))
}
fun parse(dateString: String?): Long {
if (dateString == null) return 0L
val dateValue = formatter.parse(dateString)
return dateValue?.time ?: return 0
}
}

View File

@ -58,6 +58,8 @@ class KitsuLibManga(obj: JsonObject, manga: JsonObject) {
val original = manga["attributes"]!!.jsonObject["posterImage"]!!.jsonObject["original"]!!.jsonPrimitive.content val original = manga["attributes"]!!.jsonObject["posterImage"]!!.jsonObject["original"]!!.jsonPrimitive.content
private val synopsis = manga["attributes"]!!.jsonObject["synopsis"]!!.jsonPrimitive.content private val synopsis = manga["attributes"]!!.jsonObject["synopsis"]!!.jsonPrimitive.content
private val startDate = manga["attributes"]!!.jsonObject["startDate"]?.jsonPrimitive?.contentOrNull.orEmpty() private val startDate = manga["attributes"]!!.jsonObject["startDate"]?.jsonPrimitive?.contentOrNull.orEmpty()
private val startedAt = obj["attributes"]!!.jsonObject["startedAt"]?.jsonPrimitive?.contentOrNull
private val finishedAt = obj["attributes"]!!.jsonObject["finishedAt"]?.jsonPrimitive?.contentOrNull
private val libraryId = obj["id"]!!.jsonPrimitive.int private val libraryId = obj["id"]!!.jsonPrimitive.int
val status = obj["attributes"]!!.jsonObject["status"]!!.jsonPrimitive.content val status = obj["attributes"]!!.jsonObject["status"]!!.jsonPrimitive.content
private val ratingTwenty = obj["attributes"]!!.jsonObject["ratingTwenty"]?.jsonPrimitive?.contentOrNull private val ratingTwenty = obj["attributes"]!!.jsonObject["ratingTwenty"]?.jsonPrimitive?.contentOrNull
@ -73,6 +75,8 @@ class KitsuLibManga(obj: JsonObject, manga: JsonObject) {
publishing_status = this@KitsuLibManga.status publishing_status = this@KitsuLibManga.status
publishing_type = type publishing_type = type
start_date = startDate start_date = startDate
started_reading_date = KitsuDateHelper.parse(startedAt)
finished_reading_date = KitsuDateHelper.parse(finishedAt)
status = toTrackStatus() status = toTrackStatus()
score = ratingTwenty?.let { it.toInt() / 2f } ?: 0f score = ratingTwenty?.let { it.toInt() / 2f } ?: 0f
last_chapter_read = progress last_chapter_read = progress