diff --git a/feature/complete/src/main/kotlin/com/nexters/bandalart/android/feature/complete/CompleteViewModel.kt b/feature/complete/src/main/kotlin/com/nexters/bandalart/android/feature/complete/CompleteViewModel.kt index e9efde9f..76e80117 100644 --- a/feature/complete/src/main/kotlin/com/nexters/bandalart/android/feature/complete/CompleteViewModel.kt +++ b/feature/complete/src/main/kotlin/com/nexters/bandalart/android/feature/complete/CompleteViewModel.kt @@ -12,12 +12,11 @@ import com.nexters.bandalart.android.feature.complete.navigation.BANDALART_TITLE import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject import kotlinx.coroutines.Job -import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import timber.log.Timber @@ -58,8 +57,8 @@ class CompleteViewModel @Inject constructor( private val _uiState = MutableStateFlow(CompleteUiState()) val uiState: StateFlow = this._uiState.asStateFlow() - private val _eventFlow = MutableSharedFlow() - val eventFlow: SharedFlow = _eventFlow.asSharedFlow() + private val _eventChannel = Channel() + val eventFlow = _eventChannel.receiveAsFlow() init { initComplete() @@ -98,7 +97,7 @@ class CompleteViewModel @Inject constructor( result.isFailure -> { val exception = result.exceptionOrNull()!! - _eventFlow.emit(CompleteUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) + _eventChannel.send(CompleteUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) Timber.e(exception) } } @@ -112,7 +111,7 @@ class CompleteViewModel @Inject constructor( fun navigateToHome() { viewModelScope.launch { - _eventFlow.emit(CompleteUiEvent.NavigateToHome) + _eventChannel.send(CompleteUiEvent.NavigateToHome) } } } diff --git a/feature/home/src/main/kotlin/com/nexters/bandalart/android/feature/home/BandalartBottomSheetViewModel.kt b/feature/home/src/main/kotlin/com/nexters/bandalart/android/feature/home/BandalartBottomSheetViewModel.kt index 0451e105..9e747933 100644 --- a/feature/home/src/main/kotlin/com/nexters/bandalart/android/feature/home/BandalartBottomSheetViewModel.kt +++ b/feature/home/src/main/kotlin/com/nexters/bandalart/android/feature/home/BandalartBottomSheetViewModel.kt @@ -13,16 +13,15 @@ import com.nexters.bandalart.android.feature.home.model.UpdateBandalartMainCellM import com.nexters.bandalart.android.feature.home.model.UpdateBandalartSubCellModel import com.nexters.bandalart.android.feature.home.model.UpdateBandalartTaskCellModel import dagger.hilt.android.lifecycle.HiltViewModel -import javax.inject.Inject -import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import timber.log.Timber +import javax.inject.Inject /** * BottomSheetUiState @@ -65,8 +64,8 @@ class BottomSheetViewModel @Inject constructor( private val _uiState = MutableStateFlow(BottomSheetUiState()) val uiState: StateFlow = _uiState.asStateFlow() - private val _eventFlow = MutableSharedFlow() - val eventFlow: SharedFlow = _eventFlow.asSharedFlow() + private val _eventChannel = Channel() + val eventFlow = _eventChannel.receiveAsFlow() fun copyCellData(cellData: BandalartCellUiModel) { _uiState.update { @@ -102,7 +101,7 @@ class BottomSheetViewModel @Inject constructor( result.isFailure -> { val exception = result.exceptionOrNull()!! - _eventFlow.emit(BottomSheetUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) + _eventChannel.send(BottomSheetUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) Timber.e(exception.message) } } @@ -132,7 +131,7 @@ class BottomSheetViewModel @Inject constructor( result.isFailure -> { val exception = result.exceptionOrNull()!! - _eventFlow.emit(BottomSheetUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) + _eventChannel.send(BottomSheetUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) Timber.e(exception.message) } } @@ -162,7 +161,7 @@ class BottomSheetViewModel @Inject constructor( result.isFailure -> { val exception = result.exceptionOrNull()!! - _eventFlow.emit(BottomSheetUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) + _eventChannel.send(BottomSheetUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) Timber.e(exception.message) } } @@ -189,7 +188,7 @@ class BottomSheetViewModel @Inject constructor( it.copy(isCellDeleted = false) } openDeleteCellDialog(false) - _eventFlow.emit(BottomSheetUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) + _eventChannel.send(BottomSheetUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) Timber.e(exception.message) } } diff --git a/feature/home/src/main/kotlin/com/nexters/bandalart/android/feature/home/HomeViewModel.kt b/feature/home/src/main/kotlin/com/nexters/bandalart/android/feature/home/HomeViewModel.kt index aba4c452..992de764 100644 --- a/feature/home/src/main/kotlin/com/nexters/bandalart/android/feature/home/HomeViewModel.kt +++ b/feature/home/src/main/kotlin/com/nexters/bandalart/android/feature/home/HomeViewModel.kt @@ -27,12 +27,11 @@ import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.async -import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import timber.log.Timber @@ -111,8 +110,8 @@ class HomeViewModel @Inject constructor( private val _uiState = MutableStateFlow(HomeUiState()) val uiState: StateFlow = _uiState.asStateFlow() - private val _eventFlow = MutableSharedFlow() - val eventFlow: SharedFlow = _eventFlow.asSharedFlow() + private val _eventChannel = Channel() + val eventFlow = _eventChannel.receiveAsFlow() init { _uiState.update { it.copy(isShowSkeleton = true) } @@ -272,7 +271,7 @@ class HomeViewModel @Inject constructor( _uiState.update { it.copy(isNetworking = true) } viewModelScope.launch { if (_uiState.value.bandalartList.size + 1 > 5) { - _eventFlow.emit(HomeUiEvent.ShowToast(UiText.StringResource(R.string.limit_create_bandalart))) + _eventChannel.send(HomeUiEvent.ShowToast(UiText.StringResource(R.string.limit_create_bandalart))) return@launch } _uiState.update { it.copy(isShowSkeleton = true) } @@ -289,7 +288,7 @@ class HomeViewModel @Inject constructor( setRecentBandalartKey(bandalart.key) // 새로운 반다라트를 로컬에 저장 upsertBandalartKey(bandalart.key) - _eventFlow.emit(HomeUiEvent.ShowSnackbar(UiText.StringResource(R.string.create_bandalart))) + _eventChannel.send(HomeUiEvent.ShowSnackbar(UiText.StringResource(R.string.create_bandalart))) } result.isSuccess && result.getOrNull() == null -> { @@ -304,7 +303,7 @@ class HomeViewModel @Inject constructor( isShowSkeleton = false, ) } - _eventFlow.emit(HomeUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) + _eventChannel.send(HomeUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) } } _uiState.update { it.copy(isNetworking = false) } @@ -327,7 +326,7 @@ class HomeViewModel @Inject constructor( openBandalartDeleteAlertDialog(false) getBandalartList() deleteBandalartKey(bandalartKey) - _eventFlow.emit(HomeUiEvent.ShowSnackbar(UiText.StringResource(R.string.delete_bandalart))) + _eventChannel.send(HomeUiEvent.ShowSnackbar(UiText.StringResource(R.string.delete_bandalart))) } result.isSuccess && result.getOrNull() == null -> { @@ -343,7 +342,7 @@ class HomeViewModel @Inject constructor( isBandalartDeleted = false, ) } - _eventFlow.emit(HomeUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) + _eventChannel.send(HomeUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) } } _uiState.update { it.copy(isNetworking = false) } @@ -376,7 +375,7 @@ class HomeViewModel @Inject constructor( isShowSkeleton = false, ) } - _eventFlow.emit(HomeUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) + _eventChannel.send(HomeUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) } } _uiState.update { it.copy(isNetworking = false) } @@ -403,7 +402,7 @@ class HomeViewModel @Inject constructor( result.isFailure -> { val exception = result.exceptionOrNull()!! - _eventFlow.emit(HomeUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) + _eventChannel.send(HomeUiEvent.ShowToast(UiText.DirectString(exception.message.toString()))) } } _uiState.update { it.copy(isNetworking = false) } @@ -482,7 +481,7 @@ class HomeViewModel @Inject constructor( fun navigateToComplete() { viewModelScope.launch { - _eventFlow.emit( + _eventChannel.send( HomeUiEvent.NavigateToComplete( key = uiState.value.bandalartDetailData.key, title = uiState.value.bandalartDetailData.title!!, diff --git a/feature/onboarding/src/main/kotlin/com/nexters/bandalart/android/feature/onboarding/OnBoardingViewModel.kt b/feature/onboarding/src/main/kotlin/com/nexters/bandalart/android/feature/onboarding/OnBoardingViewModel.kt index 7de538f9..d50ae57c 100644 --- a/feature/onboarding/src/main/kotlin/com/nexters/bandalart/android/feature/onboarding/OnBoardingViewModel.kt +++ b/feature/onboarding/src/main/kotlin/com/nexters/bandalart/android/feature/onboarding/OnBoardingViewModel.kt @@ -4,9 +4,8 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.nexters.bandalart.android.core.domain.usecase.bandalart.SetOnboardingCompletedStatusUseCase import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.MutableSharedFlow -import kotlinx.coroutines.flow.SharedFlow -import kotlinx.coroutines.flow.asSharedFlow +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.launch import javax.inject.Inject @@ -18,8 +17,8 @@ sealed interface OnBoardingUiEvent { class OnboardingViewModel @Inject constructor( private val setOnboardingCompletedStatusUseCase: SetOnboardingCompletedStatusUseCase, ) : ViewModel() { - private val _eventFlow = MutableSharedFlow() - val eventFlow: SharedFlow = _eventFlow.asSharedFlow() + private val _eventChannel = Channel() + val eventFlow = _eventChannel.receiveAsFlow() fun setOnboardingCompletedStatus(flag: Boolean) { viewModelScope.launch { @@ -30,7 +29,7 @@ class OnboardingViewModel @Inject constructor( private fun navigateToHome() { viewModelScope.launch { - _eventFlow.emit(OnBoardingUiEvent.NavigateToHome) + _eventChannel.send(OnBoardingUiEvent.NavigateToHome) } } } diff --git a/feature/splash/src/main/kotlin/com/nexters/bandalart/android/feature/splash/SplashViewModel.kt b/feature/splash/src/main/kotlin/com/nexters/bandalart/android/feature/splash/SplashViewModel.kt index a5c31914..751f5a67 100644 --- a/feature/splash/src/main/kotlin/com/nexters/bandalart/android/feature/splash/SplashViewModel.kt +++ b/feature/splash/src/main/kotlin/com/nexters/bandalart/android/feature/splash/SplashViewModel.kt @@ -8,13 +8,12 @@ import com.nexters.bandalart.android.core.domain.usecase.login.CreateGuestLoginT import com.nexters.bandalart.android.core.domain.usecase.login.GetGuestLoginTokenUseCase import com.nexters.bandalart.android.core.domain.usecase.login.SetGuestLoginTokenUseCase import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import timber.log.Timber @@ -54,8 +53,8 @@ class SplashViewModel @Inject constructor( private val _uiState = MutableStateFlow(SplashUiState()) val uiState: StateFlow = _uiState.asStateFlow() - private val _eventFlow = MutableSharedFlow() - val eventFlow: SharedFlow = _eventFlow.asSharedFlow() + private val _eventChannel = Channel() + val eventFlow = _eventChannel.receiveAsFlow() init { viewModelScope.launch { @@ -138,13 +137,13 @@ class SplashViewModel @Inject constructor( fun navigateToOnBoarding() { viewModelScope.launch { - _eventFlow.emit(SplashUiEvent.NavigateToOnBoarding) + _eventChannel.send(SplashUiEvent.NavigateToOnBoarding) } } fun navigateToHome() { viewModelScope.launch { - _eventFlow.emit(SplashUiEvent.NavigateToHome) + _eventChannel.send(SplashUiEvent.NavigateToHome) } } }