From f78d181b0dfe779a845ca10129764a510453153f Mon Sep 17 00:00:00 2001 From: Kaung Khant Soe Date: Thu, 19 Oct 2023 16:30:11 +0700 Subject: [PATCH 1/2] [#535] Update state flow to use asStateFlow --- .../nimblehq/sample/compose/ui/screens/home/HomeViewModel.kt | 4 ++-- .../template/compose/ui/screens/home/HomeViewModel.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/home/HomeViewModel.kt b/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/home/HomeViewModel.kt index 889254ecc..0ea523d99 100644 --- a/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/home/HomeViewModel.kt +++ b/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/home/HomeViewModel.kt @@ -22,10 +22,10 @@ class HomeViewModel @Inject constructor( ) : BaseViewModel() { private val _uiModels = MutableStateFlow>(emptyList()) - val uiModels: StateFlow> = _uiModels + val uiModels = _uiModels.asStateFlow() private val _isFirstTimeLaunch = MutableStateFlow(false) - val isFirstTimeLaunch: StateFlow = _isFirstTimeLaunch + val isFirstTimeLaunch = _isFirstTimeLaunch.asStateFlow() init { getModelsUseCase() diff --git a/template-compose/app/src/main/java/co/nimblehq/template/compose/ui/screens/home/HomeViewModel.kt b/template-compose/app/src/main/java/co/nimblehq/template/compose/ui/screens/home/HomeViewModel.kt index 243f48553..c906eb929 100644 --- a/template-compose/app/src/main/java/co/nimblehq/template/compose/ui/screens/home/HomeViewModel.kt +++ b/template-compose/app/src/main/java/co/nimblehq/template/compose/ui/screens/home/HomeViewModel.kt @@ -17,7 +17,7 @@ class HomeViewModel @Inject constructor( ) : BaseViewModel() { private val _uiModels = MutableStateFlow>(emptyList()) - val uiModels: StateFlow> = _uiModels + val uiModels = _uiModels.asStateFlow() init { useCase() From 1d51e5d331d944d2f2dc4e5108cafd5db1c13305 Mon Sep 17 00:00:00 2001 From: Kaung Khant Soe Date: Fri, 20 Oct 2023 11:10:15 +0700 Subject: [PATCH 2/2] [#535] Update state flow to use asStateFlow in base viewmodel classes --- .../co/nimblehq/sample/compose/ui/base/BaseViewModel.kt | 7 +++---- .../co/nimblehq/template/compose/ui/base/BaseViewModel.kt | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/base/BaseViewModel.kt b/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/base/BaseViewModel.kt index 85c95dfeb..e787f7676 100644 --- a/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/base/BaseViewModel.kt +++ b/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/base/BaseViewModel.kt @@ -2,7 +2,6 @@ package co.nimblehq.sample.compose.ui.base import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import co.nimblehq.sample.compose.lib.IsLoading import co.nimblehq.sample.compose.ui.AppDestination import kotlinx.coroutines.* import kotlinx.coroutines.flow.* @@ -15,13 +14,13 @@ abstract class BaseViewModel : ViewModel() { private var loadingCount: Int = 0 private val _isLoading = MutableStateFlow(false) - val isLoading: StateFlow = _isLoading + val isLoading = _isLoading.asStateFlow() protected val _error = MutableSharedFlow() - val error: SharedFlow = _error + val error = _error.asSharedFlow() protected val _navigator = MutableSharedFlow() - val navigator: SharedFlow = _navigator + val navigator = _navigator.asSharedFlow() /** * To show loading manually, should call `hideLoading` after diff --git a/template-compose/app/src/main/java/co/nimblehq/template/compose/ui/base/BaseViewModel.kt b/template-compose/app/src/main/java/co/nimblehq/template/compose/ui/base/BaseViewModel.kt index fc560b4ec..b6f4f4068 100644 --- a/template-compose/app/src/main/java/co/nimblehq/template/compose/ui/base/BaseViewModel.kt +++ b/template-compose/app/src/main/java/co/nimblehq/template/compose/ui/base/BaseViewModel.kt @@ -2,7 +2,6 @@ package co.nimblehq.template.compose.ui.base import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import co.nimblehq.template.compose.lib.IsLoading import co.nimblehq.template.compose.ui.AppDestination import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch @@ -15,13 +14,13 @@ abstract class BaseViewModel : ViewModel() { private var loadingCount: Int = 0 private val _isLoading = MutableStateFlow(false) - val isLoading: StateFlow = _isLoading + val isLoading = _isLoading.asStateFlow() protected val _error = MutableSharedFlow() - val error: SharedFlow = _error + val error = _error.asSharedFlow() protected val _navigator = MutableSharedFlow() - val navigator: SharedFlow = _navigator + val navigator = _navigator.asSharedFlow() /** * To show loading manually, should call `hideLoading` after