mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-06-08 16:59:55 +00:00
Update: Replace ProductItem field with function (a first step in refactoring Product)
This commit is contained in:
parent
c3468c466d
commit
e36375dcb1
@ -1,7 +1,6 @@
|
|||||||
package com.looker.droidify.database
|
package com.looker.droidify.database
|
||||||
|
|
||||||
import androidx.room.TypeConverter
|
import androidx.room.TypeConverter
|
||||||
import com.looker.droidify.entity.ProductItem
|
|
||||||
import com.looker.droidify.utility.jsonGenerate
|
import com.looker.droidify.utility.jsonGenerate
|
||||||
import com.looker.droidify.utility.jsonParse
|
import com.looker.droidify.utility.jsonParse
|
||||||
|
|
||||||
@ -26,12 +25,4 @@ object Converters {
|
|||||||
@TypeConverter
|
@TypeConverter
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun toByteArray(product: com.looker.droidify.entity.Product) = jsonGenerate(product::serialize)
|
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)
|
|
||||||
}
|
}
|
@ -106,8 +106,7 @@ interface ProductDao : BaseDao<Product> {
|
|||||||
(COALESCE(lock.${ROW_VERSION_CODE}, -1) NOT IN (0, product.${ROW_VERSION_CODE}) AND
|
(COALESCE(lock.${ROW_VERSION_CODE}, -1) NOT IN (0, product.${ROW_VERSION_CODE}) AND
|
||||||
product.${ROW_COMPATIBLE} != 0 AND product.${ROW_VERSION_CODE} >
|
product.${ROW_COMPATIBLE} != 0 AND product.${ROW_VERSION_CODE} >
|
||||||
COALESCE(installed.${ROW_VERSION_CODE}, 0xffffffff) AND $signatureMatches)
|
COALESCE(installed.${ROW_VERSION_CODE}, 0xffffffff) AND $signatureMatches)
|
||||||
AS ${ROW_CAN_UPDATE}, product.${ROW_COMPATIBLE},
|
AS ${ROW_CAN_UPDATE}, product.${ROW_COMPATIBLE},"""
|
||||||
product.${ROW_DATA_ITEM},"""
|
|
||||||
|
|
||||||
if (searchQuery.isNotEmpty()) {
|
if (searchQuery.isNotEmpty()) {
|
||||||
builder += """(((product.${ROW_NAME} LIKE ? OR
|
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
|
(COALESCE(lock.${ROW_VERSION_CODE}, -1) NOT IN (0, product.${ROW_VERSION_CODE}) AND
|
||||||
product.${ROW_COMPATIBLE} != 0 AND product.${ROW_VERSION_CODE} >
|
product.${ROW_COMPATIBLE} != 0 AND product.${ROW_VERSION_CODE} >
|
||||||
COALESCE(installed.${ROW_VERSION_CODE}, 0xffffffff) AND $signatureMatches)
|
COALESCE(installed.${ROW_VERSION_CODE}, 0xffffffff) AND $signatureMatches)
|
||||||
AS ${ROW_CAN_UPDATE}, product.${ROW_COMPATIBLE},
|
AS ${ROW_CAN_UPDATE}, product.${ROW_COMPATIBLE},"""
|
||||||
product.${ROW_DATA_ITEM},"""
|
|
||||||
|
|
||||||
if (searchQuery.isNotEmpty()) {
|
if (searchQuery.isNotEmpty()) {
|
||||||
builder += """(((product.${ROW_NAME} LIKE ? OR
|
builder += """(((product.${ROW_NAME} LIKE ? OR
|
||||||
@ -332,7 +330,6 @@ interface ProductTempDao : BaseDao<ProductTemp> {
|
|||||||
this.signatures = signatures
|
this.signatures = signatures
|
||||||
compatible = if (it.compatible) 1 else 0
|
compatible = if (it.compatible) 1 else 0
|
||||||
data = it
|
data = it
|
||||||
data_item = it.item()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
it.categories.forEach { category ->
|
it.categories.forEach { category ->
|
||||||
|
@ -21,8 +21,7 @@ open class Product {
|
|||||||
@ColumnInfo(typeAffinity = ColumnInfo.BLOB)
|
@ColumnInfo(typeAffinity = ColumnInfo.BLOB)
|
||||||
var data: com.looker.droidify.entity.Product? = null
|
var data: com.looker.droidify.entity.Product? = null
|
||||||
|
|
||||||
@ColumnInfo(typeAffinity = ColumnInfo.BLOB)
|
fun item(): ProductItem? = data?.item()
|
||||||
var data_item: ProductItem? = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(tableName = "temporary_product")
|
@Entity(tableName = "temporary_product")
|
||||||
|
@ -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.android.notificationManager
|
||||||
import com.looker.droidify.utility.extension.resources.getColorFromAttr
|
import com.looker.droidify.utility.extension.resources.getColorFromAttr
|
||||||
import com.looker.droidify.utility.extension.text.formatSize
|
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.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.rxjava3.disposables.Disposable
|
import io.reactivex.rxjava3.disposables.Disposable
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
@ -398,7 +398,7 @@ class SyncService : ConnectionService<SyncService.Binder>() {
|
|||||||
signal = it
|
signal = it
|
||||||
)
|
)
|
||||||
.use {
|
.use {
|
||||||
it.asSequence().map { it.getProductItem() }
|
it.asSequence().map { it.getProduct().item() }
|
||||||
.toList()
|
.toList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import com.looker.droidify.network.CoilDownloader
|
|||||||
import com.looker.droidify.utility.Utils
|
import com.looker.droidify.utility.Utils
|
||||||
import com.looker.droidify.utility.extension.resources.*
|
import com.looker.droidify.utility.extension.resources.*
|
||||||
import com.looker.droidify.utility.extension.text.nullIfEmpty
|
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
|
import com.looker.droidify.widget.CursorRecyclerAdapter
|
||||||
|
|
||||||
class AppListAdapter(private val onClick: (ProductItem) -> Unit) :
|
class AppListAdapter(private val onClick: (ProductItem) -> Unit) :
|
||||||
@ -113,7 +113,7 @@ class AppListAdapter(private val onClick: (ProductItem) -> Unit) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getProductItem(position: Int): ProductItem {
|
private fun getProductItem(position: Int): ProductItem {
|
||||||
return moveTo(position).getProductItem()
|
return moveTo(position).getProduct().item()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(
|
override fun onCreateViewHolder(
|
||||||
|
@ -15,7 +15,7 @@ fun ProductsVerticalRecycler(productsList: List<Product>) {
|
|||||||
verticalArrangement = spacedBy(2.dp)
|
verticalArrangement = spacedBy(2.dp)
|
||||||
) {
|
) {
|
||||||
items(productsList) { product: Product ->
|
items(productsList) { product: Product ->
|
||||||
product.data_item?.let { item ->
|
product.item()?.let { item ->
|
||||||
ProductRow(item.name, item.version, item.summary, onUserClick = {
|
ProductRow(item.name, item.version, item.summary, onUserClick = {
|
||||||
Log.d(this.toString(), "You clicked $it")
|
Log.d(this.toString(), "You clicked $it")
|
||||||
})
|
})
|
||||||
@ -30,7 +30,7 @@ fun ProductsHorizontalRecycler(productsList: List<Product>) {
|
|||||||
horizontalArrangement = spacedBy(2.dp)
|
horizontalArrangement = spacedBy(2.dp)
|
||||||
) {
|
) {
|
||||||
items(productsList) { product: Product ->
|
items(productsList) { product: Product ->
|
||||||
product.data_item?.let { item ->
|
product.item()?.let { item ->
|
||||||
ProductColumn(item.name, item.version, onUserClick = {
|
ProductColumn(item.name, item.version, onUserClick = {
|
||||||
Log.d(this.toString(), "You clicked $it")
|
Log.d(this.toString(), "You clicked $it")
|
||||||
})
|
})
|
||||||
|
@ -52,7 +52,7 @@ class ExploreFragment : MainNavFragmentX() {
|
|||||||
|
|
||||||
override fun setupAdapters() {
|
override fun setupAdapters() {
|
||||||
appsItemAdapter = PagedModelAdapter<Product, VAppItem>(PRODUCT_ASYNC_DIFFER_CONFIG) {
|
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 = FastAdapter.with(appsItemAdapter)
|
||||||
appsFastAdapter?.setHasStableIds(true)
|
appsFastAdapter?.setHasStableIds(true)
|
||||||
|
@ -55,11 +55,11 @@ class InstalledFragment : MainNavFragmentX() {
|
|||||||
|
|
||||||
override fun setupAdapters() {
|
override fun setupAdapters() {
|
||||||
installedItemAdapter = PagedModelAdapter<Product, VAppItem>(PRODUCT_ASYNC_DIFFER_CONFIG) {
|
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) {
|
updatedItemAdapter = PagedModelAdapter<Product, HAppItem>(PRODUCT_ASYNC_DIFFER_CONFIG) {
|
||||||
// TODO filter for only updated apps and add placeholder
|
// 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 = FastAdapter.with(installedItemAdapter)
|
||||||
installedFastAdapter?.setHasStableIds(true)
|
installedFastAdapter?.setHasStableIds(true)
|
||||||
|
@ -56,11 +56,11 @@ class LatestFragment : MainNavFragmentX() {
|
|||||||
|
|
||||||
override fun setupAdapters() {
|
override fun setupAdapters() {
|
||||||
updatedItemAdapter = PagedModelAdapter<Product, VAppItem>(PRODUCT_ASYNC_DIFFER_CONFIG) {
|
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) {
|
newItemAdapter = PagedModelAdapter<Product, HAppItem>(PRODUCT_ASYNC_DIFFER_CONFIG) {
|
||||||
// TODO filter for only new apps and add placeholder
|
// 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 = FastAdapter.with(updatedItemAdapter)
|
||||||
updatedFastAdapter?.setHasStableIds(true)
|
updatedFastAdapter?.setHasStableIds(true)
|
||||||
|
@ -240,6 +240,6 @@ val PRODUCT_ASYNC_DIFFER_CONFIG
|
|||||||
oldItem: com.looker.droidify.database.entity.Product,
|
oldItem: com.looker.droidify.database.entity.Product,
|
||||||
newItem: com.looker.droidify.database.entity.Product
|
newItem: com.looker.droidify.database.entity.Product
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return oldItem.data_item == newItem.data_item
|
return oldItem.item() == newItem.item()
|
||||||
}
|
}
|
||||||
}).build()
|
}).build()
|
Loading…
x
Reference in New Issue
Block a user