Initial Commit

This commit is contained in:
Mohit
2021-03-07 18:20:35 +05:30
commit e57df974d6
161 changed files with 13284 additions and 0 deletions

View File

@ -0,0 +1,3 @@
package com.looker.droidify.entity
class InstalledItem(val packageName: String, val version: String, val versionCode: Long, val signature: String)

View File

@ -0,0 +1,227 @@
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.utility.extension.json.*
import com.looker.droidify.utility.extension.text.*
data class Product(val repositoryId: Long, val packageName: String, val name: String, val summary: String,
val description: String, val whatsNew: String, val icon: String, val metadataIcon: String, val author: Author,
val source: String, val changelog: String, val web: String, val tracker: String,
val added: Long, val updated: Long, val suggestedVersionCode: Long,
val categories: List<String>, val antiFeatures: List<String>, val licenses: List<String>,
val donates: List<Donate>, val screenshots: List<Screenshot>, val releases: List<Release>) {
data class Author(val name: String, val email: String, val web: String)
sealed class Donate {
data class Regular(val url: String): Donate()
data class Bitcoin(val address: String): Donate()
data class Litecoin(val address: String): Donate()
data class Flattr(val id: String): Donate()
data class Liberapay(val id: String): Donate()
data class OpenCollective(val id: String): Donate()
}
class Screenshot(val locale: String, val type: Type, val path: String) {
enum class Type(val jsonName: String) {
PHONE("phone"),
SMALL_TABLET("smallTablet"),
LARGE_TABLET("largeTablet")
}
val identifier: String
get() = "$locale.${type.name}.$path"
}
// Same releases with different signatures
val selectedReleases: List<Release>
get() = releases.filter { it.selected }
val displayRelease: Release?
get() = selectedReleases.firstOrNull() ?: releases.firstOrNull()
val version: String
get() = displayRelease?.version.orEmpty()
val versionCode: Long
get() = selectedReleases.firstOrNull()?.versionCode ?: 0L
val compatible: Boolean
get() = selectedReleases.firstOrNull()?.incompatibilities?.isEmpty() == true
val signatures: List<String>
get() = selectedReleases.mapNotNull { it.signature.nullIfEmpty() }.distinct().toList()
fun item(): ProductItem {
return ProductItem(repositoryId, packageName, name, summary, icon, metadataIcon, version, "", compatible, false, 0)
}
fun canUpdate(installedItem: InstalledItem?): Boolean {
return installedItem != null && compatible && versionCode > installedItem.versionCode &&
installedItem.signature in signatures
}
fun serialize(generator: JsonGenerator) {
generator.writeNumberField("serialVersion", 1)
generator.writeStringField("packageName", packageName)
generator.writeStringField("name", name)
generator.writeStringField("summary", summary)
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 {
writeStringField("locale", it.locale)
writeStringField("type", it.type.jsonName)
writeStringField("path", it.path)
}
}
}
generator.writeArray("releases") { releases.forEach { writeDictionary { it.serialize(this) } } }
}
companion object {
fun <T> findSuggested(products: List<T>, installedItem: InstalledItem?, extract: (T) -> Product): T? {
return products.maxWith(compareBy({ extract(it).compatible &&
(installedItem == null || installedItem.signature in extract(it).signatures) }, { extract(it).versionCode }))
}
fun deserialize(repositoryId: Long, description: String, parser: JsonParser): Product {
var packageName = ""
var name = ""
var summary = ""
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 {
when {
it.string("packageName") -> packageName = valueAsString
it.string("name") -> name = valueAsString
it.string("summary") -> summary = 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) {
var type = ""
var url = ""
var address = ""
var id = ""
forEachKey {
when {
it.string("type") -> type = valueAsString
it.string("url") -> url = valueAsString
it.string("address") -> address = valueAsString
it.string("id") -> id = valueAsString
else -> skipChildren()
}
}
when (type) {
"" -> Donate.Regular(url)
"bitcoin" -> Donate.Bitcoin(address)
"litecoin" -> Donate.Litecoin(address)
"flattr" -> Donate.Flattr(id)
"liberapay" -> Donate.Liberapay(id)
"openCollective" -> Donate.OpenCollective(id)
else -> null
}
}
it.array("screenshots") -> screenshots = collectNotNull(JsonToken.START_OBJECT) {
var locale = ""
var type = ""
var path = ""
forEachKey {
when {
it.string("locale") -> locale = valueAsString
it.string("type") -> type = valueAsString
it.string("path") -> path = valueAsString
else -> skipChildren()
}
}
Screenshot.Type.values().find { it.jsonName == type }?.let { Screenshot(locale, it, path) }
}
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)
}
}
}

