This commit is contained in:
machiav3lli 2022-04-06 04:02:29 +02:00
parent f33ccfd247
commit c2e7c3823e
6 changed files with 0 additions and 260 deletions

View File

@ -28,7 +28,6 @@ const val ROW_ANTIFEATURES = "categories"
const val ROW_LICENSES = "categories"
const val ROW_DONATES = "categories"
const val ROW_SCREENSHOTS = "categories"
const val ROW_DATA = "data"
const val ROW_VERSION = "version"
const val ROW_SIGNATURE = "signature"
const val ROW_ID = "_id"

View File

@ -1,62 +0,0 @@
package com.looker.droidify.database
import android.database.ContentObservable
import android.database.ContentObserver
import android.database.Cursor
import android.database.CursorWrapper
class ObservableCursor(
cursor: Cursor,
private val observable: (
register: Boolean,
observer: () -> Unit,
) -> Unit,
) : CursorWrapper(cursor) {
private var registered = false
private val contentObservable = ContentObservable()
private val onChange: () -> Unit = {
contentObservable.dispatchChange(false, null)
}
init {
observable(true, onChange)
registered = true
}
override fun registerContentObserver(observer: ContentObserver) {
super.registerContentObserver(observer)
contentObservable.registerObserver(observer)
}
override fun unregisterContentObserver(observer: ContentObserver) {
super.unregisterContentObserver(observer)
contentObservable.unregisterObserver(observer)
}
@Suppress("DEPRECATION")
override fun requery(): Boolean {
if (!registered) {
observable(true, onChange)
registered = true
}
return super.requery()
}
@Suppress("DEPRECATION")
override fun deactivate() {
super.deactivate()
deactivateOrClose()
}
override fun close() {
super.close()
contentObservable.unregisterAll()
deactivateOrClose()
}
private fun deactivateOrClose() {
observable(false, onChange)
registered = false
}
}

View File

@ -1,94 +0,0 @@
package com.looker.droidify.database
import android.content.Context
import android.database.Cursor
import android.os.CancellationSignal
import android.os.OperationCanceledException
import androidx.loader.content.AsyncTaskLoader
class QueryLoader(context: Context, private val query: (CancellationSignal) -> Cursor?) :
AsyncTaskLoader<Cursor>(context) {
private val observer = ForceLoadContentObserver()
private var cancellationSignal: CancellationSignal? = null
private var cursor: Cursor? = null
override fun loadInBackground(): Cursor? {
val cancellationSignal = synchronized(this) {
if (isLoadInBackgroundCanceled) {
throw OperationCanceledException()
}
val cancellationSignal = CancellationSignal()
this.cancellationSignal = cancellationSignal
cancellationSignal
}
try {
val cursor = query(cancellationSignal)
if (cursor != null) {
try {
cursor.count // Ensure the cursor window is filled
cursor.registerContentObserver(observer)
} catch (e: Exception) {
cursor.close()
throw e
}
}
return cursor
} finally {
synchronized(this) {
this.cancellationSignal = null
}
}
}
override fun cancelLoadInBackground() {
super.cancelLoadInBackground()
synchronized(this) {
cancellationSignal?.cancel()
}
}
override fun deliverResult(data: Cursor?) {
if (isReset) {
data?.close()
} else {
val oldCursor = cursor
cursor = data
if (isStarted) {
super.deliverResult(data)
}
if (oldCursor != data) {
oldCursor.closeIfNeeded()
}
}
}
override fun onStartLoading() {
cursor?.let(this::deliverResult)
if (takeContentChanged() || cursor == null) {
forceLoad()
}
}
override fun onStopLoading() {
cancelLoad()
}
override fun onCanceled(data: Cursor?) {
data.closeIfNeeded()
}
override fun onReset() {
super.onReset()
stopLoading()
cursor.closeIfNeeded()
cursor = null
}
private fun Cursor?.closeIfNeeded() {
if (this != null && !isClosed) {
close()
}
}
}

View File

@ -1,92 +0,0 @@
package com.looker.droidify.entity
import com.looker.droidify.database.entity.Installed
import com.looker.droidify.database.entity.Release
import com.looker.droidify.utility.extension.text.nullIfEmpty
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
@Serializable
data class Product(
var repositoryId: Long,
val packageName: String,
val name: String,
val summary: String,
var 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>,
) {
// 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(installed: Installed?): Boolean {
return installed != null && compatible && versionCode > installed.version_code &&
installed.signature in signatures
}
fun toJSON() = Json.encodeToString(this)
companion object {
fun fromJson(json: String) = Json.decodeFromString<Product>(json)
fun <T> findSuggested(
products: List<T>,
installed: Installed?,
extract: (T) -> Product,
): T? {
return products.maxWithOrNull(compareBy({
extract(it).compatible &&
(installed == null || installed.signature in extract(it).signatures)
}, { extract(it).versionCode }))
}
}
}

View File

@ -14,10 +14,6 @@ fun Cursor.asSequence(): Sequence<Cursor> {
return generateSequence { if (moveToNext()) this else null }
}
fun Cursor.firstOrNull(): Cursor? {
return if (moveToFirst()) this else null
}
fun SQLiteDatabase.execWithResult(sql: String) {
rawQuery(sql, null).use { it.count }
}

View File

@ -23,13 +23,6 @@ object TypefaceExtra {
val light = Typeface.create("sans-serif-light", Typeface.NORMAL)!!
}
val Number.toPx
get() = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
this.toFloat(),
Resources.getSystem().displayMetrics
)
fun Context.getColorFromAttr(@AttrRes attrResId: Int): ColorStateList {
val typedArray = obtainStyledAttributes(intArrayOf(attrResId))
val (colorStateList, resId) = try {