From e84a5438fc87f3dafe3217edf01dbf09615ee8bb Mon Sep 17 00:00:00 2001 From: youlalala Date: Thu, 7 Dec 2023 21:03:56 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EC=B5=9C=EA=B7=BC=20=EC=9E=AC?= =?UTF-8?q?=EC=83=9D=20=EB=85=B8=EB=9E=98=20=ED=81=B4=EB=A6=AD=EC=8B=9C=20?= =?UTF-8?q?=EC=B5=9C=EA=B7=BC=20=EC=9E=AC=EC=83=9D=20=EB=85=B8=EB=9E=98=20?= =?UTF-8?q?=EC=8B=A4=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ohdodok/catchytape/feature/home/HomeFragment.kt | 6 +----- .../com/ohdodok/catchytape/feature/home/HomeViewModel.kt | 9 ++++++++- .../feature/home/src/main/res/layout/fragment_home.xml | 2 ++ .../src/main/res/layout/fragment_playlist_detail.xml | 1 + 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/android/feature/home/src/main/java/com/ohdodok/catchytape/feature/home/HomeFragment.kt b/android/feature/home/src/main/java/com/ohdodok/catchytape/feature/home/HomeFragment.kt index d26d450..0796204 100644 --- a/android/feature/home/src/main/java/com/ohdodok/catchytape/feature/home/HomeFragment.kt +++ b/android/feature/home/src/main/java/com/ohdodok/catchytape/feature/home/HomeFragment.kt @@ -34,7 +34,7 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) { ) observeEvents() viewModel.fetchUploadedMusics() - viewModel.fetchRecentPlayedMusics() + viewModel.fetchRecentlyPlayedMusics() setupButtons() } @@ -61,10 +61,6 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) { .build() findNavController().navigate(request) } - - binding.ivRecentlyPlayedSong.setOnClickListener { - findNavController().navigateToPlayerScreen() - } } } diff --git a/android/feature/home/src/main/java/com/ohdodok/catchytape/feature/home/HomeViewModel.kt b/android/feature/home/src/main/java/com/ohdodok/catchytape/feature/home/HomeViewModel.kt index 7eef40c..eb778dc 100644 --- a/android/feature/home/src/main/java/com/ohdodok/catchytape/feature/home/HomeViewModel.kt +++ b/android/feature/home/src/main/java/com/ohdodok/catchytape/feature/home/HomeViewModel.kt @@ -64,7 +64,7 @@ class HomeViewModel @Inject constructor( }.launchIn(viewModelScopeWithExceptionHandler) } - fun fetchRecentPlayedMusics() { + fun fetchRecentlyPlayedMusics() { playlistRepository.getRecentPlaylist() .onEach { musics -> _uiState.update { @@ -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 { diff --git a/android/feature/home/src/main/res/layout/fragment_home.xml b/android/feature/home/src/main/res/layout/fragment_home.xml index 3fc176b..a0ca57b 100644 --- a/android/feature/home/src/main/res/layout/fragment_home.xml +++ b/android/feature/home/src/main/res/layout/fragment_home.xml @@ -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" diff --git a/android/feature/playlist/src/main/res/layout/fragment_playlist_detail.xml b/android/feature/playlist/src/main/res/layout/fragment_playlist_detail.xml index c3d6ee4..4fc8430 100644 --- a/android/feature/playlist/src/main/res/layout/fragment_playlist_detail.xml +++ b/android/feature/playlist/src/main/res/layout/fragment_playlist_detail.xml @@ -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"