Use data class to parse extensions list
(cherry picked from commit f754b081ce45b9c418986778e24b6a3265ba7735) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt # app/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt
This commit is contained in:
parent
53cfe1c609
commit
3337afcf97
@ -11,11 +11,7 @@ import eu.kanade.tachiyomi.network.await
|
|||||||
import eu.kanade.tachiyomi.network.parseAs
|
import eu.kanade.tachiyomi.network.parseAs
|
||||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||||
import exh.source.BlacklistedSources
|
import exh.source.BlacklistedSources
|
||||||
import kotlinx.serialization.json.JsonArray
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.int
|
|
||||||
import kotlinx.serialization.json.jsonObject
|
|
||||||
import kotlinx.serialization.json.jsonPrimitive
|
|
||||||
import kotlinx.serialization.json.long
|
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
@ -29,17 +25,15 @@ internal class ExtensionGithubApi {
|
|||||||
networkService.client
|
networkService.client
|
||||||
.newCall(GET("${REPO_URL_PREFIX}index.min.json"))
|
.newCall(GET("${REPO_URL_PREFIX}index.min.json"))
|
||||||
.await()
|
.await()
|
||||||
.parseAs<JsonArray>()
|
.parseAs<List<ExtensionJsonObject>>()
|
||||||
.let { parseResponse(it) }
|
.toExtensions()
|
||||||
} /* SY --> */ + preferences.extensionRepos().get().flatMap { repoPath ->
|
} /* SY --> */ + preferences.extensionRepos().get().flatMap { repoPath ->
|
||||||
val url = "$BASE_URL$repoPath/repo/"
|
val url = "$BASE_URL$repoPath/repo/"
|
||||||
networkService.client
|
networkService.client
|
||||||
.newCall(GET("${url}index.min.json"))
|
.newCall(GET("${url}index.min.json"))
|
||||||
.await()
|
.await()
|
||||||
.parseAs<JsonArray>()
|
.parseAs<List<ExtensionJsonObject>>()
|
||||||
.let {
|
.toExtensions(url)
|
||||||
parseResponse(it, url)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// SY <--
|
// SY <--
|
||||||
}
|
}
|
||||||
@ -74,26 +68,26 @@ internal class ExtensionGithubApi {
|
|||||||
return extensionsWithUpdate
|
return extensionsWithUpdate
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseResponse(json: JsonArray /* SY --> */, repoUrl: String = REPO_URL_PREFIX /* SY <-- */): List<Extension.Available> {
|
private fun List<ExtensionJsonObject>.toExtensions(/* SY --> */ repoUrl: String = REPO_URL_PREFIX /* SY <-- */): List<Extension.Available> {
|
||||||
return json
|
return this
|
||||||
.filter { element ->
|
.filter {
|
||||||
val versionName = element.jsonObject["version"]!!.jsonPrimitive.content
|
val libVersion = it.version.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 {
|
||||||
val name = element.jsonObject["name"]!!.jsonPrimitive.content.substringAfter("Tachiyomi: ")
|
Extension.Available(
|
||||||
val pkgName = element.jsonObject["pkg"]!!.jsonPrimitive.content
|
name = it.name.substringAfter("Tachiyomi: "),
|
||||||
val apkName = element.jsonObject["apk"]!!.jsonPrimitive.content
|
pkgName = it.pkg,
|
||||||
val versionName = element.jsonObject["version"]!!.jsonPrimitive.content
|
versionName = it.version,
|
||||||
val versionCode = element.jsonObject["code"]!!.jsonPrimitive.long
|
versionCode = it.code,
|
||||||
val lang = element.jsonObject["lang"]!!.jsonPrimitive.content
|
lang = it.lang,
|
||||||
val nsfw = element.jsonObject["nsfw"]!!.jsonPrimitive.int == 1
|
isNsfw = it.nsfw == 1,
|
||||||
// SY -->
|
apkName = it.apk,
|
||||||
val icon = "$repoUrl/icon/${apkName.replace(".apk", ".png")}"
|
iconUrl = "${/* SY --> */ repoUrl /* SY <-- */}icon/${it.apk.replace(".apk", ".png")}",
|
||||||
// SY <--
|
// SY -->
|
||||||
|
repoUrl = repoUrl
|
||||||
Extension.Available(name, pkgName, versionName, versionCode, lang, nsfw, apkName, icon /* SY --> */, repoUrl /* SY <-- */)
|
// SY <--
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,9 +102,18 @@ internal class ExtensionGithubApi {
|
|||||||
return pkgName in BlacklistedSources.BLACKLISTED_EXTENSIONS && blacklistEnabled
|
return pkgName in BlacklistedSources.BLACKLISTED_EXTENSIONS && blacklistEnabled
|
||||||
}
|
}
|
||||||
// SY <--
|
// SY <--
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val BASE_URL = "https://raw.githubusercontent.com/"
|
|
||||||
const val REPO_URL_PREFIX = "${BASE_URL}tachiyomiorg/tachiyomi-extensions/repo/"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const val BASE_URL = "https://raw.githubusercontent.com/"
|
||||||
|
const val REPO_URL_PREFIX = "${BASE_URL}tachiyomiorg/tachiyomi-extensions/repo/"
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
private data class ExtensionJsonObject(
|
||||||
|
val name: String,
|
||||||
|
val pkg: String,
|
||||||
|
val apk: String,
|
||||||
|
val version: String,
|
||||||
|
val code: Long,
|
||||||
|
val lang: String,
|
||||||
|
val nsfw: Int,
|
||||||
|
)
|
||||||
|
@ -8,7 +8,7 @@ import coil.load
|
|||||||
import eu.davidea.viewholders.FlexibleViewHolder
|
import eu.davidea.viewholders.FlexibleViewHolder
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.databinding.ExtensionCardItemBinding
|
import eu.kanade.tachiyomi.databinding.ExtensionCardItemBinding
|
||||||
import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi
|
import eu.kanade.tachiyomi.extension.api.REPO_URL_PREFIX
|
||||||
import eu.kanade.tachiyomi.extension.model.Extension
|
import eu.kanade.tachiyomi.extension.model.Extension
|
||||||
import eu.kanade.tachiyomi.extension.model.InstallStep
|
import eu.kanade.tachiyomi.extension.model.InstallStep
|
||||||
import eu.kanade.tachiyomi.source.ConfigurableSource
|
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||||
@ -57,12 +57,12 @@ class ExtensionHolder(view: View, val adapter: ExtensionAdapter) :
|
|||||||
private fun String.plusRepo(extension: Extension): String {
|
private fun String.plusRepo(extension: Extension): String {
|
||||||
return if (extension is Extension.Available) {
|
return if (extension is Extension.Available) {
|
||||||
when (extension.repoUrl) {
|
when (extension.repoUrl) {
|
||||||
ExtensionGithubApi.REPO_URL_PREFIX -> this
|
REPO_URL_PREFIX -> this
|
||||||
else -> {
|
else -> {
|
||||||
this + if (this.isEmpty()) {
|
if (isEmpty()) {
|
||||||
""
|
this
|
||||||
} else {
|
} else {
|
||||||
" • "
|
this + " • "
|
||||||
} + itemView.context.getString(R.string.repo_source)
|
} + itemView.context.getString(R.string.repo_source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user