mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Fix: Nullability of MutableLiveData
This commit is contained in:
parent
fc74146194
commit
38c7c74ebf
@ -19,20 +19,20 @@ import kotlinx.coroutines.withContext
|
|||||||
|
|
||||||
class AppViewModelX(val db: DatabaseX, val packageName: String) : ViewModel() {
|
class AppViewModelX(val db: DatabaseX, val packageName: String) : ViewModel() {
|
||||||
|
|
||||||
val products = MediatorLiveData<List<Product>>()
|
val products: MediatorLiveData<List<Product>> = MediatorLiveData()
|
||||||
val repositories = MediatorLiveData<List<Repository>>()
|
val repositories: MediatorLiveData<List<Repository>> = MediatorLiveData()
|
||||||
val installedItem = MediatorLiveData<Installed?>()
|
val installedItem: MediatorLiveData<Installed?> = MediatorLiveData()
|
||||||
val _productRepos = MutableLiveData<List<Pair<Product, Repository>>>()
|
val _productRepos: MutableLiveData<List<Pair<Product, Repository>>> = MutableLiveData()
|
||||||
var productRepos: List<Pair<Product, Repository>>
|
var productRepos: List<Pair<Product, Repository>>
|
||||||
get() = _productRepos.value ?: emptyList()
|
get() = _productRepos.value ?: emptyList()
|
||||||
set(value) {
|
set(value) {
|
||||||
_productRepos.value = value
|
_productRepos.value = value
|
||||||
}
|
}
|
||||||
val downloadState = MutableLiveData<DownloadState>()
|
val downloadState: MutableLiveData<DownloadState> = MutableLiveData()
|
||||||
val mainAction = MutableLiveData<ActionState>()
|
val mainAction: MutableLiveData<ActionState> = MutableLiveData()
|
||||||
val actions = MediatorLiveData<Set<ActionState>>()
|
val actions: MediatorLiveData<Set<ActionState>> = MediatorLiveData()
|
||||||
val secondaryAction = MutableLiveData<ActionState>()
|
val secondaryAction: MutableLiveData<ActionState> = MutableLiveData()
|
||||||
val extras = MediatorLiveData<Extras>()
|
val extras: MediatorLiveData<Extras> = MediatorLiveData()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
products.addSource(db.productDao.getLive(packageName)) { products.setValue(it.filterNotNull()) }
|
products.addSource(db.productDao.getLive(packageName)) { products.setValue(it.filterNotNull()) }
|
||||||
@ -81,7 +81,8 @@ class AppViewModelX(val db: DatabaseX, val packageName: String) : ViewModel() {
|
|||||||
canLaunch -> ActionState.Launch
|
canLaunch -> ActionState.Launch
|
||||||
canInstall -> ActionState.Install
|
canInstall -> ActionState.Install
|
||||||
canShare -> ActionState.Share
|
canShare -> ActionState.Share
|
||||||
else -> null
|
bookmarked == true -> ActionState.Bookmarked
|
||||||
|
else -> ActionState.Bookmark
|
||||||
}
|
}
|
||||||
val secondaryAction = when {
|
val secondaryAction = when {
|
||||||
primaryAction != ActionState.Share && canShare -> ActionState.Share
|
primaryAction != ActionState.Share && canShare -> ActionState.Share
|
||||||
|
@ -27,11 +27,11 @@ class MainNavFragmentViewModelX(
|
|||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
// TODO add better sort/filter fields
|
// TODO add better sort/filter fields
|
||||||
|
|
||||||
var order = MutableLiveData(Order.LAST_UPDATE)
|
var order: MutableLiveData<Order> = MutableLiveData(Order.LAST_UPDATE)
|
||||||
private set
|
private set
|
||||||
var sections = MutableLiveData<Section>(Section.All)
|
var sections: MutableLiveData<Section> = MutableLiveData(Section.All)
|
||||||
private set
|
private set
|
||||||
var searchQuery = MutableLiveData("")
|
var searchQuery: MutableLiveData<String> = MutableLiveData("")
|
||||||
private set
|
private set
|
||||||
|
|
||||||
fun request(source: Source): Request {
|
fun request(source: Source): Request {
|
||||||
|
@ -13,8 +13,8 @@ import kotlinx.coroutines.withContext
|
|||||||
|
|
||||||
class RepositoriesViewModelX(val db: DatabaseX) : ViewModel() {
|
class RepositoriesViewModelX(val db: DatabaseX) : ViewModel() {
|
||||||
|
|
||||||
val repositories = MediatorLiveData<List<Repository>>()
|
val repositories: MediatorLiveData<List<Repository>> = MediatorLiveData()
|
||||||
val toLaunch = MediatorLiveData<Pair<Boolean, Long>?>()
|
val toLaunch: MediatorLiveData<Pair<Boolean, Long>?> = MediatorLiveData()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
repositories.addSource(db.repositoryDao.allLive, repositories::setValue)
|
repositories.addSource(db.repositoryDao.allLive, repositories::setValue)
|
||||||
|
@ -12,8 +12,8 @@ import kotlinx.coroutines.withContext
|
|||||||
|
|
||||||
class RepositoryViewModelX(val db: DatabaseX, val repositoryId: Long) : ViewModel() {
|
class RepositoryViewModelX(val db: DatabaseX, val repositoryId: Long) : ViewModel() {
|
||||||
|
|
||||||
val repo = MediatorLiveData<Repository>()
|
val repo: MediatorLiveData<Repository> = MediatorLiveData()
|
||||||
val appsCount = MediatorLiveData<Long>()
|
val appsCount: MediatorLiveData<Long> = MediatorLiveData()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
repo.addSource(db.repositoryDao.getLive(repositoryId), repo::setValue)
|
repo.addSource(db.repositoryDao.getLive(repositoryId), repo::setValue)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user