Browse Source

Kitsu: use new rating system. Fixes #743

len 8 years ago
parent
commit
619d94bf36

+ 9 - 2
app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt

@@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.data.track.TrackService
 import rx.Completable
 import rx.Observable
 import uy.kohesive.injekt.injectLazy
+import java.text.DecimalFormat
 
 class Kitsu(private val context: Context, id: Int) : TrackService(id) {
 
@@ -55,11 +56,17 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) {
     }
 
     override fun getScoreList(): List<String> {
-        return IntRange(0, 10).map { (it.toFloat() / 2).toString() }
+        val df = DecimalFormat("0.#")
+        return listOf("0") + IntRange(2, 20).map { df.format(it / 2f) }
+    }
+
+    override fun indexToScore(index: Int): Float {
+        return if (index > 0) (index + 1) / 2f else 0f
     }
 
     override fun displayScore(track: Track): String {
-        return track.toKitsuScore()
+        val df = DecimalFormat("0.#")
+        return df.format(track.score)
     }
 
     override fun add(track: Track): Observable<Track> {

+ 3 - 2
app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt

@@ -1,6 +1,7 @@
 package eu.kanade.tachiyomi.data.track.kitsu
 
 import com.github.salomonbrys.kotson.*
+import com.google.gson.GsonBuilder
 import com.google.gson.JsonObject
 import eu.kanade.tachiyomi.data.database.models.Track
 import eu.kanade.tachiyomi.network.POST
@@ -17,7 +18,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
     private val rest = Retrofit.Builder()
             .baseUrl(baseUrl)
             .client(client.newBuilder().addInterceptor(interceptor).build())
-            .addConverterFactory(GsonConverterFactory.create())
+            .addConverterFactory(GsonConverterFactory.create(GsonBuilder().serializeNulls().create()))
             .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
             .build()
             .create(KitsuApi.Rest::class.java)
@@ -65,7 +66,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
                 "attributes" to jsonObject(
                     "status" to track.toKitsuStatus(),
                     "progress" to track.last_chapter_read,
-                    "rating" to track.toKitsuScore()
+                    "ratingTwenty" to track.toKitsuScore()
                 )
             )
             // @formatter:on

+ 4 - 4
app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt

@@ -23,13 +23,13 @@ open class KitsuManga(obj: JsonObject) {
 class KitsuLibManga(obj: JsonObject, manga: JsonObject) : KitsuManga(manga) {
     val remoteId by obj.byInt("id")
     val status by obj["attributes"].byString
-    val rating = obj["attributes"].obj.get("rating").nullString
+    val ratingTwenty = obj["attributes"].obj.get("ratingTwenty").nullString
     val progress by obj["attributes"].byInt
 
     override fun toTrack() = super.toTrack().apply {
         remote_id = remoteId
         status = toTrackStatus()
-        score = rating?.let { it.toFloat() * 2 } ?: 0f
+        score = ratingTwenty?.let { it.toInt() / 2f } ?: 0f
         last_chapter_read = progress
     }
 
@@ -53,6 +53,6 @@ fun Track.toKitsuStatus() = when (status) {
     else -> throw Exception("Unknown status")
 }
 
-fun Track.toKitsuScore(): String {
-    return if (score > 0) (score / 2).toString() else ""
+fun Track.toKitsuScore(): String? {
+    return if (score > 0) (score * 2).toInt().toString() else null
 }