Add: Installed list to MainNav VM

This commit is contained in:
machiav3lli 2022-04-12 12:34:04 +02:00
parent 506e26d0cc
commit 0e379d95ff
4 changed files with 13 additions and 2 deletions

View File

@ -52,6 +52,7 @@ class ExploreFragment : MainNavFragmentX() {
viewModel.repositories.observe(viewLifecycleOwner) {
repositories = it.associateBy { repo -> repo.id }
}
viewModel.installed.observe(viewLifecycleOwner) {}
viewModel.primaryProducts.observe(viewLifecycleOwner) {
redrawPage(it, viewModel.categories.value ?: emptyList())
}

View File

@ -43,6 +43,7 @@ class InstalledFragment : MainNavFragmentX() {
viewModel.repositories.observe(viewLifecycleOwner) {
repositories = it.associateBy { repo -> repo.id }
}
viewModel.installed.observe(viewLifecycleOwner) {}
viewModel.primaryProducts.observe(viewLifecycleOwner) {
binding.primaryComposeRecycler.setContent {
AppTheme(

View File

@ -43,6 +43,7 @@ class LatestFragment : MainNavFragmentX() {
viewModel.repositories.observe(viewLifecycleOwner) {
repositories = it.associateBy { repo -> repo.id }
}
viewModel.installed.observe(viewLifecycleOwner) {}
viewModel.primaryProducts.observe(viewLifecycleOwner) {
binding.primaryComposeRecycler.setContent {
AppTheme(

View File

@ -3,6 +3,7 @@ package com.looker.droidify.ui.viewmodels
import androidx.lifecycle.*
import com.looker.droidify.content.Preferences
import com.looker.droidify.database.DatabaseX
import com.looker.droidify.database.entity.Installed
import com.looker.droidify.database.entity.Product
import com.looker.droidify.database.entity.Repository
import com.looker.droidify.entity.Order
@ -71,6 +72,7 @@ class MainNavFragmentViewModelX(
val repositories = MediatorLiveData<List<Repository>>()
val categories = MediatorLiveData<List<String>>()
val installed = MediatorLiveData<List<Installed>>()
init {
primaryProducts.addSource(
@ -99,14 +101,20 @@ class MainNavFragmentViewModelX(
}
}
}
if (secondarySource == Source.UPDATES) {
secondaryProducts.addSource(db.installedDao.allLive) {
installed.addSource(db.installedDao.allLive) {
if (primarySource == Source.INSTALLED && secondarySource == Source.UPDATES) {
viewModelScope.launch {
withContext(Dispatchers.IO) {
secondaryProducts.postValue(db.productDao.queryObject(secondaryRequest))
primaryProducts.postValue(
db.productDao.queryObject(
primaryRequest.value ?: request(primarySource)
)
)
}
}
}
installed.postValue(it)
}
}