View File

@ -0,0 +1,79 @@
package com.looker.droidify.entity
import android.os.Parcel
import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.core.JsonParser
import com.looker.droidify.R
import com.looker.droidify.utility.KParcelable
import com.looker.droidify.utility.extension.json.*
data class ProductItem(val repositoryId: Long, val packageName: String, val name: String, val summary: String,
val icon: String, val metadataIcon: String, val version: String, val installedVersion: String,
val compatible: Boolean, val canUpdate: Boolean, val matchRank: Int) {
sealed class Section: KParcelable {
object All: Section() {
@Suppress("unused") @JvmField val CREATOR = KParcelable.creator { All }
}
data class Category(val name: String): Section() {
override fun writeToParcel(dest: Parcel, flags: Int) {
dest.writeString(name)
}
companion object {
@Suppress("unused") @JvmField val CREATOR = KParcelable.creator {
val name = it.readString()!!
Category(name)
}
}
}
data class Repository(val id: Long, val name: String): Section() {
override fun writeToParcel(dest: Parcel, flags: Int) {
dest.writeLong(id)
dest.writeString(name)
}
companion object {
@Suppress("unused") @JvmField val CREATOR = KParcelable.creator {
val id = it.readLong()
val name = it.readString()!!
Repository(id, name)
}
}
}
}
enum class Order(val titleResId: Int) {
NAME(R.string.name),
DATE_ADDED(R.string.date_added),
LAST_UPDATE(R.string.last_update)
}
fun serialize(generator: JsonGenerator) {
generator.writeNumberField("serialVersion", 1)
generator.writeStringField("icon", icon)
generator.writeStringField("metadataIcon", metadataIcon)
generator.writeStringField("version", version)
}
companion object {
fun deserialize(repositoryId: Long, packageName: String, name: String, summary: String,
installedVersion: String, compatible: Boolean, canUpdate: Boolean, matchRank: Int,
parser: JsonParser): ProductItem {
var icon = ""
var metadataIcon = ""
var version = ""
parser.forEachKey {
when {
it.string("icon") -> icon = valueAsString
it.string("metadataIcon") -> metadataIcon = valueAsString
it.string("version") -> version = valueAsString
else -> skipChildren()
}
}
return ProductItem(repositoryId, packageName, name, summary, icon, metadataIcon,
version, installedVersion, compatible, canUpdate, matchRank)
}
}
}

View File

@ -0,0 +1,31 @@
package com.looker.droidify.entity
import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.core.JsonParser
import com.looker.droidify.utility.extension.json.*
data class ProductPreference(val ignoreUpdates: Boolean, val ignoreVersionCode: Long) {
fun shouldIgnoreUpdate(versionCode: Long): Boolean {
return ignoreUpdates || ignoreVersionCode == versionCode
}
fun serialize(generator: JsonGenerator) {
generator.writeBooleanField("ignoreUpdates", ignoreUpdates)
generator.writeNumberField("ignoreVersionCode", ignoreVersionCode)
}
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)
}
}
}

View File

@ -0,0 +1,156 @@
package com.looker.droidify.entity
import android.net.Uri
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.*
data class Release(val selected: Boolean, val version: String, val versionCode: Long,
val added: Long, val size: Long, val minSdkVersion: Int, val targetSdkVersion: Int, val maxSdkVersion: Int,
val source: String, val release: String, val hash: String, val hashType: String, val signature: String,
val obbMain: String, val obbMainHash: String, val obbMainHashType: String,
val obbPatch: String, val obbPatchHash: String, val obbPatchHashType: String,
val permissions: List<String>, val features: List<String>, val platforms: List<String>,
val incompatibilities: List<Incompatibility>) {
sealed class Incompatibility {
object MinSdk: Incompatibility()
object MaxSdk: Incompatibility()
object Platform: Incompatibility()
data class Feature(val feature: String): Incompatibility()
}
val identifier: String
get() = "$versionCode.$hash"
fun getDownloadUrl(repository: Repository): String {
return Uri.parse(repository.address).buildUpon().appendPath(release).build().toString()
}
val cacheFileName: String
get() = "${hash.replace('/', '-')}.apk"
fun serialize(generator: JsonGenerator) {
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 {
writeDictionary {
when (it) {
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", it.feature)
}
}::class
}
}
}
}
companion object {
fun deserialize(parser: JsonParser): Release {
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 {
when {
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 = 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
}
}
else -> skipChildren()
}
}
return Release(selected, version, versionCode, added, size,
minSdkVersion, targetSdkVersion, maxSdkVersion, source, release, hash, hashType, signature,
obbMain, obbMainHash, obbMainHashType, obbPatch, obbPatchHash, obbPatchHashType,
permissions, features, platforms, incompatibilities)
}
}
}

