Skip to content

Commit

Permalink
feat : MyPage -> Player 이동 및, 개행 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
2taezeat committed Dec 13, 2023
1 parent a523b65 commit e4f24ea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,6 +38,9 @@ class MyPageFragment : BaseFragment<FragmentMyPageBinding>(R.layout.fragment_my_
is MyPageEvent.ShowMessage -> {
showMessage(event.error.toMessageId())
}
is MyPageEvent.NavigateToPlayerScreen -> {
findNavController().navigateToPlayerScreen()
}
}
}
}
Expand All @@ -56,11 +60,20 @@ class MyPageFragment : BaseFragment<FragmentMyPageBinding>(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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<MyPageUiState> = _uiState.asStateFlow()
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@ import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class SearchFragment : BaseFragment<FragmentSearchBinding>(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() {
Expand Down

0 comments on commit e4f24ea

Please sign in to comment.