Update: Extract Author, Screenshot and Donate into a file

This commit is contained in:
machiav3lli
2022-02-20 02:19:06 +01:00
parent b56da3679c
commit 3f490c2487
10 changed files with 175 additions and 95 deletions

View File

@ -1,6 +1,8 @@
package com.looker.droidify.index
import com.looker.droidify.database.entity.Release
import com.looker.droidify.entity.Author
import com.looker.droidify.entity.Donate
import com.looker.droidify.entity.Product
import com.looker.droidify.utility.extension.android.Android
import org.xml.sax.Attributes
@ -36,17 +38,17 @@ class IndexHandler(private val repositoryId: Long, private val callback: Callbac
fun onProduct(product: Product)
}
internal object DonateComparator : Comparator<Product.Donate> {
internal object DonateComparator : Comparator<Donate> {
private val classes = listOf(
Product.Donate.Regular::class,
Product.Donate.Bitcoin::class,
Product.Donate.Litecoin::class,
Product.Donate.Flattr::class,
Product.Donate.Liberapay::class,
Product.Donate.OpenCollective::class
Donate.Regular::class,
Donate.Bitcoin::class,
Donate.Litecoin::class,
Donate.Flattr::class,
Donate.Liberapay::class,
Donate.OpenCollective::class
)
override fun compare(donate1: Product.Donate, donate2: Product.Donate): Int {
override fun compare(donate1: Donate, donate2: Donate): Int {
val index1 = classes.indexOf(donate1::class)
val index2 = classes.indexOf(donate2::class)
return when {
@ -84,7 +86,7 @@ class IndexHandler(private val repositoryId: Long, private val callback: Callbac
val categories = linkedSetOf<String>()
val antiFeatures = linkedSetOf<String>()
val licenses = mutableListOf<String>()
val donates = mutableListOf<Product.Donate>()
val donates = mutableListOf<Donate>()
val releases = mutableListOf<Release>()
fun build(): Product {
@ -97,7 +99,7 @@ class IndexHandler(private val repositoryId: Long, private val callback: Callbac
"",
icon,
"",
Product.Author(authorName, authorEmail, ""),
Author(authorName, authorEmail, ""),
source,
changelog,
web,
@ -318,12 +320,12 @@ class IndexHandler(private val repositoryId: Long, private val callback: Callbac
.filter { it.isNotEmpty() }
"license" -> productBuilder.licenses += content.split(',')
.filter { it.isNotEmpty() }
"donate" -> productBuilder.donates += Product.Donate.Regular(content)
"bitcoin" -> productBuilder.donates += Product.Donate.Bitcoin(content)
"litecoin" -> productBuilder.donates += Product.Donate.Litecoin(content)
"flattr" -> productBuilder.donates += Product.Donate.Flattr(content)
"liberapay" -> productBuilder.donates += Product.Donate.Liberapay(content)
"openCollective" -> productBuilder.donates += Product.Donate.OpenCollective(
"donate" -> productBuilder.donates += Donate.Regular(content)
"bitcoin" -> productBuilder.donates += Donate.Bitcoin(content)
"litecoin" -> productBuilder.donates += Donate.Litecoin(content)
"flattr" -> productBuilder.donates += Donate.Flattr(content)
"liberapay" -> productBuilder.donates += Donate.Liberapay(content)
"openCollective" -> productBuilder.donates += Donate.OpenCollective(
content
)
}

View File

@ -3,7 +3,10 @@ package com.looker.droidify.index
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.core.JsonToken
import com.looker.droidify.database.entity.Release
import com.looker.droidify.entity.Author
import com.looker.droidify.entity.Donate
import com.looker.droidify.entity.Product
import com.looker.droidify.entity.Screenshot
import com.looker.droidify.utility.extension.android.Android
import com.looker.droidify.utility.extension.json.*
import com.looker.droidify.utility.extension.text.nullIfEmpty
@ -123,7 +126,7 @@ object IndexV1Parser {
var categories = emptyList<String>()
var antiFeatures = emptyList<String>()
val licenses = mutableListOf<String>()
val donates = mutableListOf<Product.Donate>()
val donates = mutableListOf<Donate>()
val localizedMap = mutableMapOf<String, Localized>()
forEachKey { it ->
when {
@ -147,11 +150,11 @@ object IndexV1Parser {
it.array("antiFeatures") -> antiFeatures = collectDistinctNotEmptyStrings()
it.string("license") -> licenses += valueAsString.split(',')
.filter { it.isNotEmpty() }
it.string("donate") -> donates += Product.Donate.Regular(valueAsString)
it.string("bitcoin") -> donates += Product.Donate.Bitcoin(valueAsString)
it.string("flattrID") -> donates += Product.Donate.Flattr(valueAsString)
it.string("liberapayID") -> donates += Product.Donate.Liberapay(valueAsString)
it.string("openCollective") -> donates += Product.Donate.OpenCollective(
it.string("donate") -> donates += Donate.Regular(valueAsString)
it.string("bitcoin") -> donates += Donate.Bitcoin(valueAsString)
it.string("flattrID") -> donates += Donate.Flattr(valueAsString)
it.string("liberapayID") -> donates += Donate.Liberapay(valueAsString)
it.string("openCollective") -> donates += Donate.OpenCollective(
valueAsString
)
it.dictionary("localized") -> forEachKey { keyToken ->
@ -206,23 +209,11 @@ object IndexV1Parser {
val screenshots = screenshotPairs
?.let { (key, screenshots) ->
screenshots.phone.asSequence()
.map { Product.Screenshot(key, Product.Screenshot.Type.PHONE, it) } +
.map { Screenshot(key, Screenshot.Type.PHONE, it) } +
screenshots.smallTablet.asSequence()
.map {
Product.Screenshot(
key,
Product.Screenshot.Type.SMALL_TABLET,
it
)
} +
.map { Screenshot(key, Screenshot.Type.SMALL_TABLET, it) } +
screenshots.largeTablet.asSequence()
.map {
Product.Screenshot(
key,
Product.Screenshot.Type.LARGE_TABLET,
it
)
}
.map { Screenshot(key, Screenshot.Type.LARGE_TABLET, it) }
}
.orEmpty().toList()
return Product(
@ -234,7 +225,7 @@ object IndexV1Parser {
whatsNew,
icon,
metadataIcon,
Product.Author(authorName, authorEmail, authorWeb),
Author(authorName, authorEmail, authorWeb),
source,
changelog,
web,