mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-24 03:42:15 +00:00
Update: Revamp the Request class and add two new subclasses (ProductsUpdated, ProductsNew)
This commit is contained in:
parent
cb56f9b053
commit
251b6195d6
@ -48,33 +48,70 @@ enum class Source(val titleResId: Int, val sections: Boolean, val order: Boolean
|
||||
|
||||
sealed class Request {
|
||||
internal abstract val id: Int
|
||||
internal abstract val installed: Boolean
|
||||
internal abstract val updates: Boolean
|
||||
internal abstract val searchQuery: String
|
||||
internal abstract val section: ProductItem.Section
|
||||
internal abstract val order: ProductItem.Order
|
||||
internal open val numberOfItems: Int = 0
|
||||
|
||||
data class ProductsAvailable(
|
||||
val searchQuery: String, val section: ProductItem.Section,
|
||||
val order: ProductItem.Order,
|
||||
data class ProductsAll(
|
||||
override val searchQuery: String, override val section: ProductItem.Section,
|
||||
override val order: ProductItem.Order,
|
||||
) : Request() {
|
||||
override val id: Int
|
||||
get() = 1
|
||||
override val installed: Boolean
|
||||
get() = false
|
||||
override val updates: Boolean
|
||||
get() = false
|
||||
}
|
||||
|
||||
data class ProductsInstalled(
|
||||
val searchQuery: String, val section: ProductItem.Section,
|
||||
val order: ProductItem.Order,
|
||||
override val searchQuery: String, override val section: ProductItem.Section,
|
||||
override val order: ProductItem.Order,
|
||||
) : Request() {
|
||||
override val id: Int
|
||||
get() = 2
|
||||
override val installed: Boolean
|
||||
get() = true
|
||||
override val updates: Boolean
|
||||
get() = false
|
||||
}
|
||||
|
||||
data class ProductsUpdates(
|
||||
val searchQuery: String, val section: ProductItem.Section,
|
||||
val order: ProductItem.Order,
|
||||
override val searchQuery: String, override val section: ProductItem.Section,
|
||||
override val order: ProductItem.Order,
|
||||
) : Request() {
|
||||
override val id: Int
|
||||
get() = 3
|
||||
override val installed: Boolean
|
||||
get() = true
|
||||
override val updates: Boolean
|
||||
get() = true
|
||||
}
|
||||
|
||||
object Repositories : Request() {
|
||||
data class ProductsUpdated(
|
||||
override val searchQuery: String, override val section: ProductItem.Section,
|
||||
override val order: ProductItem.Order, override val numberOfItems: Int,
|
||||
) : Request() {
|
||||
override val id: Int
|
||||
get() = 4
|
||||
override val installed: Boolean
|
||||
get() = false
|
||||
override val updates: Boolean
|
||||
get() = false
|
||||
}
|
||||
|
||||
data class ProductsNew(
|
||||
override val searchQuery: String, override val section: ProductItem.Section,
|
||||
override val order: ProductItem.Order, override val numberOfItems: Int,
|
||||
) : Request() {
|
||||
override val id: Int
|
||||
get() = 5
|
||||
override val installed: Boolean
|
||||
get() = false
|
||||
override val updates: Boolean
|
||||
get() = false
|
||||
}
|
||||
}
|
@ -50,7 +50,7 @@ class MainNavFragmentViewModelX(val db: DatabaseX) : ViewModel() {
|
||||
launch { order.collect { if (source.order) mOrder = it } }
|
||||
}
|
||||
return when (source) {
|
||||
Source.AVAILABLE -> Request.ProductsAvailable(
|
||||
Source.AVAILABLE -> Request.ProductsAll(
|
||||
mSearchQuery,
|
||||
mSections,
|
||||
mOrder
|
||||
@ -77,34 +77,16 @@ class MainNavFragmentViewModelX(val db: DatabaseX) : ViewModel() {
|
||||
}
|
||||
|
||||
private suspend fun query(request: Request): List<Product>? {
|
||||
return withContext(Dispatchers.IO) {
|
||||
when (request) {
|
||||
is Request.ProductsAvailable -> db.productDao
|
||||
return withContext(Dispatchers.Default) {
|
||||
db.productDao
|
||||
.queryList(
|
||||
installed = false,
|
||||
updates = false,
|
||||
installed = request.installed,
|
||||
updates = request.updates,
|
||||
searchQuery = request.searchQuery,
|
||||
section = request.section,
|
||||
order = request.order
|
||||
order = request.order,
|
||||
numberOfItems = request.numberOfItems
|
||||
)
|
||||
is Request.ProductsInstalled -> db.productDao
|
||||
.queryList(
|
||||
installed = true,
|
||||
updates = false,
|
||||
searchQuery = request.searchQuery,
|
||||
section = request.section,
|
||||
order = request.order
|
||||
)
|
||||
is Request.ProductsUpdates -> db.productDao
|
||||
.queryList(
|
||||
installed = true,
|
||||
updates = true,
|
||||
searchQuery = request.searchQuery,
|
||||
section = request.section,
|
||||
order = request.order
|
||||
)
|
||||
else -> listOf()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user