From f2a9247b68278c1b880a76e49c92a203c2ea5399 Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 24 Dec 2020 17:02:33 -0500 Subject: [PATCH] Remove usage of Gson in Kitsu tracker --- .../eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt | 13 +++++++------ .../tachiyomi/data/track/kitsu/KitsuInterceptor.kt | 10 +++++++--- .../tachiyomi/data/track/kitsu/KitsuModels.kt | 2 +- .../eu/kanade/tachiyomi/data/track/kitsu/OAuth.kt | 3 +++ 4 files changed, 18 insertions(+), 10 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 32c47892e7..5ed662de53 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 @@ -2,12 +2,14 @@ package eu.kanade.tachiyomi.data.track.kitsu import android.content.Context import android.graphics.Color -import com.google.gson.Gson import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.util.lang.runAsObservable +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json import rx.Completable import rx.Observable import uy.kohesive.injekt.injectLazy @@ -28,9 +30,9 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { override val name = "Kitsu" - private val gson: Gson by injectLazy() + private val json: Json by injectLazy() - private val interceptor by lazy { KitsuInterceptor(this, gson) } + private val interceptor by lazy { KitsuInterceptor(this) } private val api by lazy { KitsuApi(client, interceptor) } @@ -124,13 +126,12 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { } fun saveToken(oauth: OAuth?) { - val json = gson.toJson(oauth) - preferences.trackToken(this).set(json) + preferences.trackToken(this).set(json.encodeToString(oauth)) } fun restoreToken(): OAuth? { return try { - gson.fromJson(preferences.trackToken(this).get(), OAuth::class.java) + json.decodeFromString(preferences.trackToken(this).get()) } catch (e: Exception) { null } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuInterceptor.kt index 0e4dc070cb..5f698731b0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuInterceptor.kt @@ -1,10 +1,14 @@ package eu.kanade.tachiyomi.data.track.kitsu -import com.google.gson.Gson +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json import okhttp3.Interceptor import okhttp3.Response +import uy.kohesive.injekt.injectLazy -class KitsuInterceptor(val kitsu: Kitsu, val gson: Gson) : Interceptor { +class KitsuInterceptor(val kitsu: Kitsu) : Interceptor { + + private val json: Json by injectLazy() /** * OAuth object used for authenticated requests. @@ -22,7 +26,7 @@ class KitsuInterceptor(val kitsu: Kitsu, val gson: Gson) : Interceptor { if (currAuth.isExpired()) { val response = chain.proceed(KitsuApi.refreshTokenRequest(refreshToken)) if (response.isSuccessful) { - newAuth(gson.fromJson(response.body!!.string(), OAuth::class.java)) + newAuth(json.decodeFromString(response.body!!.string())) } else { response.close() } 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 91b3b94dfb..a59e6c6beb 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 @@ -50,7 +50,7 @@ class KitsuLibManga(obj: JsonObject, manga: JsonObject) { private val canonicalTitle = manga["attributes"]!!.jsonObject["canonicalTitle"]!!.jsonPrimitive.content private val chapterCount = manga["attributes"]!!.jsonObject["chapterCount"]?.jsonPrimitive?.intOrNull val type = manga["attributes"]!!.jsonObject["mangaType"]?.jsonPrimitive?.contentOrNull.orEmpty() - val original = manga["attributes"]!!.jsonObject["original"]!!.jsonObject["posterImage"]!!.jsonPrimitive.content + 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 libraryId = obj["id"]!!.jsonPrimitive.int diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/OAuth.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/OAuth.kt index a10981c51e..5cd28c4962 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/OAuth.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/OAuth.kt @@ -1,5 +1,8 @@ package eu.kanade.tachiyomi.data.track.kitsu +import kotlinx.serialization.Serializable + +@Serializable data class OAuth( val access_token: String, val token_type: String,