Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into feat/#478
Browse files Browse the repository at this point in the history
# Conflicts:
#	backend/src/test/java/com/festago/support/SetUpMockito.java
  • Loading branch information
xxeol2 committed Oct 6, 2023
2 parents d850d2c + 610915a commit c6c6e8c
Show file tree
Hide file tree
Showing 49 changed files with 858 additions and 510 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.festago.festago.presentation.ui.home.festivallist.FestivalListFragmen
import com.festago.festago.presentation.ui.home.mypage.MyPageFragment
import com.festago.festago.presentation.ui.home.ticketlist.TicketListFragment
import com.festago.festago.presentation.ui.signin.SignInActivity
import com.festago.festago.presentation.util.repeatOnStarted
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand Down Expand Up @@ -48,12 +49,14 @@ class HomeActivity : AppCompatActivity() {
}

private fun initObserve() {
vm.event.observe(this) { event ->
when (event) {
is HomeEvent.ShowFestivalList -> showFestivalList()
is HomeEvent.ShowTicketList -> showTicketList()
is HomeEvent.ShowMyPage -> showMyPage()
is HomeEvent.ShowSignIn -> showSignIn()
repeatOnStarted(this) {
vm.event.collect { event ->
when (event) {
is HomeEvent.ShowFestivalList -> showFestivalList()
is HomeEvent.ShowTicketList -> showTicketList()
is HomeEvent.ShowMyPage -> showMyPage()
is HomeEvent.ShowSignIn -> showSignIn()
}
}
}
}
Expand Down
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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.festago.festago.R
import com.festago.festago.databinding.FragmentFestivalListBinding
import com.festago.festago.presentation.ui.home.ticketlist.TicketListFragment
import com.festago.festago.presentation.ui.ticketreserve.TicketReserveActivity
import com.festago.festago.presentation.util.repeatOnStarted
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand Down Expand Up @@ -38,12 +39,16 @@ class FestivalListFragment : Fragment(R.layout.fragment_festival_list) {
}

private fun initObserve() {
vm.uiState.observe(viewLifecycleOwner) {
binding.uiState = it
updateUi(it)
repeatOnStarted(viewLifecycleOwner) {
vm.uiState.collect {
binding.uiState = it
updateUi(it)
}
}
vm.event.observe(viewLifecycleOwner) {
handleEvent(it)
repeatOnStarted(viewLifecycleOwner) {
vm.event.collect {
handleEvent(it)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.festago.festago.presentation.ui.home.festivallist

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.festago.festago.analytics.AnalyticsHelper
import com.festago.festago.analytics.logNetworkFailure
import com.festago.festago.presentation.ui.home.festivallist.FestivalListEvent.ShowTicketReserve
import com.festago.festago.presentation.util.MutableSingleLiveData
import com.festago.festago.presentation.util.SingleLiveData
import com.festago.festago.repository.FestivalRepository
import dagger.hilt.android.lifecycle.HiltViewModel
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.launch
import javax.inject.Inject

Expand All @@ -19,11 +21,12 @@ class FestivalListViewModel @Inject constructor(
private val festivalRepository: FestivalRepository,
private val analyticsHelper: AnalyticsHelper,
) : ViewModel() {
private val _uiState = MutableLiveData<FestivalListUiState>(FestivalListUiState.Loading)
val uiState: LiveData<FestivalListUiState> = _uiState

private val _event = MutableSingleLiveData<FestivalListEvent>()
val event: SingleLiveData<FestivalListEvent> = _event
private val _uiState = MutableStateFlow<FestivalListUiState>(FestivalListUiState.Loading)
val uiState: StateFlow<FestivalListUiState> = _uiState.asStateFlow()

private val _event = MutableSharedFlow<FestivalListEvent>()
val event: SharedFlow<FestivalListEvent> = _event.asSharedFlow()

fun loadFestivals() {
viewModelScope.launch {
Expand All @@ -49,7 +52,9 @@ class FestivalListViewModel @Inject constructor(
}

fun showTicketReserve(festivalId: Long) {
_event.setValue(ShowTicketReserve(festivalId))
viewModelScope.launch {
_event.emit(ShowTicketReserve(festivalId))
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.festago.festago.presentation.ui.home.HomeActivity
import com.festago.festago.presentation.ui.selectschool.SelectSchoolActivity
import com.festago.festago.presentation.ui.signin.SignInActivity
import com.festago.festago.presentation.ui.tickethistory.TicketHistoryActivity
import com.festago.festago.presentation.util.repeatOnStarted
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand Down Expand Up @@ -40,26 +41,38 @@ class MyPageFragment : Fragment(R.layout.fragment_my_page) {
}

private fun initObserve() {
vm.uiState.observe(viewLifecycleOwner) { uiState ->
binding.uiState = uiState
when (uiState) {
is MyPageUiState.Loading, is MyPageUiState.Error -> Unit

is MyPageUiState.Success -> handleSuccess(uiState)
repeatOnStarted(viewLifecycleOwner) {
vm.uiState.collect { uiState ->
handleUiState(uiState)
}
binding.srlMyPage.isRefreshing = false
}
vm.event.observe(viewLifecycleOwner) { event ->
when (event) {
is MyPageEvent.ShowSignIn -> handleShowSignInEvent()
is MyPageEvent.SignOutSuccess -> handleSignOutSuccessEvent()
is MyPageEvent.DeleteAccountSuccess -> handleDeleteAccountSuccess()
is MyPageEvent.ShowTicketHistory -> handleShowTicketHistory()
is MyPageEvent.ShowConfirmDelete -> handleShowConfirmDelete()
repeatOnStarted(viewLifecycleOwner) {
vm.event.collect { event ->
handleEvent(event)
}
}
}

private fun handleUiState(uiState: MyPageUiState) {
binding.uiState = uiState
when (uiState) {
is MyPageUiState.Loading, is MyPageUiState.Error -> Unit

is MyPageUiState.Success -> handleSuccess(uiState)
}
binding.srlMyPage.isRefreshing = false
}

private fun handleEvent(event: MyPageEvent) {
when (event) {
is MyPageEvent.ShowSignIn -> handleShowSignInEvent()
is MyPageEvent.SignOutSuccess -> handleSignOutSuccessEvent()
is MyPageEvent.DeleteAccountSuccess -> handleDeleteAccountSuccess()
is MyPageEvent.ShowTicketHistory -> handleShowTicketHistory()
is MyPageEvent.ShowConfirmDelete -> handleShowConfirmDelete()
}
}

private fun handleShowSignInEvent() {
startActivity(SignInActivity.getIntent(requireContext()))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.festago.festago.presentation.ui.home.mypage

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.festago.festago.analytics.AnalyticsHelper
import com.festago.festago.analytics.logNetworkFailure
import com.festago.festago.presentation.util.MutableSingleLiveData
import com.festago.festago.presentation.util.SingleLiveData
import com.festago.festago.repository.AuthRepository
import com.festago.festago.repository.TicketRepository
import com.festago.festago.repository.UserRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.async
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.launch
import javax.inject.Inject

Expand All @@ -24,16 +26,18 @@ class MyPageViewModel @Inject constructor(
private val analyticsHelper: AnalyticsHelper,
) : ViewModel() {

private val _uiState = MutableLiveData<MyPageUiState>(MyPageUiState.Loading)
val uiState: LiveData<MyPageUiState> = _uiState
private val _uiState = MutableStateFlow<MyPageUiState>(MyPageUiState.Loading)
val uiState: StateFlow<MyPageUiState> = _uiState.asStateFlow()

private val _event = MutableSingleLiveData<MyPageEvent>()
val event: SingleLiveData<MyPageEvent> = _event
private val _event = MutableSharedFlow<MyPageEvent>()
val event: SharedFlow<MyPageEvent> = _event.asSharedFlow()

fun loadUserInfo() {
if (!authRepository.isSigned) {
_event.setValue(MyPageEvent.ShowSignIn)
_uiState.value = MyPageUiState.Error
viewModelScope.launch {
_event.emit(MyPageEvent.ShowSignIn)
_uiState.value = MyPageUiState.Error
}
return
}
viewModelScope.launch {
Expand All @@ -59,7 +63,7 @@ class MyPageViewModel @Inject constructor(
viewModelScope.launch {
authRepository.signOut()
.onSuccess {
_event.setValue(MyPageEvent.SignOutSuccess)
_event.emit(MyPageEvent.SignOutSuccess)
_uiState.value = MyPageUiState.Error
}.onFailure {
_uiState.value = MyPageUiState.Error
Expand All @@ -72,14 +76,16 @@ class MyPageViewModel @Inject constructor(
}

fun showConfirmDelete() {
_event.setValue(MyPageEvent.ShowConfirmDelete)
viewModelScope.launch {
_event.emit(MyPageEvent.ShowConfirmDelete)
}
}

fun deleteAccount() {
viewModelScope.launch {
authRepository.deleteAccount()
.onSuccess {
_event.setValue(MyPageEvent.DeleteAccountSuccess)
_event.emit(MyPageEvent.DeleteAccountSuccess)
_uiState.value = MyPageUiState.Error
}.onFailure {
_uiState.value = MyPageUiState.Error
Expand All @@ -92,7 +98,9 @@ class MyPageViewModel @Inject constructor(
}

fun showTicketHistory() {
_event.setValue(MyPageEvent.ShowTicketHistory)
viewModelScope.launch {
_event.emit(MyPageEvent.ShowTicketHistory)
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.fragment.app.viewModels
import com.festago.festago.R
import com.festago.festago.databinding.FragmentTicketListBinding
import com.festago.festago.presentation.ui.ticketentry.TicketEntryActivity
import com.festago.festago.presentation.util.repeatOnStarted
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand Down Expand Up @@ -44,12 +45,16 @@ class TicketListFragment : Fragment(R.layout.fragment_ticket_list) {
}

private fun initObserve() {
vm.uiState.observe(viewLifecycleOwner) {
binding.uiState = it
updateUi(it)
repeatOnStarted(viewLifecycleOwner) {
vm.uiState.collect {
binding.uiState = it
updateUi(it)
}
}
vm.event.observe(viewLifecycleOwner) { event ->
handleEvent(event)
repeatOnStarted(viewLifecycleOwner) {
vm.event.collect { event ->
handleEvent(event)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.festago.festago.presentation.ui.home.ticketlist

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.festago.festago.analytics.AnalyticsHelper
import com.festago.festago.analytics.logNetworkFailure
import com.festago.festago.presentation.util.MutableSingleLiveData
import com.festago.festago.presentation.util.SingleLiveData
import com.festago.festago.repository.TicketRepository
import dagger.hilt.android.lifecycle.HiltViewModel
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.launch
import javax.inject.Inject

Expand All @@ -19,11 +21,11 @@ class TicketListViewModel @Inject constructor(
private val analyticsHelper: AnalyticsHelper,
) : ViewModel() {

private val _uiState = MutableLiveData<TicketListUiState>(TicketListUiState.Loading)
val uiState: LiveData<TicketListUiState> = _uiState
private val _uiState = MutableStateFlow<TicketListUiState>(TicketListUiState.Loading)
val uiState: StateFlow<TicketListUiState> = _uiState.asStateFlow()

private val _event = MutableSingleLiveData<TicketListEvent>()
val event: SingleLiveData<TicketListEvent> = _event
private val _event = MutableSharedFlow<TicketListEvent>()
val event: SharedFlow<TicketListEvent> = _event.asSharedFlow()

fun loadCurrentTickets() {
viewModelScope.launch {
Expand All @@ -40,7 +42,9 @@ class TicketListViewModel @Inject constructor(
}

fun showTicketEntry(ticketId: Long) {
_event.setValue(TicketListEvent.ShowTicketEntry(ticketId))
viewModelScope.launch {
_event.emit(TicketListEvent.ShowTicketEntry(ticketId))
}
}

companion object {
Expand Down
Loading

0 comments on commit c6c6e8c

Please sign in to comment.