Update: Merge Installed(Item)'s entity and database.entity classes

This commit is contained in:
machiav3lli 2022-02-01 00:19:34 +01:00
parent e2791f3c38
commit d5c1fb9fb6
4 changed files with 13 additions and 34 deletions

View File

@ -280,14 +280,8 @@ interface CategoryDao : BaseDao<Category> {
// TODO make sure that apps that not uninstalled by Droid-ify still get removed // TODO make sure that apps that not uninstalled by Droid-ify still get removed
@Dao @Dao
interface InstalledDao : BaseDao<Installed> { interface InstalledDao : BaseDao<Installed> {
fun put(vararg isntalled: com.looker.droidify.entity.InstalledItem) { fun put(vararg installed: Installed) {
isntalled.forEach { installed.forEach { insertReplace(it) }
insertReplace(Installed(it.packageName).apply {
version = it.version
version_code = it.versionCode
signature = it.signature
})
}
} }
@Query("SELECT * FROM memory_installed WHERE package_name = :packageName") @Query("SELECT * FROM memory_installed WHERE package_name = :packageName")
@ -296,6 +290,9 @@ interface InstalledDao : BaseDao<Installed> {
@Query("SELECT * FROM memory_installed WHERE package_name = :packageName") @Query("SELECT * FROM memory_installed WHERE package_name = :packageName")
fun getObject(packageName: String): Installed? fun getObject(packageName: String): Installed?
@Query("SELECT * FROM memory_installed WHERE package_name = :packageName")
fun getObjectLive(packageName: String): LiveData<Installed?>
@Query("DELETE FROM memory_installed WHERE package_name = :packageName") @Query("DELETE FROM memory_installed WHERE package_name = :packageName")
fun delete(packageName: String) fun delete(packageName: String)
} }

View File

@ -4,11 +4,10 @@ import androidx.room.Entity
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
@Entity(tableName = "memory_installed") @Entity(tableName = "memory_installed")
class Installed(pName: String = "") { data class Installed(
@PrimaryKey @PrimaryKey
var package_name = pName var package_name: String = "",
var version: String = "",
var version = "" var version_code: Long = 0L,
var version_code = 0L var signature: String = ""
var signature = "" )
}

View File

@ -1,9 +0,0 @@
package com.looker.droidify.entity
// Redundant to Room's Installed
class InstalledItem(
val packageName: String,
val version: String,
val versionCode: Long,
val signature: String,
)

View File

@ -18,7 +18,6 @@ import com.looker.droidify.*
import com.looker.droidify.content.Preferences import com.looker.droidify.content.Preferences
import com.looker.droidify.database.entity.Installed import com.looker.droidify.database.entity.Installed
import com.looker.droidify.database.entity.Repository import com.looker.droidify.database.entity.Repository
import com.looker.droidify.entity.InstalledItem
import com.looker.droidify.entity.Product import com.looker.droidify.entity.Product
import com.looker.droidify.entity.ProductItem import com.looker.droidify.entity.ProductItem
import com.looker.droidify.service.Connection import com.looker.droidify.service.Connection
@ -46,9 +45,9 @@ object Utils {
.apply { setTintList(context.getColorFromAttr(tintAttrResId)) } .apply { setTintList(context.getColorFromAttr(tintAttrResId)) }
} }
fun PackageInfo.toInstalledItem(): InstalledItem { fun PackageInfo.toInstalledItem(): Installed {
val signatureString = singleSignature?.let(Utils::calculateHash).orEmpty() val signatureString = singleSignature?.let(Utils::calculateHash).orEmpty()
return InstalledItem(packageName, versionName.orEmpty(), versionCodeCompat, signatureString) return Installed(packageName, versionName.orEmpty(), versionCodeCompat, signatureString)
} }
fun getDefaultApplicationIcons(context: Context): Pair<Drawable, Drawable> { fun getDefaultApplicationIcons(context: Context): Pair<Drawable, Drawable> {
@ -221,13 +220,6 @@ fun Cursor.getRepository(): Repository = getBlob(getColumnIndex(ROW_DATA))
} }
} }
fun Cursor.getInstalledItem(): InstalledItem = InstalledItem(
getString(getColumnIndex(ROW_PACKAGE_NAME)),
getString(getColumnIndex(ROW_VERSION)),
getLong(getColumnIndex(ROW_VERSION_CODE)),
getString(getColumnIndex(ROW_SIGNATURE))
)
fun <T> ByteArray.jsonParse(callback: (JsonParser) -> T): T { fun <T> ByteArray.jsonParse(callback: (JsonParser) -> T): T {
return Json.factory.createParser(this).use { it.parseDictionary(callback) } return Json.factory.createParser(this).use { it.parseDictionary(callback) }
} }