瀏覽代碼

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

Andreas 3 年之前
父節點
當前提交
447ee4bd09

+ 2 - 0
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) }

+ 2 - 0
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))
                     }
                 }
             }

+ 25 - 0
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
+    }
+}

+ 4 - 0
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 = [email protected]
         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