mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Migrate to kotlinx.serialization for extensions and update fetching
This commit is contained in:
		| @@ -1,7 +1,8 @@ | ||||
| package eu.kanade.tachiyomi.data.updater.github | ||||
|  | ||||
| import com.google.gson.annotations.SerializedName | ||||
| import eu.kanade.tachiyomi.data.updater.Release | ||||
| import kotlinx.serialization.SerialName | ||||
| import kotlinx.serialization.Serializable | ||||
|  | ||||
| /** | ||||
|  * Release object. | ||||
| @@ -11,10 +12,11 @@ import eu.kanade.tachiyomi.data.updater.Release | ||||
|  * @param info log of latest release. | ||||
|  * @param assets assets of latest release. | ||||
|  */ | ||||
| @Serializable | ||||
| class GithubRelease( | ||||
|     @SerializedName("tag_name") val version: String, | ||||
|     @SerializedName("body") override val info: String, | ||||
|     @SerializedName("assets") private val assets: List<Assets> | ||||
|     @SerialName("tag_name") val version: String, | ||||
|     @SerialName("body") override val info: String, | ||||
|     @SerialName("assets") private val assets: List<Assets> | ||||
| ) : Release { | ||||
|  | ||||
|     /** | ||||
| @@ -28,5 +30,6 @@ class GithubRelease( | ||||
|      * Assets class containing 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) | ||||
| } | ||||
|   | ||||
| @@ -1,8 +1,10 @@ | ||||
| package eu.kanade.tachiyomi.data.updater.github | ||||
|  | ||||
| import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||||
| import eu.kanade.tachiyomi.network.NetworkHelper | ||||
| import kotlinx.serialization.json.Json | ||||
| import okhttp3.MediaType.Companion.toMediaType | ||||
| import retrofit2.Retrofit | ||||
| import retrofit2.converter.gson.GsonConverterFactory | ||||
| import retrofit2.http.GET | ||||
| import retrofit2.http.Path | ||||
| import uy.kohesive.injekt.Injekt | ||||
| @@ -17,7 +19,7 @@ interface GithubService { | ||||
|         fun create(): GithubService { | ||||
|             val restAdapter = Retrofit.Builder() | ||||
|                 .baseUrl("https://api.github.com") | ||||
|                 .addConverterFactory(GsonConverterFactory.create()) | ||||
|                 .addConverterFactory(Json { ignoreUnknownKeys = true }.asConverterFactory("application/json".toMediaType())) | ||||
|                 .client(Injekt.get<NetworkHelper>().client) | ||||
|                 .build() | ||||
|  | ||||
|   | ||||
| @@ -3,14 +3,16 @@ package eu.kanade.tachiyomi.extension.api | ||||
| import android.content.Context | ||||
| import com.github.salomonbrys.kotson.get | ||||
| 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.extension.model.Extension | ||||
| import eu.kanade.tachiyomi.extension.model.LoadResult | ||||
| import eu.kanade.tachiyomi.extension.util.ExtensionLoader | ||||
| import kotlinx.coroutines.Dispatchers | ||||
| 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 java.util.Date | ||||
|  | ||||
| @@ -53,18 +55,18 @@ internal class ExtensionGithubApi { | ||||
|     private fun parseResponse(json: JsonArray): List<Extension.Available> { | ||||
|         return json | ||||
|             .filter { element -> | ||||
|                 val versionName = element["version"].string | ||||
|                 val versionName = element.jsonObject["version"]!!.jsonPrimitive.content | ||||
|                 val libVersion = versionName.substringBeforeLast('.').toDouble() | ||||
|                 libVersion >= ExtensionLoader.LIB_VERSION_MIN && libVersion <= ExtensionLoader.LIB_VERSION_MAX | ||||
|             } | ||||
|             .map { element -> | ||||
|                 val name = element["name"].string.substringAfter("Tachiyomi: ") | ||||
|                 val pkgName = element["pkg"].string | ||||
|                 val apkName = element["apk"].string | ||||
|                 val versionName = element["version"].string | ||||
|                 val versionCode = element["code"].int | ||||
|                 val lang = element["lang"].string | ||||
|                 val nsfw = element["nsfw"].int == 1 | ||||
|                 val name = element.jsonObject["name"]!!.jsonPrimitive.content.substringAfter("Tachiyomi: ") | ||||
|                 val pkgName = element.jsonObject["pkg"]!!.jsonPrimitive.content | ||||
|                 val apkName = element.jsonObject["apk"]!!.jsonPrimitive.content | ||||
|                 val versionName = element.jsonObject["version"]!!.jsonPrimitive.content | ||||
|                 val versionCode = element.jsonObject["code"]!!.jsonPrimitive.int | ||||
|                 val lang = element.jsonObject["lang"]!!.jsonPrimitive.content | ||||
|                 val nsfw = element.jsonObject["nsfw"]!!.jsonPrimitive.int == 1 | ||||
|                 val icon = "$REPO_URL_PREFIX/icon/${apkName.replace(".apk", ".png")}" | ||||
|  | ||||
|                 Extension.Available(name, pkgName, versionName, versionCode, lang, nsfw, apkName, icon) | ||||
|   | ||||
| @@ -1,9 +1,11 @@ | ||||
| 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 kotlinx.serialization.json.Json | ||||
| import kotlinx.serialization.json.JsonArray | ||||
| import okhttp3.MediaType.Companion.toMediaType | ||||
| import retrofit2.Retrofit | ||||
| import retrofit2.converter.gson.GsonConverterFactory | ||||
| import retrofit2.http.GET | ||||
| import uy.kohesive.injekt.injectLazy | ||||
|  | ||||
| @@ -29,7 +31,7 @@ interface ExtensionGithubService { | ||||
|         fun create(): ExtensionGithubService { | ||||
|             val adapter = Retrofit.Builder() | ||||
|                 .baseUrl(ExtensionGithubApi.BASE_URL) | ||||
|                 .addConverterFactory(GsonConverterFactory.create()) | ||||
|                 .addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) | ||||
|                 .client(client) | ||||
|                 .build() | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user