Update: Replace ProductItem field with function (a first step in refactoring Product)

This commit is contained in:
machiav3lli 2022-02-01 02:41:26 +01:00
parent c3468c466d
commit e36375dcb1
10 changed files with 15 additions and 28 deletions

View File

@ -1,7 +1,6 @@
package com.looker.droidify.database
import androidx.room.TypeConverter
import com.looker.droidify.entity.ProductItem
import com.looker.droidify.utility.jsonGenerate
import com.looker.droidify.utility.jsonParse
@ -26,12 +25,4 @@ object Converters {
@TypeConverter
@JvmStatic
fun toByteArray(product: com.looker.droidify.entity.Product) = jsonGenerate(product::serialize)
@TypeConverter
@JvmStatic
fun toProductItem(byteArray: ByteArray) = byteArray.jsonParse { ProductItem.deserialize(it) }
@TypeConverter
@JvmStatic
fun toByteArray(productItem: ProductItem) = jsonGenerate(productItem::serialize)
}

View File

@ -106,8 +106,7 @@ interface ProductDao : BaseDao<Product> {
(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_DATA_ITEM},"""
AS ${ROW_CAN_UPDATE}, product.${ROW_COMPATIBLE},"""
if (searchQuery.isNotEmpty()) {
builder += """(((product.${ROW_NAME} LIKE ? OR
@ -195,8 +194,7 @@ interface ProductDao : BaseDao<Product> {
(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_DATA_ITEM},"""
AS ${ROW_CAN_UPDATE}, product.${ROW_COMPATIBLE},"""
if (searchQuery.isNotEmpty()) {
builder += """(((product.${ROW_NAME} LIKE ? OR
@ -332,7 +330,6 @@ interface ProductTempDao : BaseDao<ProductTemp> {
this.signatures = signatures
compatible = if (it.compatible) 1 else 0
data = it
data_item = it.item()
}
})
it.categories.forEach { category ->

View File

@ -21,8 +21,7 @@ open class Product {
@ColumnInfo(typeAffinity = ColumnInfo.BLOB)
var data: com.looker.droidify.entity.Product? = null
@ColumnInfo(typeAffinity = ColumnInfo.BLOB)
var data_item: ProductItem? = null
fun item(): ProductItem? = data?.item()
}
@Entity(tableName = "temporary_product")

View File

@ -27,7 +27,7 @@ import com.looker.droidify.utility.extension.android.asSequence
import com.looker.droidify.utility.extension.android.notificationManager
import com.looker.droidify.utility.extension.resources.getColorFromAttr
import com.looker.droidify.utility.extension.text.formatSize
import com.looker.droidify.utility.getProductItem
import com.looker.droidify.utility.getProduct
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
@ -398,7 +398,7 @@ class SyncService : ConnectionService<SyncService.Binder>() {
signal = it
)
.use {
it.asSequence().map { it.getProductItem() }
it.asSequence().map { it.getProduct().item() }
.toList()
}
}

View File

@ -22,7 +22,7 @@ import com.looker.droidify.network.CoilDownloader
import com.looker.droidify.utility.Utils
import com.looker.droidify.utility.extension.resources.*
import com.looker.droidify.utility.extension.text.nullIfEmpty
import com.looker.droidify.utility.getProductItem
import com.looker.droidify.utility.getProduct
import com.looker.droidify.widget.CursorRecyclerAdapter
class AppListAdapter(private val onClick: (ProductItem) -> Unit) :
@ -113,7 +113,7 @@ class AppListAdapter(private val onClick: (ProductItem) -> Unit) :
}
private fun getProductItem(position: Int): ProductItem {
return moveTo(position).getProductItem()
return moveTo(position).getProduct().item()
}
override fun onCreateViewHolder(

View File

@ -15,7 +15,7 @@ fun ProductsVerticalRecycler(productsList: List<Product>) {
verticalArrangement = spacedBy(2.dp)
) {
items(productsList) { product: Product ->
product.data_item?.let { item ->
product.item()?.let { item ->
ProductRow(item.name, item.version, item.summary, onUserClick = {
Log.d(this.toString(), "You clicked $it")
})
@ -30,7 +30,7 @@ fun ProductsHorizontalRecycler(productsList: List<Product>) {
horizontalArrangement = spacedBy(2.dp)
) {
items(productsList) { product: Product ->
product.data_item?.let { item ->
product.item()?.let { item ->
ProductColumn(item.name, item.version, onUserClick = {
Log.d(this.toString(), "You clicked $it")
})

View File

@ -52,7 +52,7 @@ class ExploreFragment : MainNavFragmentX() {
override fun setupAdapters() {
appsItemAdapter = PagedModelAdapter<Product, VAppItem>(PRODUCT_ASYNC_DIFFER_CONFIG) {
it.data_item?.let { item -> VAppItem(item, repositories[it.repository_id]) }
it.item()?.let { item -> VAppItem(item, repositories[it.repository_id]) }
}
appsFastAdapter = FastAdapter.with(appsItemAdapter)
appsFastAdapter?.setHasStableIds(true)

View File

@ -55,11 +55,11 @@ class InstalledFragment : MainNavFragmentX() {
override fun setupAdapters() {
installedItemAdapter = PagedModelAdapter<Product, VAppItem>(PRODUCT_ASYNC_DIFFER_CONFIG) {
it.data_item?.let { item -> VAppItem(item, repositories[it.repository_id]) }
it.item()?.let { item -> VAppItem(item, repositories[it.repository_id]) }
}
updatedItemAdapter = PagedModelAdapter<Product, HAppItem>(PRODUCT_ASYNC_DIFFER_CONFIG) {
// TODO filter for only updated apps and add placeholder
it.data_item?.let { item -> HAppItem(item, repositories[it.repository_id]) }
it.item()?.let { item -> HAppItem(item, repositories[it.repository_id]) }
}
installedFastAdapter = FastAdapter.with(installedItemAdapter)
installedFastAdapter?.setHasStableIds(true)

View File

@ -56,11 +56,11 @@ class LatestFragment : MainNavFragmentX() {
override fun setupAdapters() {
updatedItemAdapter = PagedModelAdapter<Product, VAppItem>(PRODUCT_ASYNC_DIFFER_CONFIG) {
it.data_item?.let { item -> VAppItem(item, repositories[it.repository_id]) }
it.item()?.let { item -> VAppItem(item, repositories[it.repository_id]) }
}
newItemAdapter = PagedModelAdapter<Product, HAppItem>(PRODUCT_ASYNC_DIFFER_CONFIG) {
// TODO filter for only new apps and add placeholder
it.data_item?.let { item -> HAppItem(item, repositories[it.repository_id]) }
it.item()?.let { item -> HAppItem(item, repositories[it.repository_id]) }
}
updatedFastAdapter = FastAdapter.with(updatedItemAdapter)
updatedFastAdapter?.setHasStableIds(true)

View File

@ -240,6 +240,6 @@ val PRODUCT_ASYNC_DIFFER_CONFIG
oldItem: com.looker.droidify.database.entity.Product,
newItem: com.looker.droidify.database.entity.Product
): Boolean {
return oldItem.data_item == newItem.data_item
return oldItem.item() == newItem.item()
}
}).build()