From 38c7c74ebfdbc3dfe3be72f7d786a9d14c2df068 Mon Sep 17 00:00:00 2001 From: machiav3lli Date: Wed, 29 Jun 2022 04:06:57 +0200 Subject: [PATCH] Fix: Nullability of MutableLiveData --- .../droidify/ui/viewmodels/AppViewModelX.kt | 21 ++++++++++--------- .../viewmodels/MainNavFragmentViewModelX.kt | 6 +++--- .../ui/viewmodels/RepositoriesViewModelX.kt | 4 ++-- .../ui/viewmodels/RepositoryViewModelX.kt | 4 ++-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/com/looker/droidify/ui/viewmodels/AppViewModelX.kt b/src/main/kotlin/com/looker/droidify/ui/viewmodels/AppViewModelX.kt index d7a65348..fb67564f 100644 --- a/src/main/kotlin/com/looker/droidify/ui/viewmodels/AppViewModelX.kt +++ b/src/main/kotlin/com/looker/droidify/ui/viewmodels/AppViewModelX.kt @@ -19,20 +19,20 @@ import kotlinx.coroutines.withContext class AppViewModelX(val db: DatabaseX, val packageName: String) : ViewModel() { - val products = MediatorLiveData>() - val repositories = MediatorLiveData>() - val installedItem = MediatorLiveData() - val _productRepos = MutableLiveData>>() + val products: MediatorLiveData> = MediatorLiveData() + val repositories: MediatorLiveData> = MediatorLiveData() + val installedItem: MediatorLiveData = MediatorLiveData() + val _productRepos: MutableLiveData>> = MutableLiveData() var productRepos: List> get() = _productRepos.value ?: emptyList() set(value) { _productRepos.value = value } - val downloadState = MutableLiveData() - val mainAction = MutableLiveData() - val actions = MediatorLiveData>() - val secondaryAction = MutableLiveData() - val extras = MediatorLiveData() + val downloadState: MutableLiveData = MutableLiveData() + val mainAction: MutableLiveData = MutableLiveData() + val actions: MediatorLiveData> = MediatorLiveData() + val secondaryAction: MutableLiveData = MutableLiveData() + val extras: MediatorLiveData = MediatorLiveData() init { 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 canInstall -> ActionState.Install canShare -> ActionState.Share - else -> null + bookmarked == true -> ActionState.Bookmarked + else -> ActionState.Bookmark } val secondaryAction = when { primaryAction != ActionState.Share && canShare -> ActionState.Share diff --git a/src/main/kotlin/com/looker/droidify/ui/viewmodels/MainNavFragmentViewModelX.kt b/src/main/kotlin/com/looker/droidify/ui/viewmodels/MainNavFragmentViewModelX.kt index 269f26fe..899e806b 100644 --- a/src/main/kotlin/com/looker/droidify/ui/viewmodels/MainNavFragmentViewModelX.kt +++ b/src/main/kotlin/com/looker/droidify/ui/viewmodels/MainNavFragmentViewModelX.kt @@ -27,11 +27,11 @@ class MainNavFragmentViewModelX( ) : ViewModel() { // TODO add better sort/filter fields - var order = MutableLiveData(Order.LAST_UPDATE) + var order: MutableLiveData = MutableLiveData(Order.LAST_UPDATE) private set - var sections = MutableLiveData
(Section.All) + var sections: MutableLiveData
= MutableLiveData(Section.All) private set - var searchQuery = MutableLiveData("") + var searchQuery: MutableLiveData = MutableLiveData("") private set fun request(source: Source): Request { diff --git a/src/main/kotlin/com/looker/droidify/ui/viewmodels/RepositoriesViewModelX.kt b/src/main/kotlin/com/looker/droidify/ui/viewmodels/RepositoriesViewModelX.kt index 9cba24cb..b5d124c2 100644 --- a/src/main/kotlin/com/looker/droidify/ui/viewmodels/RepositoriesViewModelX.kt +++ b/src/main/kotlin/com/looker/droidify/ui/viewmodels/RepositoriesViewModelX.kt @@ -13,8 +13,8 @@ import kotlinx.coroutines.withContext class RepositoriesViewModelX(val db: DatabaseX) : ViewModel() { - val repositories = MediatorLiveData>() - val toLaunch = MediatorLiveData?>() + val repositories: MediatorLiveData> = MediatorLiveData() + val toLaunch: MediatorLiveData?> = MediatorLiveData() init { repositories.addSource(db.repositoryDao.allLive, repositories::setValue) diff --git a/src/main/kotlin/com/looker/droidify/ui/viewmodels/RepositoryViewModelX.kt b/src/main/kotlin/com/looker/droidify/ui/viewmodels/RepositoryViewModelX.kt index e2224189..26c85c55 100644 --- a/src/main/kotlin/com/looker/droidify/ui/viewmodels/RepositoryViewModelX.kt +++ b/src/main/kotlin/com/looker/droidify/ui/viewmodels/RepositoryViewModelX.kt @@ -12,8 +12,8 @@ import kotlinx.coroutines.withContext class RepositoryViewModelX(val db: DatabaseX, val repositoryId: Long) : ViewModel() { - val repo = MediatorLiveData() - val appsCount = MediatorLiveData() + val repo: MediatorLiveData = MediatorLiveData() + val appsCount: MediatorLiveData = MediatorLiveData() init { repo.addSource(db.repositoryDao.getLive(repositoryId), repo::setValue)