Add: Categories to MainNavVM

This commit is contained in:
machiav3lli 2022-02-17 23:59:39 +01:00
parent 1fdc74731e
commit 211ec583c5
2 changed files with 11 additions and 0 deletions

View File

@ -226,6 +226,15 @@ interface CategoryDao : BaseDao<Category> {
) )
val allNames: List<String> val allNames: List<String>
@get:Query(
"""SELECT DISTINCT category.name
FROM category AS category
JOIN repository AS repository
ON category.repository_id = repository._id
WHERE repository.enabled != 0"""
)
val allNamesLive: LiveData<List<String>>
@Query("DELETE FROM category WHERE repository_id = :id") @Query("DELETE FROM category WHERE repository_id = :id")
fun deleteById(id: Long): Int fun deleteById(id: Long): Int
} }

View File

@ -67,6 +67,7 @@ class MainNavFragmentViewModelX(
val secondaryProducts = MediatorLiveData<List<Product>>() val secondaryProducts = MediatorLiveData<List<Product>>()
val repositories = MediatorLiveData<List<Repository>>() val repositories = MediatorLiveData<List<Repository>>()
val categories = MediatorLiveData<List<String>>()
init { init {
primaryProducts.addSource( primaryProducts.addSource(
@ -78,6 +79,7 @@ class MainNavFragmentViewModelX(
secondaryProducts::setValue secondaryProducts::setValue
) )
repositories.addSource(db.repositoryDao.allLive, repositories::setValue) repositories.addSource(db.repositoryDao.allLive, repositories::setValue)
categories.addSource(db.categoryDao.allNamesLive, categories::setValue)
} }
fun setSection(newSection: Section) { fun setSection(newSection: Section) {