Skip to content

Commit

Permalink
[AN/USER] feat: 학교 상세 화면과 축제 상세, 아티스트 상세 연결(#835) (#842)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
EmilyCh0 and SeongHoonC authored Apr 10, 2024
1 parent 3543535 commit 8b5ca75
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -50,6 +51,11 @@ class SchoolDetailFragment : Fragment() {
updateUi(it)
}
}
repeatOnStarted(viewLifecycleOwner) {
vm.event.collect {
handleEvent(it)
}
}
}

private fun initView(schoolId: Long) {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,6 +29,9 @@ class SchoolDetailViewModel @Inject constructor(
private val _uiState = MutableStateFlow<SchoolDetailUiState>(SchoolDetailUiState.Loading)
val uiState: StateFlow<SchoolDetailUiState> = _uiState.asStateFlow()

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

fun loadSchoolDetail(schoolId: Long) {
viewModelScope.launch {
val deferredSchoolInfo = async { schoolRepository.loadSchoolInfo(schoolId) }
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ data class ArtistUiState(
val id: Long,
val name: String,
val imageUrl: String,
val onArtistDetailClick: (Long) -> Unit,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ data class FestivalItemUiState(
val endDate: LocalDate,
val imageUrl: String,
val artists: List<ArtistUiState>,
val onFestivalDetailClick: (Long) -> Unit,
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</data>

<androidx.constraintlayout.widget.ConstraintLayout
onSingleClick="@{()->artist.onArtistDetailClick.invoke(artist.id)}"
android:layout_width="66dp"
android:layout_height="66dp">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</data>

<androidx.constraintlayout.widget.ConstraintLayout
onSingleClick="@{() -> item.onFestivalDetailClick.invoke(item.id)}"
android:layout_width="match_parent"
android:layout_height="132dp"
android:layout_marginHorizontal="16dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
<argument
android:name="schoolId"
app:argType="long" />
<action
android:id="@+id/action_schoolDetailFragment_to_festivalDetailFragment"
app:destination="@id/festivalDetailFragment"
app:enterAnim="@android:anim/slide_in_left"
app:popExitAnim="@android:anim/slide_out_right" />

</fragment>
<fragment
android:id="@+id/festivalDetailFragment"
Expand Down

0 comments on commit 8b5ca75

Please sign in to comment.