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() {