-
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.
[AN/USER] refactor: LiveData to Flow 리팩터링 (티켓 목록, 티켓 예매, 티켓 기록, 홈화면) (#…
…495) * refactor: TicketList uiState StateFlow 로 변경 * refactor: TicketListFragment 에서 uiState 를 수집하도록 변경 * refactor: TicketList 에서 event 가 sharedFlow 사용하도록 변경 * refactor: Flow 적용 테스트 리팩터링 * refactor: 티켓 제시 이벤트 테스트 리팩터링 * refactor: 티켓 예매 화면 uiState 에 StateFlow 적용 * refactor: 티켓 예매 화면 event 에 SharedFlow 적용 * refactor: 티켓 예매 화면 테스트 리팩터링 * refactor: 티켓 목록 화면 테스트 이벤트 취소 로직 추가 * refactor: 티켓 기록 화면 uiState StateFlow 로 리팩터링 * refactor: 티켓 기록 화면 테스트 리팩터링 * refactor: 홈 화면 event SharedFlow 적용 * refactor: 홈 화면 테스트 event sharedFlow 리팩터링 * refactor: 테스트에서 cancelAndIgnoreRemainingEvents 제거 * refactor: uiState 가 더 이상 nullable 하지 않음 반영
- Loading branch information
1 parent
59d81b6
commit 886d1ab
Showing
14 changed files
with
224 additions
and
183 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) | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
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
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
Oops, something went wrong.