From e4f24eaaed87f040fd3e99c23f5809ddbcb0639c Mon Sep 17 00:00:00 2001 From: 2taezeat Date: Wed, 13 Dec 2023 13:36:36 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20MyPage=20->=20Player=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99=20=EB=B0=8F,=20=EA=B0=9C=ED=96=89=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchytape/feature/mypage/MyPageFragment.kt | 15 ++++++++++++++- .../catchytape/feature/mypage/MyPageViewModel.kt | 13 ++++++++++++- .../catchytape/feature/search/SearchFragment.kt | 4 ---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/android/feature/mypage/src/main/java/com/ohdodok/catchytape/feature/mypage/MyPageFragment.kt b/android/feature/mypage/src/main/java/com/ohdodok/catchytape/feature/mypage/MyPageFragment.kt index e50328e..9400845 100644 --- a/android/feature/mypage/src/main/java/com/ohdodok/catchytape/feature/mypage/MyPageFragment.kt +++ b/android/feature/mypage/src/main/java/com/ohdodok/catchytape/feature/mypage/MyPageFragment.kt @@ -5,6 +5,7 @@ import android.view.View import androidx.core.net.toUri import androidx.core.view.ViewCompat import androidx.fragment.app.viewModels +import androidx.navigation.NavController import androidx.navigation.NavDeepLinkRequest import androidx.navigation.fragment.findNavController import com.ohdodok.catchytape.core.ui.BaseFragment @@ -37,6 +38,9 @@ class MyPageFragment : BaseFragment(R.layout.fragment_my_ is MyPageEvent.ShowMessage -> { showMessage(event.error.toMessageId()) } + is MyPageEvent.NavigateToPlayerScreen -> { + findNavController().navigateToPlayerScreen() + } } } } @@ -56,11 +60,20 @@ class MyPageFragment : BaseFragment(R.layout.fragment_my_ } private fun setupRecyclerView() { - binding.rvMusics.adapter = MusicAdapter(Orientation.VERTICAL) + binding.rvMusics.adapter = MusicAdapter( + musicItemOrientation = Orientation.VERTICAL, + listener = viewModel + ) } override fun onStart() { super.onStart() viewModel.fetchMyMusics(count = 3) } +} + +private fun NavController.navigateToPlayerScreen() { + val request = + NavDeepLinkRequest.Builder.fromUri("android-app://com.ohdodok.catchytape/player_fragment".toUri()).build() + navigate(request) } \ No newline at end of file diff --git a/android/feature/mypage/src/main/java/com/ohdodok/catchytape/feature/mypage/MyPageViewModel.kt b/android/feature/mypage/src/main/java/com/ohdodok/catchytape/feature/mypage/MyPageViewModel.kt index 0489d25..e7d4ac3 100644 --- a/android/feature/mypage/src/main/java/com/ohdodok/catchytape/feature/mypage/MyPageViewModel.kt +++ b/android/feature/mypage/src/main/java/com/ohdodok/catchytape/feature/mypage/MyPageViewModel.kt @@ -6,6 +6,8 @@ import com.ohdodok.catchytape.core.domain.model.CtErrorType import com.ohdodok.catchytape.core.domain.model.CtException import com.ohdodok.catchytape.core.domain.model.Music import com.ohdodok.catchytape.core.domain.repository.MusicRepository +import com.ohdodok.catchytape.core.domain.usecase.player.CurrentPlaylistUseCase +import com.ohdodok.catchytape.core.ui.MusicAdapter import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.flow.MutableSharedFlow @@ -28,7 +30,8 @@ data class MyPageUiState( @HiltViewModel class MyPageViewModel @Inject constructor( private val musicRepository: MusicRepository, -) : ViewModel() { + private val currentPlaylistUseCase: CurrentPlaylistUseCase, +) : ViewModel(), MusicAdapter.Listener { private val _uiState = MutableStateFlow(MyPageUiState()) val uiState: StateFlow = _uiState.asStateFlow() @@ -55,8 +58,16 @@ class MyPageViewModel @Inject constructor( } .launchIn(viewModelScopeWithExceptionHandler) } + + override fun onClick(music: Music) { + currentPlaylistUseCase.playMusic(music) + viewModelScope.launch { + _events.emit(MyPageEvent.NavigateToPlayerScreen) + } + } } sealed interface MyPageEvent { data class ShowMessage(val error: CtErrorType) : MyPageEvent + data object NavigateToPlayerScreen : MyPageEvent } \ No newline at end of file diff --git a/android/feature/search/src/main/java/com/ohdodok/catchytape/feature/search/SearchFragment.kt b/android/feature/search/src/main/java/com/ohdodok/catchytape/feature/search/SearchFragment.kt index ed9baa7..59fe7a8 100644 --- a/android/feature/search/src/main/java/com/ohdodok/catchytape/feature/search/SearchFragment.kt +++ b/android/feature/search/src/main/java/com/ohdodok/catchytape/feature/search/SearchFragment.kt @@ -19,19 +19,15 @@ import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class SearchFragment : BaseFragment(R.layout.fragment_search) { - private val viewModel: SearchViewModel by viewModels() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) ViewCompat.setOnApplyWindowInsetsListener(binding.root, RootViewInsetsCallback()) - binding.viewModel = viewModel - observeEvents() setupRecyclerView() - } private fun setupRecyclerView() {