Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

최근 재생한 노래 재생 #305

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
)
observeEvents()
viewModel.fetchUploadedMusics()
viewModel.fetchRecentPlayedMusics()
viewModel.fetchRecentlyPlayedMusics()
setupButtons()
}

Expand All @@ -61,10 +61,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
.build()
findNavController().navigate(request)
}

binding.ivRecentlyPlayedSong.setOnClickListener {
findNavController().navigateToPlayerScreen()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class HomeViewModel @Inject constructor(
}.launchIn(viewModelScopeWithExceptionHandler)
}

fun fetchRecentPlayedMusics() {
fun fetchRecentlyPlayedMusics() {
playlistRepository.getRecentPlaylist()
.onEach { musics ->
_uiState.update {
Expand All @@ -73,6 +73,13 @@ class HomeViewModel @Inject constructor(
}.launchIn(viewModelScopeWithExceptionHandler)
}

fun playRecentlyPlayedMusic() {
currentPlaylistUseCase.playMusics(uiState.value.recentlyPlayedMusics.first(), uiState.value.recentlyPlayedMusics)
viewModelScope.launch {
_events.emit(HomeEvent.NavigateToPlayerScreen)
}
}

override fun onClick(music: Music) {
currentPlaylistUseCase.playMusics(music, uiState.value.recentlyUploadedMusics)
viewModelScope.launch {
Expand Down
2 changes: 2 additions & 0 deletions android/feature/home/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="@dimen/small"
android:clickable="@{viewModel.uiState.firstRecentlyPlayedMusicImageUrl == null ? false : true}"
android:onClick="@{() -> viewModel.playRecentlyPlayedMusic()}"
app:imgUrl="@{viewModel.uiState.firstRecentlyPlayedMusicImageUrl}"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="@id/tv_recently_played_song"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
android:background="@drawable/btn_circle_background"
android:contentDescription="@string/play"
android:src="@drawable/ic_play"
app:tint="@color/surface"
android:onClick="@{() -> viewModel.playFromFirst()}"
app:layout_constraintBottom_toTopOf="@id/rv_playlist"
app:layout_constraintEnd_toEndOf="parent"
Expand Down