mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-24 03:42:15 +00:00
Clean up
This commit is contained in:
parent
1c7d2e3e08
commit
c1a4feb927
@ -2,10 +2,6 @@ package com.looker.droidify.database.entity
|
|||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import com.fasterxml.jackson.core.JsonGenerator
|
|
||||||
import com.fasterxml.jackson.core.JsonParser
|
|
||||||
import com.fasterxml.jackson.core.JsonToken
|
|
||||||
import com.looker.droidify.utility.extension.json.*
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
@ -71,158 +67,9 @@ data class Release(
|
|||||||
val cacheFileName: String
|
val cacheFileName: String
|
||||||
get() = "${hash.replace('/', '-')}.apk"
|
get() = "${hash.replace('/', '-')}.apk"
|
||||||
|
|
||||||
fun serialize(generator: JsonGenerator) {
|
|
||||||
generator.writeStringField("packageName", packageName)
|
|
||||||
generator.writeNumberField("serialVersion", 1)
|
|
||||||
generator.writeBooleanField("selected", selected)
|
|
||||||
generator.writeStringField("version", version)
|
|
||||||
generator.writeNumberField("versionCode", versionCode)
|
|
||||||
generator.writeNumberField("added", added)
|
|
||||||
generator.writeNumberField("size", size)
|
|
||||||
generator.writeNumberField("minSdkVersion", minSdkVersion)
|
|
||||||
generator.writeNumberField("targetSdkVersion", targetSdkVersion)
|
|
||||||
generator.writeNumberField("maxSdkVersion", maxSdkVersion)
|
|
||||||
generator.writeStringField("source", source)
|
|
||||||
generator.writeStringField("release", release)
|
|
||||||
generator.writeStringField("hash", hash)
|
|
||||||
generator.writeStringField("hashType", hashType)
|
|
||||||
generator.writeStringField("signature", signature)
|
|
||||||
generator.writeStringField("obbMain", obbMain)
|
|
||||||
generator.writeStringField("obbMainHash", obbMainHash)
|
|
||||||
generator.writeStringField("obbMainHashType", obbMainHashType)
|
|
||||||
generator.writeStringField("obbPatch", obbPatch)
|
|
||||||
generator.writeStringField("obbPatchHash", obbPatchHash)
|
|
||||||
generator.writeStringField("obbPatchHashType", obbPatchHashType)
|
|
||||||
generator.writeArray("permissions") { permissions.forEach { writeString(it) } }
|
|
||||||
generator.writeArray("features") { features.forEach { writeString(it) } }
|
|
||||||
generator.writeArray("platforms") { platforms.forEach { writeString(it) } }
|
|
||||||
generator.writeArray("incompatibilities") {
|
|
||||||
incompatibilities.forEach { serializeIncompatibility(it) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fun toJSON() = Json.encodeToString(this)
|
fun toJSON() = Json.encodeToString(this)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun deserialize(parser: JsonParser): Release {
|
|
||||||
var packageName = ""
|
|
||||||
var selected = false
|
|
||||||
var version = ""
|
|
||||||
var versionCode = 0L
|
|
||||||
var added = 0L
|
|
||||||
var size = 0L
|
|
||||||
var minSdkVersion = 0
|
|
||||||
var targetSdkVersion = 0
|
|
||||||
var maxSdkVersion = 0
|
|
||||||
var source = ""
|
|
||||||
var release = ""
|
|
||||||
var hash = ""
|
|
||||||
var hashType = ""
|
|
||||||
var signature = ""
|
|
||||||
var obbMain = ""
|
|
||||||
var obbMainHash = ""
|
|
||||||
var obbMainHashType = ""
|
|
||||||
var obbPatch = ""
|
|
||||||
var obbPatchHash = ""
|
|
||||||
var obbPatchHashType = ""
|
|
||||||
var permissions = emptyList<String>()
|
|
||||||
var features = emptyList<String>()
|
|
||||||
var platforms = emptyList<String>()
|
|
||||||
var incompatibilities = emptyList<Incompatibility>()
|
|
||||||
parser.forEachKey { it ->
|
|
||||||
when {
|
|
||||||
it.string("packageName") -> packageName = valueAsString
|
|
||||||
it.boolean("selected") -> selected = valueAsBoolean
|
|
||||||
it.string("version") -> version = valueAsString
|
|
||||||
it.number("versionCode") -> versionCode = valueAsLong
|
|
||||||
it.number("added") -> added = valueAsLong
|
|
||||||
it.number("size") -> size = valueAsLong
|
|
||||||
it.number("minSdkVersion") -> minSdkVersion = valueAsInt
|
|
||||||
it.number("targetSdkVersion") -> targetSdkVersion = valueAsInt
|
|
||||||
it.number("maxSdkVersion") -> maxSdkVersion = valueAsInt
|
|
||||||
it.string("source") -> source = valueAsString
|
|
||||||
it.string("release") -> release = valueAsString
|
|
||||||
it.string("hash") -> hash = valueAsString
|
|
||||||
it.string("hashType") -> hashType = valueAsString
|
|
||||||
it.string("signature") -> signature = valueAsString
|
|
||||||
it.string("obbMain") -> obbMain = valueAsString
|
|
||||||
it.string("obbMainHash") -> obbMainHash = valueAsString
|
|
||||||
it.string("obbMainHashType") -> obbMainHashType = valueAsString
|
|
||||||
it.string("obbPatch") -> obbPatch = valueAsString
|
|
||||||
it.string("obbPatchHash") -> obbPatchHash = valueAsString
|
|
||||||
it.string("obbPatchHashType") -> obbPatchHashType = valueAsString
|
|
||||||
it.array("permissions") -> permissions = collectNotNullStrings()
|
|
||||||
it.array("features") -> features = collectNotNullStrings()
|
|
||||||
it.array("platforms") -> platforms = collectNotNullStrings()
|
|
||||||
it.array("incompatibilities") -> incompatibilities =
|
|
||||||
deserializeIncompatibilities()
|
|
||||||
else -> skipChildren()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Release(
|
|
||||||
packageName,
|
|
||||||
selected,
|
|
||||||
version,
|
|
||||||
versionCode,
|
|
||||||
added,
|
|
||||||
size,
|
|
||||||
minSdkVersion,
|
|
||||||
targetSdkVersion,
|
|
||||||
maxSdkVersion,
|
|
||||||
source,
|
|
||||||
release,
|
|
||||||
hash,
|
|
||||||
hashType,
|
|
||||||
signature,
|
|
||||||
obbMain,
|
|
||||||
obbMainHash,
|
|
||||||
obbMainHashType,
|
|
||||||
obbPatch,
|
|
||||||
obbPatchHash,
|
|
||||||
obbPatchHashType,
|
|
||||||
permissions,
|
|
||||||
features,
|
|
||||||
platforms,
|
|
||||||
incompatibilities
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun JsonParser.deserializeIncompatibilities() = collectNotNull(JsonToken.START_OBJECT) {
|
|
||||||
var type = ""
|
|
||||||
var feature = ""
|
|
||||||
forEachKey {
|
|
||||||
when {
|
|
||||||
it.string("type") -> type = valueAsString
|
|
||||||
it.string("feature") -> feature = valueAsString
|
|
||||||
else -> skipChildren()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
when (type) {
|
|
||||||
"minSdk" -> Incompatibility.MinSdk
|
|
||||||
"maxSdk" -> Incompatibility.MaxSdk
|
|
||||||
"platform" -> Incompatibility.Platform
|
|
||||||
"feature" -> Incompatibility.Feature(feature)
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun JsonGenerator.serializeIncompatibility(incompatibility: Incompatibility) =
|
|
||||||
writeDictionary {
|
|
||||||
when (incompatibility) {
|
|
||||||
is Incompatibility.MinSdk -> {
|
|
||||||
writeStringField("type", "minSdk")
|
|
||||||
}
|
|
||||||
is Incompatibility.MaxSdk -> {
|
|
||||||
writeStringField("type", "maxSdk")
|
|
||||||
}
|
|
||||||
is Incompatibility.Platform -> {
|
|
||||||
writeStringField("type", "platform")
|
|
||||||
}
|
|
||||||
is Incompatibility.Feature -> {
|
|
||||||
writeStringField("type", "feature")
|
|
||||||
writeStringField("feature", incompatibility.feature)
|
|
||||||
}
|
|
||||||
}::class
|
|
||||||
}
|
|
||||||
fun fromJson(json: String) = Json.decodeFromString<Release>(json)
|
fun fromJson(json: String) = Json.decodeFromString<Release>(json)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,6 @@ package com.looker.droidify.database.entity
|
|||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import com.fasterxml.jackson.core.JsonGenerator
|
|
||||||
import com.fasterxml.jackson.core.JsonParser
|
|
||||||
import com.looker.droidify.utility.extension.json.collectNotNullStrings
|
|
||||||
import com.looker.droidify.utility.extension.json.forEachKey
|
|
||||||
import com.looker.droidify.utility.extension.json.writeArray
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
@ -62,62 +57,9 @@ data class Repository(
|
|||||||
this.entityTag = ""
|
this.entityTag = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
fun serialize(generator: JsonGenerator) {
|
|
||||||
generator.writeNumberField("serialVersion", 1)
|
|
||||||
generator.writeNumberField("id", id)
|
|
||||||
generator.writeStringField("address", address)
|
|
||||||
generator.writeArray("mirrors") { mirrors.forEach { writeString(it) } }
|
|
||||||
generator.writeStringField("name", name)
|
|
||||||
generator.writeStringField("description", description)
|
|
||||||
generator.writeNumberField("version", version)
|
|
||||||
generator.writeBooleanField("enabled", enabled)
|
|
||||||
generator.writeStringField("fingerprint", fingerprint)
|
|
||||||
generator.writeStringField("lastModified", lastModified)
|
|
||||||
generator.writeStringField("entityTag", entityTag)
|
|
||||||
generator.writeNumberField("updated", updated)
|
|
||||||
generator.writeNumberField("timestamp", timestamp)
|
|
||||||
generator.writeStringField("authentication", authentication)
|
|
||||||
}
|
|
||||||
fun toJSON() = Json.encodeToString(this)
|
fun toJSON() = Json.encodeToString(this)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun deserialize(parser: JsonParser): Repository {
|
|
||||||
var id = 0L
|
|
||||||
var address = ""
|
|
||||||
var mirrors = emptyList<String>()
|
|
||||||
var name = ""
|
|
||||||
var description = ""
|
|
||||||
var version = 0
|
|
||||||
var enabled = false
|
|
||||||
var fingerprint = ""
|
|
||||||
var lastModified = ""
|
|
||||||
var entityTag = ""
|
|
||||||
var updated = 0L
|
|
||||||
var timestamp = 0L
|
|
||||||
var authentication = ""
|
|
||||||
parser.forEachKey {
|
|
||||||
when {
|
|
||||||
it.string("id") -> id = valueAsLong
|
|
||||||
it.string("address") -> address = valueAsString
|
|
||||||
it.array("mirrors") -> mirrors = collectNotNullStrings()
|
|
||||||
it.string("name") -> name = valueAsString
|
|
||||||
it.string("description") -> description = valueAsString
|
|
||||||
it.number("version") -> version = valueAsInt
|
|
||||||
it.boolean("enabled") -> enabled = valueAsBoolean
|
|
||||||
it.string("fingerprint") -> fingerprint = valueAsString
|
|
||||||
it.string("lastModified") -> lastModified = valueAsString
|
|
||||||
it.string("entityTag") -> entityTag = valueAsString
|
|
||||||
it.number("updated") -> updated = valueAsLong
|
|
||||||
it.number("timestamp") -> timestamp = valueAsLong
|
|
||||||
it.string("authentication") -> authentication = valueAsString
|
|
||||||
else -> skipChildren()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Repository(
|
|
||||||
id, address, mirrors, name, description, version, enabled, fingerprint,
|
|
||||||
lastModified, entityTag, updated, timestamp, authentication
|
|
||||||
)
|
|
||||||
}
|
|
||||||
fun fromJson(json: String) = Json.decodeFromString<Repository>(json)
|
fun fromJson(json: String) = Json.decodeFromString<Repository>(json)
|
||||||
|
|
||||||
fun newRepository(
|
fun newRepository(
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
package com.looker.droidify.entity
|
package com.looker.droidify.entity
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator
|
|
||||||
import com.fasterxml.jackson.core.JsonParser
|
|
||||||
import com.fasterxml.jackson.core.JsonToken
|
|
||||||
import com.looker.droidify.database.entity.Installed
|
import com.looker.droidify.database.entity.Installed
|
||||||
import com.looker.droidify.database.entity.Release
|
import com.looker.droidify.database.entity.Release
|
||||||
import com.looker.droidify.utility.extension.json.*
|
|
||||||
import com.looker.droidify.utility.extension.text.nullIfEmpty
|
import com.looker.droidify.utility.extension.text.nullIfEmpty
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
@ -77,72 +73,6 @@ data class Product(
|
|||||||
installed.signature in signatures
|
installed.signature in signatures
|
||||||
}
|
}
|
||||||
|
|
||||||
fun serialize(generator: JsonGenerator) {
|
|
||||||
generator.writeNumberField("repositoryId", repositoryId)
|
|
||||||
generator.writeNumberField("serialVersion", 1)
|
|
||||||
generator.writeStringField("packageName", packageName)
|
|
||||||
generator.writeStringField("name", name)
|
|
||||||
generator.writeStringField("summary", summary)
|
|
||||||
generator.writeStringField("description", description)
|
|
||||||
generator.writeStringField("whatsNew", whatsNew)
|
|
||||||
generator.writeStringField("icon", icon)
|
|
||||||
generator.writeStringField("metadataIcon", metadataIcon)
|
|
||||||
generator.writeStringField("authorName", author.name)
|
|
||||||
generator.writeStringField("authorEmail", author.email)
|
|
||||||
generator.writeStringField("authorWeb", author.web)
|
|
||||||
generator.writeStringField("source", source)
|
|
||||||
generator.writeStringField("changelog", changelog)
|
|
||||||
generator.writeStringField("web", web)
|
|
||||||
generator.writeStringField("tracker", tracker)
|
|
||||||
generator.writeNumberField("added", added)
|
|
||||||
generator.writeNumberField("updated", updated)
|
|
||||||
generator.writeNumberField("suggestedVersionCode", suggestedVersionCode)
|
|
||||||
generator.writeArray("categories") { categories.forEach(::writeString) }
|
|
||||||
generator.writeArray("antiFeatures") { antiFeatures.forEach(::writeString) }
|
|
||||||
generator.writeArray("licenses") { licenses.forEach(::writeString) }
|
|
||||||
generator.writeArray("donates") {
|
|
||||||
donates.forEach {
|
|
||||||
writeDictionary {
|
|
||||||
when (it) {
|
|
||||||
is Donate.Regular -> {
|
|
||||||
writeStringField("type", "")
|
|
||||||
writeStringField("url", it.url)
|
|
||||||
}
|
|
||||||
is Donate.Bitcoin -> {
|
|
||||||
writeStringField("type", "bitcoin")
|
|
||||||
writeStringField("address", it.address)
|
|
||||||
}
|
|
||||||
is Donate.Litecoin -> {
|
|
||||||
writeStringField("type", "litecoin")
|
|
||||||
writeStringField("address", it.address)
|
|
||||||
}
|
|
||||||
is Donate.Flattr -> {
|
|
||||||
writeStringField("type", "flattr")
|
|
||||||
writeStringField("id", it.id)
|
|
||||||
}
|
|
||||||
is Donate.Liberapay -> {
|
|
||||||
writeStringField("type", "liberapay")
|
|
||||||
writeStringField("id", it.id)
|
|
||||||
}
|
|
||||||
is Donate.OpenCollective -> {
|
|
||||||
writeStringField("type", "openCollective")
|
|
||||||
writeStringField("id", it.id)
|
|
||||||
}
|
|
||||||
}::class
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
generator.writeArray("screenshots") {
|
|
||||||
screenshots.forEach {
|
|
||||||
writeDictionary {
|
|
||||||
it.serialize(
|
|
||||||
this
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
generator.writeArray("releases") { releases.forEach { writeDictionary { it.serialize(this) } } }
|
|
||||||
}
|
|
||||||
fun toJSON() = Json.encodeToString(this)
|
fun toJSON() = Json.encodeToString(this)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@ -158,88 +88,5 @@ data class Product(
|
|||||||
(installed == null || installed.signature in extract(it).signatures)
|
(installed == null || installed.signature in extract(it).signatures)
|
||||||
}, { extract(it).versionCode }))
|
}, { extract(it).versionCode }))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deserialize(parser: JsonParser): Product {
|
|
||||||
var repositoryId = 0L
|
|
||||||
var packageName = ""
|
|
||||||
var name = ""
|
|
||||||
var summary = ""
|
|
||||||
var description = ""
|
|
||||||
var whatsNew = ""
|
|
||||||
var icon = ""
|
|
||||||
var metadataIcon = ""
|
|
||||||
var authorName = ""
|
|
||||||
var authorEmail = ""
|
|
||||||
var authorWeb = ""
|
|
||||||
var source = ""
|
|
||||||
var changelog = ""
|
|
||||||
var web = ""
|
|
||||||
var tracker = ""
|
|
||||||
var added = 0L
|
|
||||||
var updated = 0L
|
|
||||||
var suggestedVersionCode = 0L
|
|
||||||
var categories = emptyList<String>()
|
|
||||||
var antiFeatures = emptyList<String>()
|
|
||||||
var licenses = emptyList<String>()
|
|
||||||
var donates = emptyList<Donate>()
|
|
||||||
var screenshots = emptyList<Screenshot>()
|
|
||||||
var releases = emptyList<Release>()
|
|
||||||
parser.forEachKey { it ->
|
|
||||||
when {
|
|
||||||
it.string("repositoryId") -> repositoryId = valueAsLong
|
|
||||||
it.string("packageName") -> packageName = valueAsString
|
|
||||||
it.string("name") -> name = valueAsString
|
|
||||||
it.string("summary") -> summary = valueAsString
|
|
||||||
it.string("description") -> description = valueAsString
|
|
||||||
it.string("whatsNew") -> whatsNew = valueAsString
|
|
||||||
it.string("icon") -> icon = valueAsString
|
|
||||||
it.string("metadataIcon") -> metadataIcon = valueAsString
|
|
||||||
it.string("authorName") -> authorName = valueAsString
|
|
||||||
it.string("authorEmail") -> authorEmail = valueAsString
|
|
||||||
it.string("authorWeb") -> authorWeb = valueAsString
|
|
||||||
it.string("source") -> source = valueAsString
|
|
||||||
it.string("changelog") -> changelog = valueAsString
|
|
||||||
it.string("web") -> web = valueAsString
|
|
||||||
it.string("tracker") -> tracker = valueAsString
|
|
||||||
it.number("added") -> added = valueAsLong
|
|
||||||
it.number("updated") -> updated = valueAsLong
|
|
||||||
it.number("suggestedVersionCode") -> suggestedVersionCode = valueAsLong
|
|
||||||
it.array("categories") -> categories = collectNotNullStrings()
|
|
||||||
it.array("antiFeatures") -> antiFeatures = collectNotNullStrings()
|
|
||||||
it.array("licenses") -> licenses = collectNotNullStrings()
|
|
||||||
it.array("donates") -> donates =
|
|
||||||
collectNotNull(JsonToken.START_OBJECT, Donate::deserialize)
|
|
||||||
it.array("screenshots") -> screenshots =
|
|
||||||
collectNotNull(JsonToken.START_OBJECT, Screenshot::deserialize)
|
|
||||||
it.array("releases") -> releases =
|
|
||||||
collectNotNull(JsonToken.START_OBJECT, Release.Companion::deserialize)
|
|
||||||
else -> skipChildren()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Product(
|
|
||||||
repositoryId,
|
|
||||||
packageName,
|
|
||||||
name,
|
|
||||||
summary,
|
|
||||||
description,
|
|
||||||
whatsNew,
|
|
||||||
icon,
|
|
||||||
metadataIcon,
|
|
||||||
Author(authorName, authorEmail, authorWeb),
|
|
||||||
source,
|
|
||||||
changelog,
|
|
||||||
web,
|
|
||||||
tracker,
|
|
||||||
added,
|
|
||||||
updated,
|
|
||||||
suggestedVersionCode,
|
|
||||||
categories,
|
|
||||||
antiFeatures,
|
|
||||||
licenses,
|
|
||||||
donates,
|
|
||||||
screenshots,
|
|
||||||
releases
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package com.looker.droidify.entity
|
package com.looker.droidify.entity
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator
|
|
||||||
import com.fasterxml.jackson.core.JsonParser
|
|
||||||
import com.looker.droidify.utility.extension.json.forEachKey
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
@ -14,25 +11,9 @@ data class ProductPreference(val ignoreUpdates: Boolean, val ignoreVersionCode:
|
|||||||
return ignoreUpdates || ignoreVersionCode == versionCode
|
return ignoreUpdates || ignoreVersionCode == versionCode
|
||||||
}
|
}
|
||||||
|
|
||||||
fun serialize(generator: JsonGenerator) {
|
|
||||||
generator.writeBooleanField("ignoreUpdates", ignoreUpdates)
|
|
||||||
generator.writeNumberField("ignoreVersionCode", ignoreVersionCode)
|
|
||||||
}
|
|
||||||
fun toJSON() = Json.encodeToString(this)
|
fun toJSON() = Json.encodeToString(this)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun deserialize(parser: JsonParser): ProductPreference {
|
|
||||||
var ignoreUpdates = false
|
|
||||||
var ignoreVersionCode = 0L
|
|
||||||
parser.forEachKey {
|
|
||||||
when {
|
|
||||||
it.boolean("ignoreUpdates") -> ignoreUpdates = valueAsBoolean
|
|
||||||
it.number("ignoreVersionCode") -> ignoreVersionCode = valueAsLong
|
|
||||||
else -> skipChildren()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ProductPreference(ignoreUpdates, ignoreVersionCode)
|
|
||||||
}
|
|
||||||
fun fromJson(json: String) = Json.decodeFromString<ProductPreference>(json)
|
fun fromJson(json: String) = Json.decodeFromString<ProductPreference>(json)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ import android.content.pm.PackageInfo
|
|||||||
import android.content.pm.Signature
|
import android.content.pm.Signature
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import com.fasterxml.jackson.core.JsonGenerator
|
|
||||||
import com.fasterxml.jackson.core.JsonParser
|
|
||||||
import com.looker.droidify.BuildConfig
|
import com.looker.droidify.BuildConfig
|
||||||
import com.looker.droidify.PREFS_LANGUAGE_DEFAULT
|
import com.looker.droidify.PREFS_LANGUAGE_DEFAULT
|
||||||
import com.looker.droidify.R
|
import com.looker.droidify.R
|
||||||
@ -22,14 +20,10 @@ import com.looker.droidify.service.DownloadService
|
|||||||
import com.looker.droidify.utility.extension.android.Android
|
import com.looker.droidify.utility.extension.android.Android
|
||||||
import com.looker.droidify.utility.extension.android.singleSignature
|
import com.looker.droidify.utility.extension.android.singleSignature
|
||||||
import com.looker.droidify.utility.extension.android.versionCodeCompat
|
import com.looker.droidify.utility.extension.android.versionCodeCompat
|
||||||
import com.looker.droidify.utility.extension.json.Json
|
|
||||||
import com.looker.droidify.utility.extension.json.parseDictionary
|
|
||||||
import com.looker.droidify.utility.extension.json.writeDictionary
|
|
||||||
import com.looker.droidify.utility.extension.resources.getDrawableCompat
|
import com.looker.droidify.utility.extension.resources.getDrawableCompat
|
||||||
import com.looker.droidify.utility.extension.text.hex
|
import com.looker.droidify.utility.extension.text.hex
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import java.io.ByteArrayOutputStream
|
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import java.security.cert.Certificate
|
import java.security.cert.Certificate
|
||||||
import java.security.cert.CertificateEncodingException
|
import java.security.cert.CertificateEncodingException
|
||||||
@ -175,16 +169,6 @@ object Utils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> ByteArray.jsonParse(callback: (JsonParser) -> T): T {
|
|
||||||
return Json.factory.createParser(this).use { it.parseDictionary(callback) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun jsonGenerate(callback: (JsonGenerator) -> Unit): ByteArray {
|
|
||||||
val outputStream = ByteArrayOutputStream()
|
|
||||||
Json.factory.createGenerator(outputStream).use { it.writeDictionary(callback) }
|
|
||||||
return outputStream.toByteArray()
|
|
||||||
}
|
|
||||||
|
|
||||||
val isDarkTheme: Boolean
|
val isDarkTheme: Boolean
|
||||||
get() = when (Preferences[Preferences.Key.Theme]) {
|
get() = when (Preferences[Preferences.Key.Theme]) {
|
||||||
is Preferences.Theme.Light -> false
|
is Preferences.Theme.Light -> false
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
package com.looker.droidify.utility.extension.json
|
package com.looker.droidify.utility.extension.json
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.*
|
import com.fasterxml.jackson.core.JsonFactory
|
||||||
|
import com.fasterxml.jackson.core.JsonParseException
|
||||||
|
import com.fasterxml.jackson.core.JsonParser
|
||||||
|
import com.fasterxml.jackson.core.JsonToken
|
||||||
|
|
||||||
object Json {
|
object Json {
|
||||||
val factory = JsonFactory()
|
val factory = JsonFactory()
|
||||||
@ -80,49 +83,3 @@ fun JsonParser.collectNotNullStrings(): List<String> {
|
|||||||
fun JsonParser.collectDistinctNotEmptyStrings(): List<String> {
|
fun JsonParser.collectDistinctNotEmptyStrings(): List<String> {
|
||||||
return collectNotNullStrings().asSequence().filter { it.isNotEmpty() }.distinct().toList()
|
return collectNotNullStrings().asSequence().filter { it.isNotEmpty() }.distinct().toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> JsonParser.collectList(arrayName: String, callback: JsonParser.() -> T?): MutableList<T> {
|
|
||||||
val list = mutableListOf<T>()
|
|
||||||
forEachKey {
|
|
||||||
when {
|
|
||||||
it.array(arrayName) ->
|
|
||||||
list.addAll(
|
|
||||||
collectNotNull(JsonToken.START_OBJECT) {
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
else -> skipChildren()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun <T> JsonParser.parseDictionary(callback: JsonParser.() -> T): T {
|
|
||||||
if (nextToken() == JsonToken.START_OBJECT) {
|
|
||||||
val result = callback()
|
|
||||||
if (nextToken() != null) {
|
|
||||||
illegal()
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
} else {
|
|
||||||
illegal()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun JsonGenerator.writeDictionary(callback: JsonGenerator.() -> Unit) {
|
|
||||||
writeStartObject()
|
|
||||||
callback()
|
|
||||||
writeEndObject()
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun JsonGenerator.writeArray(fieldName: String, callback: JsonGenerator.() -> Unit) {
|
|
||||||
writeArrayFieldStart(fieldName)
|
|
||||||
callback()
|
|
||||||
writeEndArray()
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun <T> JsonGenerator.writeList(listName: String, list: List<T>, callback: T.() -> Unit) {
|
|
||||||
writeArray(listName) {
|
|
||||||
list.forEach { writeDictionary { it.callback() } }
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user