-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2493969
commit 8c25373
Showing
2 changed files
with
23 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 14 additions & 9 deletions
23
android/festago/app/src/main/java/com/festago/festago/presentation/ui/home/HomeViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,32 @@ | ||
package com.festago.festago.presentation.ui.home | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.festago.festago.presentation.ui.home.HomeItemType.FESTIVAL_LIST | ||
import com.festago.festago.presentation.ui.home.HomeItemType.MY_PAGE | ||
import com.festago.festago.presentation.ui.home.HomeItemType.TICKET_LIST | ||
import com.festago.festago.presentation.util.MutableSingleLiveData | ||
import com.festago.festago.presentation.util.SingleLiveData | ||
import com.festago.festago.repository.AuthRepository | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.SharedFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class HomeViewModel @Inject constructor(private val authRepository: AuthRepository) : ViewModel() { | ||
|
||
private val _event = MutableSingleLiveData<HomeEvent>() | ||
val event: SingleLiveData<HomeEvent> = _event | ||
private val _event = MutableSharedFlow<HomeEvent>() | ||
val event: SharedFlow<HomeEvent> = _event.asSharedFlow() | ||
|
||
fun loadHomeItem(homeItemType: HomeItemType) { | ||
when { | ||
homeItemType == FESTIVAL_LIST -> _event.setValue(HomeEvent.ShowFestivalList) | ||
!authRepository.isSigned -> _event.setValue(HomeEvent.ShowSignIn) | ||
homeItemType == TICKET_LIST -> _event.setValue(HomeEvent.ShowTicketList) | ||
homeItemType == MY_PAGE -> _event.setValue(HomeEvent.ShowMyPage) | ||
viewModelScope.launch { | ||
when { | ||
homeItemType == FESTIVAL_LIST -> _event.emit(HomeEvent.ShowFestivalList) | ||
!authRepository.isSigned -> _event.emit(HomeEvent.ShowSignIn) | ||
homeItemType == TICKET_LIST -> _event.emit(HomeEvent.ShowTicketList) | ||
homeItemType == MY_PAGE -> _event.emit(HomeEvent.ShowMyPage) | ||
} | ||
} | ||
} | ||
} |