From 8b5ca757b32917f5afeee46a617254118bb579fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=B4=EC=8B=9C?= <67777523+EmilyCh0@users.noreply.github.com> Date: Wed, 10 Apr 2024 22:59:29 +0900 Subject: [PATCH] =?UTF-8?q?[AN/USER]=20feat:=20=ED=95=99=EA=B5=90=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=ED=99=94=EB=A9=B4=EA=B3=BC=20=EC=B6=95?= =?UTF-8?q?=EC=A0=9C=20=EC=83=81=EC=84=B8,=20=EC=95=84=ED=8B=B0=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=83=81=EC=84=B8=20=EC=97=B0=EA=B2=B0(#835)=20(#8?= =?UTF-8?q?42)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor(repository): Default 가 접두사가 되도록 변경 * refactor(FestivalSearch): 축제 검색 객체 재생성 * refactor(response): API 명세에 맞게 이름 수정 * refactor(Module): 검색 원격 저장소 주입 * fest(Module): 아티스트 저장소 주입 * fest(Festival): 축제는 학교를 가지지 않을 수 있다 * fest(artist): 아티스트 상세 응답 받기 객체 정의 * fest(festival): 7 이하는 분홍색으로 표시한다 * fest(ArtistDetailViewModel): 데이터를 비동기로 요청한다 * fest(FestivalResponse): 학교를 가지지 않을 수 있다 * refactor(ArtistDetailViewModel): 아티스트 상세 비동기 호출 코드 정리 * refactor(ArtistSearchViewHolder): 공연 개수 길이에 따라 색깔이 바뀐다 * feat: 학교 상세 화면 다른 화면과 연결 --------- Co-authored-by: vrexpert --- .../ui/schooldetail/SchoolDetailEvent.kt | 7 ++++++ .../ui/schooldetail/SchoolDetailFragment.kt | 24 +++++++++++++++++++ .../ui/schooldetail/SchoolDetailViewModel.kt | 22 ++++++++++++++++- .../ui/schooldetail/uistate/ArtistUiState.kt | 1 + .../uistate/FestivalItemUiState.kt | 1 + .../res/layout/item_school_detail_artist.xml | 1 + .../layout/item_school_detail_festival.xml | 1 + .../src/main/res/navigation/festival_list.xml | 6 +++++ 8 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/SchoolDetailEvent.kt diff --git a/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/SchoolDetailEvent.kt b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/SchoolDetailEvent.kt new file mode 100644 index 000000000..02b0420c3 --- /dev/null +++ b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/SchoolDetailEvent.kt @@ -0,0 +1,7 @@ +package com.festago.festago.presentation.ui.schooldetail + +sealed interface SchoolDetailEvent { + class ShowArtistDetail(val artistId: Long) : SchoolDetailEvent + + class ShowFestivalDetail(val festivalId: Long) : SchoolDetailEvent +} diff --git a/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/SchoolDetailFragment.kt b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/SchoolDetailFragment.kt index eb3d31fbe..5cf6f5194 100644 --- a/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/SchoolDetailFragment.kt +++ b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/SchoolDetailFragment.kt @@ -9,6 +9,7 @@ import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels +import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import com.festago.festago.presentation.databinding.FragmentSchoolDetailBinding import com.festago.festago.presentation.databinding.ItemMediaBinding @@ -50,6 +51,11 @@ class SchoolDetailFragment : Fragment() { updateUi(it) } } + repeatOnStarted(viewLifecycleOwner) { + vm.event.collect { + handleEvent(it) + } + } } private fun initView(schoolId: Long) { @@ -89,6 +95,24 @@ class SchoolDetailFragment : Fragment() { } } + private fun handleEvent(event: SchoolDetailEvent) = when (event) { + is SchoolDetailEvent.ShowArtistDetail -> { + findNavController().navigate( + SchoolDetailFragmentDirections.actionSchoolDetailFragmentToArtistDetailFragment( + event.artistId + ) + ) + } + + is SchoolDetailEvent.ShowFestivalDetail -> { + findNavController().navigate( + SchoolDetailFragmentDirections.actionSchoolDetailFragmentToFestivalDetailFragment( + event.festivalId + ) + ) + } + } + private fun startBrowser(url: String) { val intent = Intent(Intent.ACTION_VIEW) intent.data = Uri.parse(url) diff --git a/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/SchoolDetailViewModel.kt b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/SchoolDetailViewModel.kt index 562fc90f2..f6608688d 100644 --- a/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/SchoolDetailViewModel.kt +++ b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/SchoolDetailViewModel.kt @@ -11,8 +11,11 @@ import com.festago.festago.presentation.ui.schooldetail.uistate.FestivalItemUiSt import com.festago.festago.presentation.ui.schooldetail.uistate.SchoolDetailUiState 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 @@ -26,6 +29,9 @@ class SchoolDetailViewModel @Inject constructor( private val _uiState = MutableStateFlow(SchoolDetailUiState.Loading) val uiState: StateFlow = _uiState.asStateFlow() + private val _event: MutableSharedFlow = MutableSharedFlow() + val event: SharedFlow = _event.asSharedFlow() + fun loadSchoolDetail(schoolId: Long) { viewModelScope.launch { val deferredSchoolInfo = async { schoolRepository.loadSchoolInfo(schoolId) } @@ -57,8 +63,22 @@ class SchoolDetailViewModel @Inject constructor( endDate = endDate, imageUrl = imageUrl, artists = artists.map { artist -> - ArtistUiState(artist.id, artist.name, artist.imageUrl) + ArtistUiState( + id = artist.id, + name = artist.name, + imageUrl = artist.imageUrl, + onArtistDetailClick = { id -> + viewModelScope.launch { + _event.emit(SchoolDetailEvent.ShowArtistDetail(id)) + } + } + ) }, + onFestivalDetailClick = { id -> + viewModelScope.launch { + _event.emit(SchoolDetailEvent.ShowFestivalDetail(id)) + } + } ) companion object { diff --git a/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/uistate/ArtistUiState.kt b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/uistate/ArtistUiState.kt index 36f2bf4c6..e6663d81d 100644 --- a/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/uistate/ArtistUiState.kt +++ b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/uistate/ArtistUiState.kt @@ -4,4 +4,5 @@ data class ArtistUiState( val id: Long, val name: String, val imageUrl: String, + val onArtistDetailClick: (Long) -> Unit, ) diff --git a/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/uistate/FestivalItemUiState.kt b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/uistate/FestivalItemUiState.kt index 246165d63..8ee7e77a1 100644 --- a/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/uistate/FestivalItemUiState.kt +++ b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/schooldetail/uistate/FestivalItemUiState.kt @@ -9,4 +9,5 @@ data class FestivalItemUiState( val endDate: LocalDate, val imageUrl: String, val artists: List, + val onFestivalDetailClick: (Long) -> Unit, ) diff --git a/android/festago/presentation/src/main/res/layout/item_school_detail_artist.xml b/android/festago/presentation/src/main/res/layout/item_school_detail_artist.xml index 6ca1a4e3f..1c30c1a3c 100644 --- a/android/festago/presentation/src/main/res/layout/item_school_detail_artist.xml +++ b/android/festago/presentation/src/main/res/layout/item_school_detail_artist.xml @@ -11,6 +11,7 @@ diff --git a/android/festago/presentation/src/main/res/layout/item_school_detail_festival.xml b/android/festago/presentation/src/main/res/layout/item_school_detail_festival.xml index 01d39ed26..7305dc826 100644 --- a/android/festago/presentation/src/main/res/layout/item_school_detail_festival.xml +++ b/android/festago/presentation/src/main/res/layout/item_school_detail_festival.xml @@ -17,6 +17,7 @@ + +