From 447ee4bd09b7e8a2e9cafa5149d825f36f4058aa Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 18 Jul 2021 18:47:40 +0200 Subject: [PATCH] Add support for start/end fields for Kitsu (#5573) --- .../tachiyomi/data/track/kitsu/Kitsu.kt | 2 ++ .../tachiyomi/data/track/kitsu/KitsuApi.kt | 2 ++ .../data/track/kitsu/KitsuDateHelper.kt | 25 +++++++++++++++++++ .../tachiyomi/data/track/kitsu/KitsuModels.kt | 4 +++ 4 files changed, 33 insertions(+) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuDateHelper.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt index c2b385a70e..2336818307 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt @@ -26,6 +26,8 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { @StringRes override fun nameRes() = R.string.tracker_kitsu + override val supportsReadingDates: Boolean = true + private val json: Json by injectLazy() private val interceptor by lazy { KitsuInterceptor(this) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt index 3dde8aa286..71c655798b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt @@ -84,6 +84,8 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) put("status", track.toKitsuStatus()) put("progress", track.last_chapter_read) put("ratingTwenty", track.toKitsuScore()) + put("startedAt", KitsuDateHelper.convert(track.started_reading_date)) + put("finishedAt", KitsuDateHelper.convert(track.finished_reading_date)) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuDateHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuDateHelper.kt new file mode 100644 index 0000000000..6828e1e1a9 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuDateHelper.kt @@ -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 + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt index 7e2c467d99..d5ec925414 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt @@ -58,6 +58,8 @@ class KitsuLibManga(obj: JsonObject, manga: JsonObject) { val original = manga["attributes"]!!.jsonObject["posterImage"]!!.jsonObject["original"]!!.jsonPrimitive.content private val synopsis = manga["attributes"]!!.jsonObject["synopsis"]!!.jsonPrimitive.content 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 val status = obj["attributes"]!!.jsonObject["status"]!!.jsonPrimitive.content 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_type = type start_date = startDate + started_reading_date = KitsuDateHelper.parse(startedAt) + finished_reading_date = KitsuDateHelper.parse(finishedAt) status = toTrackStatus() score = ratingTwenty?.let { it.toInt() / 2f } ?: 0f last_chapter_read = progress