From 9233ab945a3d80c9c33ff383cd803ab48dbbe0b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=84=9D?= Date: Thu, 2 Mar 2023 00:37:31 +0900 Subject: [PATCH] =?UTF-8?q?Issues=20#287=20feat:=20noHistory=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20=EB=B0=8F=20isLogin=20SharedFlow=20=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 1 - .../main/java/com/lighthouse/ui/MainActivity.kt | 3 +-- .../java/com/lighthouse/ui/MainViewModel.kt | 17 +++++++++++++---- .../features/setting/ui/SettingFragment.kt | 8 +++++--- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 409624cd3..5ab7b7b84 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -26,7 +26,6 @@ diff --git a/app/src/main/java/com/lighthouse/ui/MainActivity.kt b/app/src/main/java/com/lighthouse/ui/MainActivity.kt index d99468111..d9598ae1f 100644 --- a/app/src/main/java/com/lighthouse/ui/MainActivity.kt +++ b/app/src/main/java/com/lighthouse/ui/MainActivity.kt @@ -72,11 +72,10 @@ class MainActivity : AppCompatActivity() { private fun setUpIsLogin() { repeatOnStarted { - viewModel.isLogin().collect { isLogin -> + viewModel.isLoginFlow.collect { isLogin -> when (isLogin) { true -> navController.navigate(R.id.action_global_main_graph) false -> navController.navigate(R.id.action_global_intro_graph) - else -> Unit } } } diff --git a/app/src/main/java/com/lighthouse/ui/MainViewModel.kt b/app/src/main/java/com/lighthouse/ui/MainViewModel.kt index e6bd57c59..508b2dbf9 100644 --- a/app/src/main/java/com/lighthouse/ui/MainViewModel.kt +++ b/app/src/main/java/com/lighthouse/ui/MainViewModel.kt @@ -4,8 +4,9 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.lighthouse.domain.usecase.user.IsLoginUserUseCase import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.asSharedFlow +import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel @@ -13,6 +14,14 @@ internal class MainViewModel @Inject constructor( private val isLoginUserUseCase: IsLoginUserUseCase ) : ViewModel() { - fun isLogin() = isLoginUserUseCase() - .stateIn(viewModelScope, SharingStarted.Eagerly, null) + private val _isLoginFlow = MutableSharedFlow() + val isLoginFlow = _isLoginFlow.asSharedFlow() + + init { + viewModelScope.launch { + isLoginUserUseCase().collect { isLogin -> + _isLoginFlow.emit(isLogin) + } + } + } } diff --git a/features/ui-setting/src/main/java/com/lighthouse/features/setting/ui/SettingFragment.kt b/features/ui-setting/src/main/java/com/lighthouse/features/setting/ui/SettingFragment.kt index 636213de5..5dd1a1e82 100644 --- a/features/ui-setting/src/main/java/com/lighthouse/features/setting/ui/SettingFragment.kt +++ b/features/ui-setting/src/main/java/com/lighthouse/features/setting/ui/SettingFragment.kt @@ -167,9 +167,7 @@ class SettingFragment : Fragment(R.layout.fragment_setting) { SettingMenu.USED_GIFTICON -> appNavigationViewModel.navigate(AppNavigationItem.UsedGifticon) - SettingMenu.SECURITY -> - appNavigationViewModel.navigate(AppNavigationItem.Security) - + SettingMenu.SECURITY -> gotoSecurity() SettingMenu.LOCATION -> gotoLocation() SettingMenu.SIGN_IN -> signIn() SettingMenu.SIGN_OUT -> signOut() @@ -190,6 +188,10 @@ class SettingFragment : Fragment(R.layout.fragment_setting) { } } + private fun gotoSecurity() { + appNavigationViewModel.navigate(AppNavigationItem.Security) + } + private fun gotoLocation() { if ( locationPermissionManager.isGrant() ||