mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 11:22:12 +00:00
Update: Replace entities hard strings with constants
This commit is contained in:
parent
92035ba7da
commit
d2c0a997d2
@ -10,9 +10,23 @@ const val NOTIFICATION_ID_UPDATES = 2
|
||||
const val NOTIFICATION_ID_DOWNLOADING = 3
|
||||
const val NOTIFICATION_ID_INSTALLER = 4
|
||||
|
||||
const val TABLE_CATEGORY = "category"
|
||||
const val TABLE_CATEGORY_NAME = "category"
|
||||
const val TABLE_CATEGORY_TEMP_NAME = "temporary_category"
|
||||
const val TABLE_INSTALLED = "installed"
|
||||
const val TABLE_INSTALLED_NAME = "memory_installed"
|
||||
const val TABLE_LOCK = "lock"
|
||||
const val TABLE_LOCK_NAME = "memory_lock"
|
||||
const val TABLE_PRODUCT = "product"
|
||||
const val TABLE_PRODUCT_NAME = "product"
|
||||
const val TABLE_PRODUCT_TEMP_NAME = "temporary_product"
|
||||
const val TABLE_RELEASE = "release"
|
||||
const val TABLE_RELEASE_NAME = "release"
|
||||
const val TABLE_REPOSITORY = "repository"
|
||||
const val TABLE_REPOSITORY_NAME = "repository"
|
||||
|
||||
const val ROW_REPOSITORY_ID = "repositoryId"
|
||||
const val ROW_PACKAGE_NAME = "packageName"
|
||||
const val ROW_NAME = "name"
|
||||
const val ROW_LABEL = "label"
|
||||
const val ROW_SUMMARY = "summary"
|
||||
const val ROW_DESCRIPTION = "description"
|
||||
@ -33,14 +47,8 @@ const val ROW_VERSION = "version"
|
||||
const val ROW_SIGNATURE = "signature"
|
||||
const val ROW_ID = "_id"
|
||||
const val ROW_ENABLED = "enabled"
|
||||
const val ROW_DELETED = "deleted"
|
||||
const val ROW_CAN_UPDATE = "can_update"
|
||||
const val ROW_MATCH_RANK = "match_rank"
|
||||
const val ROW_REPOSITORY_NAME = "repository"
|
||||
const val ROW_PRODUCT_NAME = "product"
|
||||
const val ROW_CATEGORY_NAME = "category"
|
||||
const val ROW_INSTALLED_NAME = "memory_installed"
|
||||
const val ROW_LOCK_NAME = "memory_lock"
|
||||
|
||||
const val JOB_ID_SYNC = 1
|
||||
|
||||
|
@ -135,65 +135,65 @@ interface ProductDao : BaseDao<Product> {
|
||||
): SupportSQLiteQuery {
|
||||
val builder = QueryBuilder()
|
||||
|
||||
val signatureMatches = """installed.${ROW_SIGNATURE} IS NOT NULL AND
|
||||
product.${ROW_SIGNATURES} LIKE ('%.' || installed.${ROW_SIGNATURE} || '.%') AND
|
||||
product.${ROW_SIGNATURES} != ''"""
|
||||
val signatureMatches = """$TABLE_INSTALLED.$ROW_SIGNATURE IS NOT NULL AND
|
||||
$TABLE_PRODUCT.$ROW_SIGNATURES LIKE ('%.' || $TABLE_INSTALLED.$ROW_SIGNATURE || '.%') AND
|
||||
$TABLE_PRODUCT.$ROW_SIGNATURES != ''"""
|
||||
|
||||
// Select the return fields
|
||||
builder += """SELECT product.rowid AS _id, product.$ROW_REPOSITORY_ID,
|
||||
product.$ROW_PACKAGE_NAME, product.$ROW_NAME,
|
||||
product.$ROW_SUMMARY, installed.$ROW_VERSION,
|
||||
(COALESCE(lock.$ROW_VERSION_CODE, -1) NOT IN (0, product.$ROW_VERSION_CODE) AND
|
||||
product.$ROW_COMPATIBLE != 0 AND product.$ROW_VERSION_CODE >
|
||||
COALESCE(installed.$ROW_VERSION_CODE, 0xffffffff) AND $signatureMatches)
|
||||
AS $ROW_CAN_UPDATE, product.$ROW_COMPATIBLE, product.$ROW_ICON,
|
||||
product.$ROW_METADATA_ICON, product.$ROW_RELEASES, product.$ROW_CATEGORIES,
|
||||
product.$ROW_ANTIFEATURES, product.$ROW_LICENSES, product.$ROW_DONATES, product.$ROW_SCREENSHOTS,"""
|
||||
builder += """SELECT $TABLE_PRODUCT.rowid AS $ROW_ID, $TABLE_PRODUCT.$ROW_REPOSITORY_ID,
|
||||
$TABLE_PRODUCT.$ROW_PACKAGE_NAME, $TABLE_PRODUCT.$ROW_LABEL,
|
||||
$TABLE_PRODUCT.$ROW_SUMMARY, $TABLE_INSTALLED.$ROW_VERSION,
|
||||
(COALESCE($TABLE_LOCK.$ROW_VERSION_CODE, -1) NOT IN (0, $TABLE_PRODUCT.$ROW_VERSION_CODE) AND
|
||||
$TABLE_PRODUCT.$ROW_COMPATIBLE != 0 AND $TABLE_PRODUCT.$ROW_VERSION_CODE >
|
||||
COALESCE($TABLE_INSTALLED.$ROW_VERSION_CODE, 0xffffffff) AND $signatureMatches)
|
||||
AS $ROW_CAN_UPDATE, $TABLE_PRODUCT.$ROW_COMPATIBLE, $TABLE_PRODUCT.$ROW_ICON,
|
||||
$TABLE_PRODUCT.$ROW_METADATA_ICON, $TABLE_PRODUCT.$ROW_RELEASES, $TABLE_PRODUCT.$ROW_CATEGORIES,
|
||||
$TABLE_PRODUCT.$ROW_ANTIFEATURES, $TABLE_PRODUCT.$ROW_LICENSES, $TABLE_PRODUCT.$ROW_DONATES, $TABLE_PRODUCT.$ROW_SCREENSHOTS,"""
|
||||
|
||||
// Calculate the matching score with the search query
|
||||
if (searchQuery.isNotEmpty()) {
|
||||
builder += """(((product.${ROW_NAME} LIKE ? OR
|
||||
product.${ROW_SUMMARY} LIKE ?) * 7) |
|
||||
((product.${ROW_PACKAGE_NAME} LIKE ?) * 3) |
|
||||
(product.${ROW_DESCRIPTION} LIKE ?)) AS ${ROW_MATCH_RANK},"""
|
||||
builder += """((($TABLE_PRODUCT.$ROW_LABEL LIKE ? OR
|
||||
$TABLE_PRODUCT.$ROW_SUMMARY LIKE ?) * 7) |
|
||||
(($TABLE_PRODUCT.$ROW_PACKAGE_NAME LIKE ?) * 3) |
|
||||
($TABLE_PRODUCT.$ROW_DESCRIPTION LIKE ?)) AS $ROW_MATCH_RANK,"""
|
||||
builder %= List(4) { "%$searchQuery%" }
|
||||
} else {
|
||||
builder += "0 AS ${ROW_MATCH_RANK},"
|
||||
builder += "0 AS $ROW_MATCH_RANK,"
|
||||
}
|
||||
|
||||
// Take product as main table
|
||||
builder += """MAX((product.${ROW_COMPATIBLE} AND
|
||||
(installed.${ROW_SIGNATURE} IS NULL OR $signatureMatches)) ||
|
||||
PRINTF('%016X', product.${ROW_VERSION_CODE})) FROM $ROW_PRODUCT_NAME AS product"""
|
||||
builder += """MAX(($TABLE_PRODUCT.$ROW_COMPATIBLE AND
|
||||
($TABLE_INSTALLED.$ROW_SIGNATURE IS NULL OR $signatureMatches)) ||
|
||||
PRINTF('%016X', $TABLE_PRODUCT.$ROW_VERSION_CODE)) FROM $TABLE_PRODUCT_NAME AS $TABLE_PRODUCT"""
|
||||
|
||||
// Merge the matching repositories
|
||||
builder += """JOIN $ROW_REPOSITORY_NAME AS repository
|
||||
ON product.${ROW_REPOSITORY_ID} = repository.${ROW_ID}"""
|
||||
builder += """JOIN $TABLE_REPOSITORY_NAME AS $TABLE_REPOSITORY
|
||||
ON $TABLE_PRODUCT.$ROW_REPOSITORY_ID = $TABLE_REPOSITORY.$ROW_ID"""
|
||||
|
||||
// Merge the matching locks
|
||||
builder += """LEFT JOIN $ROW_LOCK_NAME AS lock
|
||||
ON product.${ROW_PACKAGE_NAME} = lock.${ROW_PACKAGE_NAME}"""
|
||||
builder += """LEFT JOIN $TABLE_LOCK_NAME AS $TABLE_LOCK
|
||||
ON $TABLE_PRODUCT.$ROW_PACKAGE_NAME = $TABLE_LOCK.$ROW_PACKAGE_NAME"""
|
||||
|
||||
// Merge the matching installed
|
||||
if (!installed && !updates) builder += "LEFT"
|
||||
builder += """JOIN $ROW_INSTALLED_NAME AS installed
|
||||
ON product.${ROW_PACKAGE_NAME} = installed.${ROW_PACKAGE_NAME}"""
|
||||
builder += """JOIN $TABLE_INSTALLED_NAME AS $TABLE_INSTALLED
|
||||
ON $TABLE_PRODUCT.$ROW_PACKAGE_NAME = $TABLE_INSTALLED.$ROW_PACKAGE_NAME"""
|
||||
|
||||
// Merge the matching category
|
||||
if (section is Section.Category) {
|
||||
builder += """JOIN $ROW_CATEGORY_NAME AS category
|
||||
ON product.${ROW_PACKAGE_NAME} = category.${ROW_PACKAGE_NAME}"""
|
||||
builder += """JOIN $TABLE_CATEGORY_NAME AS $TABLE_CATEGORY
|
||||
ON $TABLE_PRODUCT.$ROW_PACKAGE_NAME = $TABLE_CATEGORY.$ROW_PACKAGE_NAME"""
|
||||
}
|
||||
|
||||
// Filter only active repositories
|
||||
builder += """WHERE repository.${ROW_ENABLED} != 0"""
|
||||
builder += """WHERE $TABLE_REPOSITORY.$ROW_ENABLED != 0"""
|
||||
|
||||
// Filter only the selected repository/category
|
||||
if (section is Section.Category) {
|
||||
builder += "AND category.${ROW_LABEL} = ?"
|
||||
builder += "AND $TABLE_CATEGORY.$ROW_LABEL = ?"
|
||||
builder %= section.name
|
||||
} else if (section is Section.Repository) {
|
||||
builder += "AND product.${ROW_REPOSITORY_ID} = ?"
|
||||
builder += "AND $TABLE_PRODUCT.$ROW_REPOSITORY_ID = ?"
|
||||
builder %= section.id.toString()
|
||||
}
|
||||
|
||||
@ -204,12 +204,12 @@ interface ProductDao : BaseDao<Product> {
|
||||
|
||||
when (updateCategory) {
|
||||
UpdateCategory.ALL -> Unit
|
||||
UpdateCategory.NEW -> builder += """AND product.${ROW_ADDED} = product.${ROW_UPDATED}"""
|
||||
UpdateCategory.UPDATED -> builder += """AND product.${ROW_ADDED} < product.${ROW_UPDATED}"""
|
||||
UpdateCategory.NEW -> builder += """AND $TABLE_PRODUCT.$ROW_ADDED = $TABLE_PRODUCT.$ROW_UPDATED"""
|
||||
UpdateCategory.UPDATED -> builder += """AND $TABLE_PRODUCT.$ROW_ADDED < $TABLE_PRODUCT.$ROW_UPDATED"""
|
||||
}
|
||||
|
||||
// Sum up all products with the same package name
|
||||
builder += "GROUP BY product.${ROW_PACKAGE_NAME} HAVING 1"
|
||||
builder += "GROUP BY $TABLE_PRODUCT.$ROW_PACKAGE_NAME HAVING 1"
|
||||
|
||||
// Filter if only can update
|
||||
if (updates) {
|
||||
@ -221,10 +221,10 @@ interface ProductDao : BaseDao<Product> {
|
||||
if (searchQuery.isNotEmpty()) builder += """$ROW_MATCH_RANK DESC,"""
|
||||
when (order) {
|
||||
Order.NAME -> Unit
|
||||
Order.DATE_ADDED -> builder += "product.${ROW_ADDED} DESC,"
|
||||
Order.LAST_UPDATE -> builder += "product.${ROW_UPDATED} DESC,"
|
||||
Order.DATE_ADDED -> builder += "$TABLE_PRODUCT.$ROW_ADDED DESC,"
|
||||
Order.LAST_UPDATE -> builder += "$TABLE_PRODUCT.$ROW_UPDATED DESC,"
|
||||
}::class
|
||||
builder += "product.${ROW_NAME} COLLATE LOCALIZED ASC${if (numberOfItems > 0) " LIMIT $numberOfItems" else ""}"
|
||||
builder += "$TABLE_PRODUCT.$ROW_LABEL COLLATE LOCALIZED ASC${if (numberOfItems > 0) " LIMIT $numberOfItems" else ""}"
|
||||
|
||||
return SimpleSQLiteQuery(builder.build(), builder.arguments.toTypedArray())
|
||||
}
|
||||
|
@ -1,13 +1,17 @@
|
||||
package com.looker.droidify.database.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import com.looker.droidify.*
|
||||
|
||||
@Entity(tableName = "category", primaryKeys = ["repositoryId", "packageName", "label"])
|
||||
@Entity(
|
||||
tableName = TABLE_CATEGORY_NAME,
|
||||
primaryKeys = [ROW_REPOSITORY_ID, ROW_PACKAGE_NAME, ROW_LABEL]
|
||||
)
|
||||
open class Category {
|
||||
var repositoryId: Long = 0
|
||||
var packageName = ""
|
||||
var label = ""
|
||||
}
|
||||
|
||||
@Entity(tableName = "temporary_category")
|
||||
@Entity(tableName = TABLE_CATEGORY_TEMP_NAME)
|
||||
class CategoryTemp : Category()
|
@ -2,8 +2,9 @@ package com.looker.droidify.database.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.looker.droidify.TABLE_INSTALLED_NAME
|
||||
|
||||
@Entity(tableName = "memory_installed")
|
||||
@Entity(tableName = TABLE_INSTALLED_NAME)
|
||||
data class Installed(
|
||||
@PrimaryKey
|
||||
var packageName: String = "",
|
||||
|
@ -2,8 +2,9 @@ package com.looker.droidify.database.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.looker.droidify.TABLE_LOCK_NAME
|
||||
|
||||
@Entity(tableName = "memory_lock")
|
||||
@Entity(tableName = TABLE_LOCK_NAME)
|
||||
data class Lock(
|
||||
@PrimaryKey
|
||||
var packageName: String = "",
|
||||
|
@ -1,6 +1,10 @@
|
||||
package com.looker.droidify.database.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import com.looker.droidify.ROW_PACKAGE_NAME
|
||||
import com.looker.droidify.ROW_REPOSITORY_ID
|
||||
import com.looker.droidify.TABLE_PRODUCT_NAME
|
||||
import com.looker.droidify.TABLE_PRODUCT_TEMP_NAME
|
||||
import com.looker.droidify.entity.Author
|
||||
import com.looker.droidify.entity.Donate
|
||||
import com.looker.droidify.entity.ProductItem
|
||||
@ -12,7 +16,7 @@ import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
// TODO Add Product Extras to handle favorite lists etc..
|
||||
@Entity(tableName = "product", primaryKeys = ["repositoryId", "packageName"])
|
||||
@Entity(tableName = TABLE_PRODUCT_NAME, primaryKeys = [ROW_REPOSITORY_ID, ROW_PACKAGE_NAME])
|
||||
@Serializable
|
||||
open class Product(
|
||||
var repositoryId: Long,
|
||||
@ -131,7 +135,7 @@ open class Product(
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(tableName = "temporary_product")
|
||||
@Entity(tableName = TABLE_PRODUCT_TEMP_NAME)
|
||||
class ProductTemp(
|
||||
repositoryId: Long,
|
||||
packageName: String,
|
||||
|
@ -2,13 +2,20 @@ package com.looker.droidify.database.entity
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.room.Entity
|
||||
import com.looker.droidify.ROW_PACKAGE_NAME
|
||||
import com.looker.droidify.ROW_SIGNATURE
|
||||
import com.looker.droidify.ROW_VERSION_CODE
|
||||
import com.looker.droidify.TABLE_RELEASE_NAME
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
// TODO make a Room entity
|
||||
@Entity(primaryKeys = ["packageName", "versionCode", "signature"])
|
||||
@Entity(
|
||||
tableName = TABLE_RELEASE_NAME,
|
||||
primaryKeys = [ROW_PACKAGE_NAME, ROW_VERSION_CODE, ROW_SIGNATURE]
|
||||
)
|
||||
@Serializable
|
||||
data class Release(
|
||||
val packageName: String,
|
||||
|
@ -3,17 +3,19 @@ package com.looker.droidify.database.entity
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.looker.droidify.ROW_ID
|
||||
import com.looker.droidify.TABLE_REPOSITORY_NAME
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.net.URL
|
||||
|
||||
@Entity
|
||||
@Entity(tableName = TABLE_REPOSITORY_NAME)
|
||||
@Serializable
|
||||
data class Repository(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = "_id")
|
||||
@ColumnInfo(name = ROW_ID)
|
||||
var id: Long = 0,
|
||||
var address: String = "",
|
||||
var mirrors: List<String> = emptyList(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user