From 619d94bf36bb5d191b01032e23e5b81949b48673 Mon Sep 17 00:00:00 2001 From: len Date: Sun, 9 Apr 2017 13:56:52 +0200 Subject: [PATCH] Kitsu: use new rating system. Fixes #743 --- .../eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt | 11 +++++++++-- .../eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt | 5 +++-- .../kanade/tachiyomi/data/track/kitsu/KitsuModels.kt | 8 ++++---- 3 files changed, 16 insertions(+), 8 deletions(-) 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 d99475cb8d..5195f5fc0b 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 @@ -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 { - 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 { 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 2ddca50b67..18e7f5494f 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 @@ -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 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 8679ccdbb3..6498c995fd 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 @@ -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 }