mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-06-08 16:59:55 +00:00
Clean up & TODOs
This commit is contained in:
parent
69fba1452d
commit
67a1d9918e
@ -96,8 +96,6 @@ interface ProductDao : BaseDao<Product> {
|
|||||||
query: SupportSQLiteQuery
|
query: SupportSQLiteQuery
|
||||||
): DataSource.Factory<Int, Product>
|
): DataSource.Factory<Int, Product>
|
||||||
|
|
||||||
// TODO optimize and simplify
|
|
||||||
// TODO add an UpdateCategory argument
|
|
||||||
fun queryList(
|
fun queryList(
|
||||||
installed: Boolean, updates: Boolean, searchQuery: String,
|
installed: Boolean, updates: Boolean, searchQuery: String,
|
||||||
section: Section, order: Order, numberOfItems: Int = 0
|
section: Section, order: Order, numberOfItems: Int = 0
|
||||||
@ -105,6 +103,7 @@ interface ProductDao : BaseDao<Product> {
|
|||||||
buildProductQuery(installed, updates, searchQuery, section, order, numberOfItems)
|
buildProductQuery(installed, updates, searchQuery, section, order, numberOfItems)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO add an UpdateCategory argument
|
||||||
fun buildProductQuery(
|
fun buildProductQuery(
|
||||||
installed: Boolean, updates: Boolean, searchQuery: String,
|
installed: Boolean, updates: Boolean, searchQuery: String,
|
||||||
section: Section, order: Order, numberOfItems: Int = 0
|
section: Section, order: Order, numberOfItems: Int = 0
|
||||||
@ -115,6 +114,7 @@ interface ProductDao : BaseDao<Product> {
|
|||||||
product.${ROW_SIGNATURES} LIKE ('%.' || installed.${ROW_SIGNATURE} || '.%') AND
|
product.${ROW_SIGNATURES} LIKE ('%.' || installed.${ROW_SIGNATURE} || '.%') AND
|
||||||
product.${ROW_SIGNATURES} != ''"""
|
product.${ROW_SIGNATURES} != ''"""
|
||||||
|
|
||||||
|
// Select the return fields
|
||||||
builder += """SELECT product.rowid AS _id, product.${ROW_REPOSITORY_ID},
|
builder += """SELECT product.rowid AS _id, product.${ROW_REPOSITORY_ID},
|
||||||
product.${ROW_PACKAGE_NAME}, product.${ROW_NAME},
|
product.${ROW_PACKAGE_NAME}, product.${ROW_NAME},
|
||||||
product.${ROW_SUMMARY}, installed.${ROW_VERSION},
|
product.${ROW_SUMMARY}, installed.${ROW_VERSION},
|
||||||
@ -124,6 +124,7 @@ interface ProductDao : BaseDao<Product> {
|
|||||||
AS ${ROW_CAN_UPDATE}, product.${ROW_COMPATIBLE},
|
AS ${ROW_CAN_UPDATE}, product.${ROW_COMPATIBLE},
|
||||||
product.${ROW_ICON}, product.${ROW_METADATA_ICON}, product.${ROW_RELEASES},"""
|
product.${ROW_ICON}, product.${ROW_METADATA_ICON}, product.${ROW_RELEASES},"""
|
||||||
|
|
||||||
|
// Calculate the matching score with the search query
|
||||||
if (searchQuery.isNotEmpty()) {
|
if (searchQuery.isNotEmpty()) {
|
||||||
builder += """(((product.${ROW_NAME} LIKE ? OR
|
builder += """(((product.${ROW_NAME} LIKE ? OR
|
||||||
product.${ROW_SUMMARY} LIKE ?) * 7) |
|
product.${ROW_SUMMARY} LIKE ?) * 7) |
|
||||||
@ -134,27 +135,34 @@ interface ProductDao : BaseDao<Product> {
|
|||||||
builder += "0 AS ${ROW_MATCH_RANK},"
|
builder += "0 AS ${ROW_MATCH_RANK},"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Take product as main table
|
||||||
builder += """MAX((product.${ROW_COMPATIBLE} AND
|
builder += """MAX((product.${ROW_COMPATIBLE} AND
|
||||||
(installed.${ROW_SIGNATURE} IS NULL OR $signatureMatches)) ||
|
(installed.${ROW_SIGNATURE} IS NULL OR $signatureMatches)) ||
|
||||||
PRINTF('%016X', product.${ROW_VERSION_CODE})) FROM $ROW_PRODUCT_NAME AS product"""
|
PRINTF('%016X', product.${ROW_VERSION_CODE})) FROM $ROW_PRODUCT_NAME AS product"""
|
||||||
|
|
||||||
|
// Merge the matching repositories
|
||||||
builder += """JOIN $ROW_REPOSITORY_NAME AS repository
|
builder += """JOIN $ROW_REPOSITORY_NAME AS repository
|
||||||
ON product.${ROW_REPOSITORY_ID} = repository.${ROW_ID}"""
|
ON product.${ROW_REPOSITORY_ID} = repository.${ROW_ID}"""
|
||||||
|
|
||||||
|
// Merge the matching locks
|
||||||
builder += """LEFT JOIN $ROW_LOCK_NAME AS lock
|
builder += """LEFT JOIN $ROW_LOCK_NAME AS lock
|
||||||
ON product.${ROW_PACKAGE_NAME} = lock.${ROW_PACKAGE_NAME}"""
|
ON product.${ROW_PACKAGE_NAME} = lock.${ROW_PACKAGE_NAME}"""
|
||||||
|
|
||||||
if (!installed && !updates) {
|
// Merge the matching installed
|
||||||
builder += "LEFT"
|
if (!installed && !updates) builder += "LEFT"
|
||||||
}
|
|
||||||
builder += """JOIN $ROW_INSTALLED_NAME AS installed
|
builder += """JOIN $ROW_INSTALLED_NAME AS installed
|
||||||
ON product.${ROW_PACKAGE_NAME} = installed.${ROW_PACKAGE_NAME}"""
|
ON product.${ROW_PACKAGE_NAME} = installed.${ROW_PACKAGE_NAME}"""
|
||||||
|
|
||||||
|
// Merge the matching category
|
||||||
if (section is Section.Category) {
|
if (section is Section.Category) {
|
||||||
builder += """JOIN $ROW_CATEGORY_NAME AS category
|
builder += """JOIN $ROW_CATEGORY_NAME AS category
|
||||||
ON product.${ROW_PACKAGE_NAME} = category.${ROW_PACKAGE_NAME}"""
|
ON product.${ROW_PACKAGE_NAME} = category.${ROW_PACKAGE_NAME}"""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filter only active repositories
|
||||||
builder += """WHERE repository.${ROW_ENABLED} != 0"""
|
builder += """WHERE repository.${ROW_ENABLED} != 0"""
|
||||||
|
|
||||||
|
// Filter only the selected repository/category
|
||||||
if (section is Section.Category) {
|
if (section is Section.Category) {
|
||||||
builder += "AND category.${ROW_NAME} = ?"
|
builder += "AND category.${ROW_NAME} = ?"
|
||||||
builder %= section.name
|
builder %= section.name
|
||||||
@ -163,21 +171,22 @@ interface ProductDao : BaseDao<Product> {
|
|||||||
builder %= section.id.toString()
|
builder %= section.id.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filter only apps that have some matching score to the search query
|
||||||
if (searchQuery.isNotEmpty()) {
|
if (searchQuery.isNotEmpty()) {
|
||||||
builder += """AND $ROW_MATCH_RANK > 0"""
|
builder += """AND $ROW_MATCH_RANK > 0"""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sum up all products with the same package name
|
||||||
builder += "GROUP BY product.${ROW_PACKAGE_NAME} HAVING 1"
|
builder += "GROUP BY product.${ROW_PACKAGE_NAME} HAVING 1"
|
||||||
|
|
||||||
|
// Filter if only can update
|
||||||
if (updates) {
|
if (updates) {
|
||||||
builder += "AND $ROW_CAN_UPDATE"
|
builder += "AND $ROW_CAN_UPDATE"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set sorting order
|
||||||
builder += "ORDER BY"
|
builder += "ORDER BY"
|
||||||
|
if (searchQuery.isNotEmpty()) builder += """$ROW_MATCH_RANK DESC,"""
|
||||||
if (searchQuery.isNotEmpty()) {
|
|
||||||
builder += """$ROW_MATCH_RANK DESC,"""
|
|
||||||
}
|
|
||||||
|
|
||||||
when (order) {
|
when (order) {
|
||||||
Order.NAME -> Unit
|
Order.NAME -> Unit
|
||||||
Order.DATE_ADDED -> builder += "product.${ROW_ADDED} DESC,"
|
Order.DATE_ADDED -> builder += "product.${ROW_ADDED} DESC,"
|
||||||
|
@ -1,12 +1,5 @@
|
|||||||
package com.looker.droidify.database
|
package com.looker.droidify.database
|
||||||
|
|
||||||
import android.database.Cursor
|
|
||||||
import android.database.sqlite.SQLiteDatabase
|
|
||||||
import android.os.CancellationSignal
|
|
||||||
import com.looker.droidify.BuildConfig
|
|
||||||
import com.looker.droidify.utility.extension.android.asSequence
|
|
||||||
import com.looker.droidify.utility.extension.text.debug
|
|
||||||
|
|
||||||
class QueryBuilder {
|
class QueryBuilder {
|
||||||
companion object {
|
companion object {
|
||||||
fun trimQuery(query: String): String {
|
fun trimQuery(query: String): String {
|
||||||
@ -34,19 +27,4 @@ class QueryBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun build() = builder.toString()
|
fun build() = builder.toString()
|
||||||
|
|
||||||
fun query(db: SQLiteDatabase, signal: CancellationSignal?): Cursor {
|
|
||||||
val query = builder.toString()
|
|
||||||
val arguments = arguments.toTypedArray()
|
|
||||||
if (BuildConfig.DEBUG) {
|
|
||||||
synchronized(QueryBuilder::class.java) {
|
|
||||||
debug(query)
|
|
||||||
db.rawQuery("EXPLAIN QUERY PLAN $query", arguments).use {
|
|
||||||
it.asSequence()
|
|
||||||
.forEach { debug(":: ${it.getString(it.getColumnIndex("detail"))}") }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return db.rawQuery(query, arguments, signal)
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -21,6 +21,7 @@ open class Product {
|
|||||||
var metadataIcon = ""
|
var metadataIcon = ""
|
||||||
var releases: List<Release> = emptyList()
|
var releases: List<Release> = emptyList()
|
||||||
|
|
||||||
|
// TODO Remove in next iteration
|
||||||
@ColumnInfo(typeAffinity = ColumnInfo.BLOB)
|
@ColumnInfo(typeAffinity = ColumnInfo.BLOB)
|
||||||
var data: com.looker.droidify.entity.Product? = null
|
var data: com.looker.droidify.entity.Product? = null
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user