From 63d32b28d44074372b2b0d5b6b0036fc55ebc36e Mon Sep 17 00:00:00 2001 From: algosketch Date: Tue, 12 Dec 2023 10:50:14 +0900 Subject: [PATCH 1/4] =?UTF-8?q?fix=20:=20=EB=B0=94=ED=85=80=20=EC=9E=AC?= =?UTF-8?q?=EC=83=9D=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=EA=B0=80=20?= =?UTF-8?q?=EC=9D=98=EB=8F=84=EC=B9=98=20=EC=95=8A=EA=B2=8C=20=ED=91=9C?= =?UTF-8?q?=EC=8B=9C=EB=90=98=EB=8A=94=20=EB=B2=84=EA=B7=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/src/main/java/com/ohdodok/catchytape/MainActivity.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/ohdodok/catchytape/MainActivity.kt b/android/app/src/main/java/com/ohdodok/catchytape/MainActivity.kt index 89d1968..d4a5191 100644 --- a/android/app/src/main/java/com/ohdodok/catchytape/MainActivity.kt +++ b/android/app/src/main/java/com/ohdodok/catchytape/MainActivity.kt @@ -102,7 +102,8 @@ class MainActivity : AppCompatActivity() { navHostFragment.findNavController().addOnDestinationChangedListener { _, destination, _ -> when (destination.id) { - com.ohdodok.catchytape.feature.player.R.id.player_fragment -> { + com.ohdodok.catchytape.feature.player.R.id.player_fragment, + com.ohdodok.catchytape.feature.player.R.id.playlist_bottom_sheet -> { hideBottomNav() hidePlayerController() } From a722b2e842312242a869f921f3335d3cfebf08cd Mon Sep 17 00:00:00 2001 From: algosketch Date: Tue, 12 Dec 2023 11:07:23 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat=20:=20=EB=B0=94=ED=85=80=EC=8B=9C?= =?UTF-8?q?=ED=8A=B8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchytape/core/ui/PlaylistBottomSheet.kt | 23 +++++++++++++++---- .../core/ui/PlaylistBottomSheetViewModel.kt | 12 +++++++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheet.kt b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheet.kt index beefc37..6cd2454 100644 --- a/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheet.kt +++ b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheet.kt @@ -4,12 +4,15 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.annotation.StringRes import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import androidx.navigation.fragment.findNavController import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import com.google.android.material.snackbar.Snackbar +import com.ohdodok.catchytape.core.ui.cterror.toMessageId import com.ohdodok.catchytape.core.ui.databinding.BottomSheetPlaylistBinding import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.launch @@ -31,21 +34,33 @@ class PlaylistBottomSheet : BottomSheetDialogFragment() { binding.viewModel = viewModel binding.rvPlaylists.adapter = PlaylistAdapter() - observeEvent() + observeEvents() return binding.root } - private fun observeEvent() { + private fun observeEvents() { viewLifecycleOwner.lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { - viewModel.closeEvent.collect { - findNavController().popBackStack() + viewModel.events.collect { event -> + when (event) { + is PlaylistBottomSheetEvent.Close -> { + findNavController().popBackStack() + } + + is PlaylistBottomSheetEvent.ShowMessage -> { + showMessage(event.error.toMessageId()) + } + } } } } } + private fun showMessage(@StringRes messageId: Int) { + Snackbar.make(this.requireView(), messageId, Snackbar.LENGTH_LONG).show() + } + override fun onDestroyView() { super.onDestroyView() _binding = null diff --git a/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheetViewModel.kt b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheetViewModel.kt index 32da440..01f5829 100644 --- a/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheetViewModel.kt +++ b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheetViewModel.kt @@ -3,6 +3,7 @@ package com.ohdodok.catchytape.core.ui import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.ohdodok.catchytape.core.domain.model.CtErrorType import com.ohdodok.catchytape.core.domain.model.Playlist import com.ohdodok.catchytape.core.domain.repository.PlaylistRepository import com.ohdodok.catchytape.core.ui.model.PlaylistUiModel @@ -17,6 +18,11 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import javax.inject.Inject +sealed interface PlaylistBottomSheetEvent { + data object Close : PlaylistBottomSheetEvent + data class ShowMessage(val error: CtErrorType) : PlaylistBottomSheetEvent +} + @HiltViewModel class PlaylistBottomSheetViewModel @Inject constructor( savedStateHandle: SavedStateHandle, @@ -30,8 +36,8 @@ class PlaylistBottomSheetViewModel @Inject constructor( private val _playlists = MutableStateFlow(emptyList()) val playlists: StateFlow> = _playlists.asStateFlow() - private val _closeEvent = MutableSharedFlow() - val closeEvent: SharedFlow = _closeEvent.asSharedFlow() + private val _events = MutableSharedFlow() + val events: SharedFlow = _events.asSharedFlow() init { fetchPlaylists() @@ -46,7 +52,7 @@ class PlaylistBottomSheetViewModel @Inject constructor( private fun addMusicToPlaylist(playlistId: Int, musicId: String) { viewModelScope.launch { playlistRepository.addMusicToPlaylist(playlistId = playlistId, musicId = musicId) - _closeEvent.emit(Unit) + _events.emit(PlaylistBottomSheetEvent.Close) } } From 2dbd3df1cdc984d830d6fb274bc781455c0d05d2 Mon Sep 17 00:00:00 2001 From: algosketch Date: Tue, 12 Dec 2023 11:10:00 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix=20:=20=EC=A4=91=EB=B3=B5=EB=90=9C=20?= =?UTF-8?q?=EC=9D=8C=EC=95=85=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/ui/PlaylistBottomSheetViewModel.kt | 12 +++++++++++- android/core/ui/src/main/res/values/strings.xml | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheetViewModel.kt b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheetViewModel.kt index 01f5829..7d1d1ef 100644 --- a/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheetViewModel.kt +++ b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheetViewModel.kt @@ -4,10 +4,12 @@ import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ohdodok.catchytape.core.domain.model.CtErrorType +import com.ohdodok.catchytape.core.domain.model.CtException import com.ohdodok.catchytape.core.domain.model.Playlist import com.ohdodok.catchytape.core.domain.repository.PlaylistRepository import com.ohdodok.catchytape.core.ui.model.PlaylistUiModel import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharedFlow @@ -39,6 +41,14 @@ class PlaylistBottomSheetViewModel @Inject constructor( private val _events = MutableSharedFlow() val events: SharedFlow = _events.asSharedFlow() + private val exceptionHandler = CoroutineExceptionHandler { _, throwable -> + val errorType = + if (throwable is CtException) throwable.ctError + else CtErrorType.UN_KNOWN + + viewModelScope.launch { _events.emit(PlaylistBottomSheetEvent.ShowMessage(errorType)) } + } + init { fetchPlaylists() } @@ -50,7 +60,7 @@ class PlaylistBottomSheetViewModel @Inject constructor( } private fun addMusicToPlaylist(playlistId: Int, musicId: String) { - viewModelScope.launch { + viewModelScope.launch(exceptionHandler) { playlistRepository.addMusicToPlaylist(playlistId = playlistId, musicId = musicId) _events.emit(PlaylistBottomSheetEvent.Close) } diff --git a/android/core/ui/src/main/res/values/strings.xml b/android/core/ui/src/main/res/values/strings.xml index 7fa5418..44e45c5 100644 --- a/android/core/ui/src/main/res/values/strings.xml +++ b/android/core/ui/src/main/res/values/strings.xml @@ -48,7 +48,7 @@ 서버가 작업 중이에요. 잠시만 기다려주세요. "error_message_not_exist_playlist_on_user" "error_message_not_exist_music" - "error_message_already_added" + 이미 추가된 음악이에요. "error_message_invalid_input_value" "error_message_not_exist_user" 이미 회원가입이 완료된 이메일이에요 ! From a3656ad4b276a067ead5133b2b0b6c00dc1e199b Mon Sep 17 00:00:00 2001 From: algosketch Date: Tue, 12 Dec 2023 11:18:08 +0900 Subject: [PATCH 4/4] =?UTF-8?q?feat=20:=20=EC=9D=8C=EC=95=85=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EC=84=B1=EA=B3=B5=EC=8B=9C=20=EB=A9=94=EC=8B=9C?= =?UTF-8?q?=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ohdodok/catchytape/core/ui/PlaylistBottomSheet.kt | 7 ++++--- .../catchytape/core/ui/PlaylistBottomSheetViewModel.kt | 4 ++-- android/core/ui/src/main/res/values/strings.xml | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheet.kt b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheet.kt index 6cd2454..1d8e0bd 100644 --- a/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheet.kt +++ b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheet.kt @@ -4,6 +4,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Toast import androidx.annotation.StringRes import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle @@ -11,7 +12,6 @@ import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import androidx.navigation.fragment.findNavController import com.google.android.material.bottomsheet.BottomSheetDialogFragment -import com.google.android.material.snackbar.Snackbar import com.ohdodok.catchytape.core.ui.cterror.toMessageId import com.ohdodok.catchytape.core.ui.databinding.BottomSheetPlaylistBinding import dagger.hilt.android.AndroidEntryPoint @@ -44,7 +44,8 @@ class PlaylistBottomSheet : BottomSheetDialogFragment() { repeatOnLifecycle(Lifecycle.State.STARTED) { viewModel.events.collect { event -> when (event) { - is PlaylistBottomSheetEvent.Close -> { + is PlaylistBottomSheetEvent.Success -> { + showMessage(R.string.add_to_playlist_success) findNavController().popBackStack() } @@ -58,7 +59,7 @@ class PlaylistBottomSheet : BottomSheetDialogFragment() { } private fun showMessage(@StringRes messageId: Int) { - Snackbar.make(this.requireView(), messageId, Snackbar.LENGTH_LONG).show() + Toast.makeText(requireActivity(), messageId, Toast.LENGTH_SHORT).show() } override fun onDestroyView() { diff --git a/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheetViewModel.kt b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheetViewModel.kt index 7d1d1ef..f01afa4 100644 --- a/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheetViewModel.kt +++ b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheetViewModel.kt @@ -21,7 +21,7 @@ import kotlinx.coroutines.launch import javax.inject.Inject sealed interface PlaylistBottomSheetEvent { - data object Close : PlaylistBottomSheetEvent + data object Success : PlaylistBottomSheetEvent data class ShowMessage(val error: CtErrorType) : PlaylistBottomSheetEvent } @@ -62,7 +62,7 @@ class PlaylistBottomSheetViewModel @Inject constructor( private fun addMusicToPlaylist(playlistId: Int, musicId: String) { viewModelScope.launch(exceptionHandler) { playlistRepository.addMusicToPlaylist(playlistId = playlistId, musicId = musicId) - _events.emit(PlaylistBottomSheetEvent.Close) + _events.emit(PlaylistBottomSheetEvent.Success) } } diff --git a/android/core/ui/src/main/res/values/strings.xml b/android/core/ui/src/main/res/values/strings.xml index 44e45c5..249df7a 100644 --- a/android/core/ui/src/main/res/values/strings.xml +++ b/android/core/ui/src/main/res/values/strings.xml @@ -37,6 +37,7 @@ 트랙 %d개 재생 목록에 노래 추가 + 노래를 추가했어요. "error_message_connection" "error_message_ssl_hand_shake"