Migrate to kotlinx.serialization for extensions and update fetching

(cherry picked from commit 7a476abb53a4d3a36cf4f7618af83d984a78536b)

# Conflicts:
#	build.gradle.kts
This commit is contained in:
arkon 2020-10-11 14:53:02 -04:00 committed by Jobobby04
parent 4d64734dec
commit b4cf0e9723
6 changed files with 34 additions and 26 deletions

View File

@ -187,10 +187,12 @@ dependencies {
// REST // REST
final retrofit_version = '2.9.0' final retrofit_version = '2.9.0'
implementation "com.squareup.retrofit2:retrofit:$retrofit_version" implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version" implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation "com.squareup.retrofit2:adapter-rxjava:$retrofit_version" implementation "com.squareup.retrofit2:adapter-rxjava:$retrofit_version"
// JSON // JSON
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0"
implementation 'com.google.code.gson:gson:2.8.6' implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.github.salomonbrys.kotson:kotson:2.5.0' implementation 'com.github.salomonbrys.kotson:kotson:2.5.0'
@ -293,8 +295,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-reflect:$BuildPluginsVersion.KOTLIN" implementation "org.jetbrains.kotlin:kotlin-reflect:$BuildPluginsVersion.KOTLIN"
// SY for mangadex utils // SY for mangadex utils
implementation "org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0-RC" implementation "org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.0.0"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.0.0-RC"
final coroutines_version = '1.3.9' final coroutines_version = '1.3.9'

View File

@ -1,7 +1,8 @@
package eu.kanade.tachiyomi.data.updater.github package eu.kanade.tachiyomi.data.updater.github
import com.google.gson.annotations.SerializedName
import eu.kanade.tachiyomi.data.updater.Release import eu.kanade.tachiyomi.data.updater.Release
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
/** /**
* Release object. * Release object.
@ -11,10 +12,11 @@ import eu.kanade.tachiyomi.data.updater.Release
* @param info log of latest release. * @param info log of latest release.
* @param assets assets of latest release. * @param assets assets of latest release.
*/ */
@Serializable
class GithubRelease( class GithubRelease(
@SerializedName("tag_name") val version: String, @SerialName("tag_name") val version: String,
@SerializedName("body") override val info: String, @SerialName("body") override val info: String,
@SerializedName("assets") private val assets: List<Assets> @SerialName("assets") private val assets: List<Assets>
) : Release { ) : Release {
/** /**
@ -28,5 +30,6 @@ class GithubRelease(
* Assets class containing download url. * Assets class containing download url.
* @param downloadLink download url. * @param downloadLink download url.
*/ */
class Assets(@SerializedName("browser_download_url") val downloadLink: String) @Serializable
class Assets(@SerialName("browser_download_url") val downloadLink: String)
} }

View File

@ -1,8 +1,10 @@
package eu.kanade.tachiyomi.data.updater.github package eu.kanade.tachiyomi.data.updater.github
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.NetworkHelper
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import retrofit2.Retrofit import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET import retrofit2.http.GET
import retrofit2.http.Path import retrofit2.http.Path
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
@ -17,7 +19,7 @@ interface GithubService {
fun create(): GithubService { fun create(): GithubService {
val restAdapter = Retrofit.Builder() val restAdapter = Retrofit.Builder()
.baseUrl("https://api.github.com") .baseUrl("https://api.github.com")
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(Json { ignoreUnknownKeys = true }.asConverterFactory("application/json".toMediaType()))
.client(Injekt.get<NetworkHelper>().client) .client(Injekt.get<NetworkHelper>().client)
.build() .build()

View File

@ -3,8 +3,6 @@ package eu.kanade.tachiyomi.extension.api
import android.content.Context import android.content.Context
import com.github.salomonbrys.kotson.get import com.github.salomonbrys.kotson.get
import com.github.salomonbrys.kotson.int import com.github.salomonbrys.kotson.int
import com.github.salomonbrys.kotson.string
import com.google.gson.JsonArray
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.Extension
import eu.kanade.tachiyomi.extension.model.LoadResult import eu.kanade.tachiyomi.extension.model.LoadResult
@ -12,6 +10,10 @@ import eu.kanade.tachiyomi.extension.util.ExtensionLoader
import exh.source.BlacklistedSources import exh.source.BlacklistedSources
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.int
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.util.Date import java.util.Date
@ -61,18 +63,18 @@ internal class ExtensionGithubApi {
private fun parseResponse(json: JsonArray): List<Extension.Available> { private fun parseResponse(json: JsonArray): List<Extension.Available> {
return json return json
.filter { element -> .filter { element ->
val versionName = element["version"].string val versionName = element.jsonObject["version"]!!.jsonPrimitive.content
val libVersion = versionName.substringBeforeLast('.').toDouble() val libVersion = versionName.substringBeforeLast('.').toDouble()
libVersion >= ExtensionLoader.LIB_VERSION_MIN && libVersion <= ExtensionLoader.LIB_VERSION_MAX libVersion >= ExtensionLoader.LIB_VERSION_MIN && libVersion <= ExtensionLoader.LIB_VERSION_MAX
} }
.map { element -> .map { element ->
val name = element["name"].string.substringAfter("Tachiyomi: ") val name = element.jsonObject["name"]!!.jsonPrimitive.content.substringAfter("Tachiyomi: ")
val pkgName = element["pkg"].string val pkgName = element.jsonObject["pkg"]!!.jsonPrimitive.content
val apkName = element["apk"].string val apkName = element.jsonObject["apk"]!!.jsonPrimitive.content
val versionName = element["version"].string val versionName = element.jsonObject["version"]!!.jsonPrimitive.content
val versionCode = element["code"].int val versionCode = element.jsonObject["code"]!!.jsonPrimitive.int
val lang = element["lang"].string val lang = element.jsonObject["lang"]!!.jsonPrimitive.content
val nsfw = element["nsfw"].int == 1 val nsfw = element.jsonObject["nsfw"]!!.jsonPrimitive.int == 1
val icon = "$REPO_URL_PREFIX/icon/${apkName.replace(".apk", ".png")}" val icon = "$REPO_URL_PREFIX/icon/${apkName.replace(".apk", ".png")}"
Extension.Available(name, pkgName, versionName, versionCode, lang, nsfw, apkName, icon) Extension.Available(name, pkgName, versionName, versionCode, lang, nsfw, apkName, icon)

View File

@ -1,9 +1,11 @@
package eu.kanade.tachiyomi.extension.api package eu.kanade.tachiyomi.extension.api
import com.google.gson.JsonArray import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.NetworkHelper
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import okhttp3.MediaType.Companion.toMediaType
import retrofit2.Retrofit import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET import retrofit2.http.GET
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -29,7 +31,7 @@ interface ExtensionGithubService {
fun create(): ExtensionGithubService { fun create(): ExtensionGithubService {
val adapter = Retrofit.Builder() val adapter = Retrofit.Builder()
.baseUrl(ExtensionGithubApi.BASE_URL) .baseUrl(ExtensionGithubApi.BASE_URL)
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.client(client) .client(client)
.build() .build()

View File

@ -29,13 +29,11 @@ buildscript {
dependencies { dependencies {
classpath("com.github.zellius:android-shortcut-gradle-plugin:0.1.2") classpath("com.github.zellius:android-shortcut-gradle-plugin:0.1.2")
classpath("com.google.gms:google-services:4.3.3") classpath("com.google.gms:google-services:4.3.3")
classpath("com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:8.4.2") classpath("com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:8.3.0")
classpath(kotlin("serialization", version = BuildPluginsVersion.KOTLIN))
// Realm (EH) // Realm (EH)
classpath("io.realm:realm-gradle-plugin:7.0.1") classpath("io.realm:realm-gradle-plugin:7.0.1")
// SY for mangadex utils
classpath("org.jetbrains.kotlin:kotlin-serialization:${BuildPluginsVersion.KOTLIN}")
// Firebase Crashlytics // Firebase Crashlytics
classpath("com.google.firebase:firebase-crashlytics-gradle:2.2.1") classpath("com.google.firebase:firebase-crashlytics-gradle:2.2.1")
} }