View File

@ -0,0 +1,124 @@
package com.looker.droidify.entity
import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.core.JsonParser
import com.looker.droidify.utility.extension.json.*
import java.net.URL
data class Repository(val id: Long, val address: String, val mirrors: List<String>,
val name: String, val description: String, val version: Int, val enabled: Boolean,
val fingerprint: String, val lastModified: String, val entityTag: String,
val updated: Long, val timestamp: Long, val authentication: String) {
fun edit(address: String, fingerprint: String, authentication: String): Repository {
val addressChanged = this.address != address
val fingerprintChanged = this.fingerprint != fingerprint
val changed = addressChanged || fingerprintChanged
return copy(address = address, fingerprint = fingerprint, lastModified = if (changed) "" else lastModified,
entityTag = if (changed) "" else entityTag, authentication = authentication)
}
fun update(mirrors: List<String>, name: String, description: String, version: Int,
lastModified: String, entityTag: String, timestamp: Long): Repository {
return copy(mirrors = mirrors, name = name, description = description,
version = if (version >= 0) version else this.version, lastModified = lastModified,
entityTag = entityTag, updated = System.currentTimeMillis(), timestamp = timestamp)
}
fun enable(enabled: Boolean): Repository {
return copy(enabled = enabled, lastModified = "", entityTag = "")
}
fun serialize(generator: JsonGenerator) {
generator.writeNumberField("serialVersion", 1)
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)
}
companion object {
fun deserialize(id: Long, parser: JsonParser): Repository {
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("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 newRepository(address: String, fingerprint: String, authentication: String): Repository {
val name = try {
URL(address).let { "${it.host}${it.path}" }
} catch (e: Exception) {
address
}
return defaultRepository(address, name, "", 0, true, fingerprint, authentication)
}
private fun defaultRepository(address: String, name: String, description: String,
version: Int, enabled: Boolean, fingerprint: String, authentication: String): Repository {
return Repository(-1, address, emptyList(), name, description, version, enabled,
fingerprint, "", "", 0L, 0L, authentication)
}
val defaultRepositories = listOf(run {
defaultRepository("https://f-droid.org/repo", "F-Droid", "The official F-Droid Free Software repository. " +
"Everything in this repository is always built from the source code.",
21, true, "43238D512C1E5EB2D6569F4A3AFBF5523418B82E0A3ED1552770ABB9A9C9CCAB", "")
}, run {
defaultRepository("https://f-droid.org/archive", "F-Droid Archive", "The archive of the official F-Droid Free " +
"Software repository. Apps here are old and can contain known vulnerabilities and security issues!",
21, false, "43238D512C1E5EB2D6569F4A3AFBF5523418B82E0A3ED1552770ABB9A9C9CCAB", "")
}, run {
defaultRepository("https://guardianproject.info/fdroid/repo", "Guardian Project Official Releases", "The " +
"official repository of The Guardian Project apps for use with the F-Droid client. Applications in this " +
"repository are official binaries built by the original application developers and signed by the same key as " +
"the APKs that are released in the Google Play Store.",
21, false, "B7C2EEFD8DAC7806AF67DFCD92EB18126BC08312A7F2D6F3862E46013C7A6135", "")
}, run {
defaultRepository("https://guardianproject.info/fdroid/archive", "Guardian Project Archive", "The official " +
"repository of The Guardian Project apps for use with the F-Droid client. This contains older versions of " +
"applications from the main repository.", 21, false,
"B7C2EEFD8DAC7806AF67DFCD92EB18126BC08312A7F2D6F3862E46013C7A6135", "")
}, run {
defaultRepository("https://apt.izzysoft.de/fdroid/repo", "IzzyOnDroid F-Droid Repo", "This is a " +
"repository of apps to be used with F-Droid the original application developers, taken from the resp. " +
"repositories (mostly GitHub). At this moment I cannot give guarantees on regular updates for all of them, " +
"though most are checked multiple times a week ", 21, true,
"3BF0D6ABFEAE2F401707B6D966BE743BF0EEE49C2561B9BA39073711F628937A", "")
})
}
}