From f87ee249eeb6c49bf9bba489d5576f831c118225 Mon Sep 17 00:00:00 2001 From: algosketch Date: Wed, 6 Dec 2023 23:16:54 +0900 Subject: [PATCH 01/11] =?UTF-8?q?feat=20:=20=EB=B0=94=ED=85=80=20=EC=8B=9C?= =?UTF-8?q?=ED=8A=B8=20=EB=A7=88=ED=81=AC=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/res/layout/bottom_sheet_playlist.xml | 52 +++++++++++++++++++ .../core/ui/src/main/res/values/strings.xml | 1 + 2 files changed, 53 insertions(+) create mode 100644 android/core/ui/src/main/res/layout/bottom_sheet_playlist.xml diff --git a/android/core/ui/src/main/res/layout/bottom_sheet_playlist.xml b/android/core/ui/src/main/res/layout/bottom_sheet_playlist.xml new file mode 100644 index 0000000..8bdd633 --- /dev/null +++ b/android/core/ui/src/main/res/layout/bottom_sheet_playlist.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/core/ui/src/main/res/values/strings.xml b/android/core/ui/src/main/res/values/strings.xml index 08c39f6..6407098 100644 --- a/android/core/ui/src/main/res/values/strings.xml +++ b/android/core/ui/src/main/res/values/strings.xml @@ -53,5 +53,6 @@ "error_message_not_exist_genre" "error_message_expired_token" "error_message_service" + 재생 목록에 노래 추가 From fa015fedc83411ead05eb8087924765b49ad81bc Mon Sep 17 00:00:00 2001 From: algosketch Date: Wed, 6 Dec 2023 23:25:06 +0900 Subject: [PATCH 02/11] =?UTF-8?q?feat=20:=20=EC=A0=80=EC=9E=A5=20=EB=B2=84?= =?UTF-8?q?=ED=8A=BC=20=EB=88=84=EB=A5=B4=EB=A9=B4=20=EB=B0=94=ED=85=80=20?= =?UTF-8?q?=EC=8B=9C=ED=8A=B8=EA=B0=80=20=EB=BF=85!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchytape/core/ui/PlaylistBottomSheet.kt | 20 +++++++++++++++++++ .../feature/player/PlayerFragment.kt | 6 ++++++ 2 files changed, 26 insertions(+) create mode 100644 android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheet.kt 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 new file mode 100644 index 0000000..ee868f8 --- /dev/null +++ b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheet.kt @@ -0,0 +1,20 @@ +package com.ohdodok.catchytape.core.ui + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.google.android.material.bottomsheet.BottomSheetDialogFragment + +class PlaylistBottomSheet : BottomSheetDialogFragment() { + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? = inflater.inflate(R.layout.bottom_sheet_playlist, container, false) + + companion object { + const val TAG = "PlaylistBottomSheet" + } +} \ No newline at end of file diff --git a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt index 71d048d..ab800b3 100644 --- a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt +++ b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt @@ -8,6 +8,7 @@ import androidx.media3.exoplayer.ExoPlayer import androidx.navigation.NavController import androidx.navigation.fragment.findNavController import com.ohdodok.catchytape.core.ui.BaseFragment +import com.ohdodok.catchytape.core.ui.PlaylistBottomSheet import com.ohdodok.catchytape.core.ui.toMessageId import com.ohdodok.catchytape.feature.player.databinding.FragmentPlayerBinding import dagger.hilt.android.AndroidEntryPoint @@ -64,6 +65,11 @@ class PlayerFragment : BaseFragment(R.layout.fragment_pla binding.btnPrevious.setOnClickListener { player.movePreviousMedia() } + + binding.btnAddToPlaylist.setOnClickListener { + val bottomSheet = PlaylistBottomSheet() + bottomSheet.show(parentFragmentManager, PlaylistBottomSheet.TAG) + } } private fun collectEvents() { From 94a7bfa1f96d4a7059a150e7975de74ec6784063 Mon Sep 17 00:00:00 2001 From: algosketch Date: Wed, 6 Dec 2023 23:56:34 +0900 Subject: [PATCH 03/11] =?UTF-8?q?feat=20:=20=EC=A0=80=EC=9E=A5=20=EB=B2=84?= =?UTF-8?q?=ED=8A=BC=EC=97=90=20ViewModel=20=ED=95=A8=EC=88=98=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchytape/feature/player/PlayerViewModel.kt | 12 ++++++++++++ .../player/src/main/res/layout/fragment_player.xml | 1 + 2 files changed, 13 insertions(+) diff --git a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt index e5df8f2..6e70df6 100644 --- a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt +++ b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.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.CurrentPlaylist import com.ohdodok.catchytape.core.domain.model.Music +import com.ohdodok.catchytape.core.domain.model.Playlist +import com.ohdodok.catchytape.core.domain.repository.PlaylistRepository import com.ohdodok.catchytape.core.domain.usecase.player.CurrentPlaylistUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.CoroutineExceptionHandler @@ -16,6 +18,7 @@ import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import javax.inject.Inject @@ -29,11 +32,13 @@ data class PlayerState( sealed interface PlayerEvent { data class ShowError(val error: CtErrorType) : PlayerEvent + data class AddToPlaylist(val playlists: List) : PlayerEvent } @HiltViewModel class PlayerViewModel @Inject constructor( private val currentPlaylistUseCase: CurrentPlaylistUseCase, + private val playlistRepository: PlaylistRepository, ) : ViewModel(), PlayerEventListener { private val _currentPlaylist = MutableStateFlow(null) @@ -68,6 +73,13 @@ class PlayerViewModel @Inject constructor( } } + fun addToPlaylist() { + viewModelScope.launch(exceptionHandler) { + val playlists = playlistRepository.getPlaylists().first() + _events.emit(PlayerEvent.AddToPlaylist(playlists)) + } + } + override fun onPlayingChanged(isPlaying: Boolean) { _uiState.update { it.copy(isPlaying = isPlaying) diff --git a/android/feature/player/src/main/res/layout/fragment_player.xml b/android/feature/player/src/main/res/layout/fragment_player.xml index 2200564..27daa7c 100644 --- a/android/feature/player/src/main/res/layout/fragment_player.xml +++ b/android/feature/player/src/main/res/layout/fragment_player.xml @@ -86,6 +86,7 @@ android:layout_marginEnd="@dimen/margin_horizontal" android:backgroundTint="@color/surface_bright" android:minWidth="0dp" + android:onClick="@{() -> viewModel.addToPlaylist()}" android:paddingHorizontal="12dp" android:paddingVertical="0dp" android:text="@string/save" From 3adee939ee08b073197cfb1baa26b0c7ac0df4ca Mon Sep 17 00:00:00 2001 From: algosketch Date: Thu, 7 Dec 2023 00:12:42 +0900 Subject: [PATCH 04/11] =?UTF-8?q?refactor=20:=20PlaylistAdapter=20?= =?UTF-8?q?=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ohdodok/catchytape/core/ui}/PlaylistAdapter.kt | 6 +++--- .../ohdodok/catchytape/core/ui}/model/PlaylistUiModel.kt | 2 +- .../ui}/src/main/res/layout/item_playlist.xml | 2 +- android/core/ui/src/main/res/values/strings.xml | 2 +- .../catchytape/feature/playlist/PlaylistsFragment.kt | 1 + .../catchytape/feature/playlist/PlaylistsViewModel.kt | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) rename android/{feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist => core/ui/src/main/java/com/ohdodok/catchytape/core/ui}/PlaylistAdapter.kt (88%) rename android/{feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist => core/ui/src/main/java/com/ohdodok/catchytape/core/ui}/model/PlaylistUiModel.kt (73%) rename android/{feature/playlist => core/ui}/src/main/res/layout/item_playlist.xml (97%) diff --git a/android/feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist/PlaylistAdapter.kt b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistAdapter.kt similarity index 88% rename from android/feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist/PlaylistAdapter.kt rename to android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistAdapter.kt index 3b1fbef..4f0ac67 100644 --- a/android/feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist/PlaylistAdapter.kt +++ b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistAdapter.kt @@ -1,12 +1,12 @@ -package com.ohdodok.catchytape.feature.playlist +package com.ohdodok.catchytape.core.ui import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView -import com.ohdodok.catchytape.feature.playlist.databinding.ItemPlaylistBinding -import com.ohdodok.catchytape.feature.playlist.model.PlaylistUiModel +import com.ohdodok.catchytape.core.ui.databinding.ItemPlaylistBinding +import com.ohdodok.catchytape.core.ui.model.PlaylistUiModel class PlaylistAdapter : ListAdapter(PlaylistItemDiffUtil) { diff --git a/android/feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist/model/PlaylistUiModel.kt b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/model/PlaylistUiModel.kt similarity index 73% rename from android/feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist/model/PlaylistUiModel.kt rename to android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/model/PlaylistUiModel.kt index ce1c89f..40ddc9b 100644 --- a/android/feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist/model/PlaylistUiModel.kt +++ b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/model/PlaylistUiModel.kt @@ -1,4 +1,4 @@ -package com.ohdodok.catchytape.feature.playlist.model +package com.ohdodok.catchytape.core.ui.model data class PlaylistUiModel( val id: Int, diff --git a/android/feature/playlist/src/main/res/layout/item_playlist.xml b/android/core/ui/src/main/res/layout/item_playlist.xml similarity index 97% rename from android/feature/playlist/src/main/res/layout/item_playlist.xml rename to android/core/ui/src/main/res/layout/item_playlist.xml index 3633a0d..56740af 100644 --- a/android/feature/playlist/src/main/res/layout/item_playlist.xml +++ b/android/core/ui/src/main/res/layout/item_playlist.xml @@ -7,7 +7,7 @@ + type="com.ohdodok.catchytape.core.ui.model.PlaylistUiModel" /> 설명 썸네일 이미지 선택 - + 트랙 %d개 "error_message_connection" "error_message_ssl_hand_shake" diff --git a/android/feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist/PlaylistsFragment.kt b/android/feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist/PlaylistsFragment.kt index dacd0bd..21c90e2 100644 --- a/android/feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist/PlaylistsFragment.kt +++ b/android/feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist/PlaylistsFragment.kt @@ -7,6 +7,7 @@ import androidx.fragment.app.viewModels import androidx.navigation.NavController import androidx.navigation.fragment.findNavController import com.ohdodok.catchytape.core.ui.BaseFragment +import com.ohdodok.catchytape.core.ui.PlaylistAdapter import com.ohdodok.catchytape.core.ui.toMessageId import com.ohdodok.catchytape.feature.playlist.databinding.FragmentPlaylistsBinding import dagger.hilt.android.AndroidEntryPoint diff --git a/android/feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist/PlaylistsViewModel.kt b/android/feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist/PlaylistsViewModel.kt index 917b2b0..2f4a31c 100644 --- a/android/feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist/PlaylistsViewModel.kt +++ b/android/feature/playlist/src/main/java/com/ohdodok/catchytape/feature/playlist/PlaylistsViewModel.kt @@ -6,7 +6,7 @@ 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.feature.playlist.model.PlaylistUiModel +import com.ohdodok.catchytape.core.ui.model.PlaylistUiModel import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.flow.MutableSharedFlow From de3d003dd97307d2291ae9a87b7724abe9929eb4 Mon Sep 17 00:00:00 2001 From: algosketch Date: Thu, 7 Dec 2023 00:24:31 +0900 Subject: [PATCH 05/11] =?UTF-8?q?feat=20:=20=EB=B0=94=ED=85=80=EC=8B=9C?= =?UTF-8?q?=ED=8A=B8=EC=97=90=20=ED=94=8C=EB=A0=88=EC=9D=B4=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EB=9D=84=EC=9A=B0=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchytape/core/ui/PlaylistBottomSheet.kt | 19 +++++++++++++-- .../feature/player/PlayerFragment.kt | 23 +++++++++++++++---- 2 files changed, 35 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 ee868f8..3a52e20 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 @@ -5,14 +5,29 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import com.ohdodok.catchytape.core.ui.databinding.BottomSheetPlaylistBinding +import com.ohdodok.catchytape.core.ui.model.PlaylistUiModel -class PlaylistBottomSheet : BottomSheetDialogFragment() { +class PlaylistBottomSheet( + private val playlists: List, +) : BottomSheetDialogFragment() { + + private var _binding: BottomSheetPlaylistBinding? = null + private val binding get() = _binding!! override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View? = inflater.inflate(R.layout.bottom_sheet_playlist, container, false) + ): View { + _binding = BottomSheetPlaylistBinding.inflate(inflater, container, false) + + binding.rvPlaylists.adapter = PlaylistAdapter().apply { + submitList(playlists) + } + + return binding.root + } companion object { const val TAG = "PlaylistBottomSheet" diff --git a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt index ab800b3..dad93ca 100644 --- a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt +++ b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt @@ -7,8 +7,10 @@ import androidx.fragment.app.activityViewModels import androidx.media3.exoplayer.ExoPlayer import androidx.navigation.NavController import androidx.navigation.fragment.findNavController +import com.ohdodok.catchytape.core.domain.model.Playlist import com.ohdodok.catchytape.core.ui.BaseFragment import com.ohdodok.catchytape.core.ui.PlaylistBottomSheet +import com.ohdodok.catchytape.core.ui.model.PlaylistUiModel import com.ohdodok.catchytape.core.ui.toMessageId import com.ohdodok.catchytape.feature.player.databinding.FragmentPlayerBinding import dagger.hilt.android.AndroidEntryPoint @@ -65,11 +67,6 @@ class PlayerFragment : BaseFragment(R.layout.fragment_pla binding.btnPrevious.setOnClickListener { player.movePreviousMedia() } - - binding.btnAddToPlaylist.setOnClickListener { - val bottomSheet = PlaylistBottomSheet() - bottomSheet.show(parentFragmentManager, PlaylistBottomSheet.TAG) - } } private fun collectEvents() { @@ -77,6 +74,10 @@ class PlayerFragment : BaseFragment(R.layout.fragment_pla viewModel.events.collect { event -> when (event) { is PlayerEvent.ShowError -> showMessage(event.error.toMessageId()) + is PlayerEvent.AddToPlaylist -> { + PlaylistBottomSheet(event.playlists.toUiModels()) + .show(parentFragmentManager, PlaylistBottomSheet.TAG) + } } } } @@ -86,3 +87,15 @@ class PlayerFragment : BaseFragment(R.layout.fragment_pla fun NavController.navigateToPlayer() { this.navigate(R.id.player_nav_graph) } + +private fun List.toUiModels(): List = this.map { it.toUiModel() } + +private fun Playlist.toUiModel(): PlaylistUiModel { + return PlaylistUiModel( + id = id, + title = title, + thumbnailUrl = thumbnailUrl, + trackSize = trackSize, + onClick = {} + ) +} \ No newline at end of file From 6eb6d420861ffd6ea41dfaf531067e7b040a1653 Mon Sep 17 00:00:00 2001 From: algosketch Date: Thu, 7 Dec 2023 01:06:26 +0900 Subject: [PATCH 06/11] =?UTF-8?q?feat=20:=20Dialog=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=EB=A5=BC=20?= =?UTF-8?q?=EC=97=86=EC=95=A0=20=ED=99=94=EB=A9=B4=20=ED=9A=8C=EC=A0=84?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=EC=9D=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/core/ui/build.gradle.kts | 1 + .../catchytape/core/ui/PlaylistBottomSheet.kt | 23 +++++----- .../core/ui/PlaylistBottomSheetViewModel.kt | 45 +++++++++++++++++++ .../main/res/layout/bottom_sheet_playlist.xml | 7 +++ .../feature/player/PlayerFragment.kt | 16 +------ .../feature/player/PlayerViewModel.kt | 9 +--- .../main/res/navigation/player_navigation.xml | 10 ++++- 7 files changed, 78 insertions(+), 33 deletions(-) create mode 100644 android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheetViewModel.kt diff --git a/android/core/ui/build.gradle.kts b/android/core/ui/build.gradle.kts index f664468..58ef4f2 100644 --- a/android/core/ui/build.gradle.kts +++ b/android/core/ui/build.gradle.kts @@ -1,6 +1,7 @@ @Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed plugins { id("catchytape.android.library") + id("catchytape.android.hilt") } android { 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 3a52e20..56e848e 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,13 +4,14 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.viewModels import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.ohdodok.catchytape.core.ui.databinding.BottomSheetPlaylistBinding -import com.ohdodok.catchytape.core.ui.model.PlaylistUiModel +import dagger.hilt.android.AndroidEntryPoint -class PlaylistBottomSheet( - private val playlists: List, -) : BottomSheetDialogFragment() { +@AndroidEntryPoint +class PlaylistBottomSheet : BottomSheetDialogFragment() { + val viewModel: PlaylistBottomSheetViewModel by viewModels() private var _binding: BottomSheetPlaylistBinding? = null private val binding get() = _binding!! @@ -19,17 +20,17 @@ class PlaylistBottomSheet( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View { + ): View { _binding = BottomSheetPlaylistBinding.inflate(inflater, container, false) - - binding.rvPlaylists.adapter = PlaylistAdapter().apply { - submitList(playlists) - } + binding.lifecycleOwner = viewLifecycleOwner + binding.viewModel = viewModel + binding.rvPlaylists.adapter = PlaylistAdapter() return binding.root } - companion object { - const val TAG = "PlaylistBottomSheet" + override fun onDestroyView() { + super.onDestroyView() + _binding = null } } \ No newline at end of file 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 new file mode 100644 index 0000000..59a3e54 --- /dev/null +++ b/android/core/ui/src/main/java/com/ohdodok/catchytape/core/ui/PlaylistBottomSheetViewModel.kt @@ -0,0 +1,45 @@ +package com.ohdodok.catchytape.core.ui + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +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.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.launch +import javax.inject.Inject + +@HiltViewModel +class PlaylistBottomSheetViewModel @Inject constructor( + private val playlistRepository: PlaylistRepository, +) : ViewModel() { + + private val _playlists = MutableStateFlow(emptyList()) + val playlists: StateFlow> = _playlists.asStateFlow() + + init { + fetchPlaylists() + } + + private fun fetchPlaylists() { + viewModelScope.launch { + _playlists.value = playlistRepository.getPlaylists().first().toUiModels() + } + } +} + +private fun List.toUiModels(): List = this.map { it.toUiModel() } + +private fun Playlist.toUiModel(): PlaylistUiModel { + return PlaylistUiModel( + id = id, + title = title, + thumbnailUrl = thumbnailUrl, + trackSize = trackSize, + onClick = {} + ) +} \ No newline at end of file diff --git a/android/core/ui/src/main/res/layout/bottom_sheet_playlist.xml b/android/core/ui/src/main/res/layout/bottom_sheet_playlist.xml index 8bdd633..69a58d5 100644 --- a/android/core/ui/src/main/res/layout/bottom_sheet_playlist.xml +++ b/android/core/ui/src/main/res/layout/bottom_sheet_playlist.xml @@ -3,6 +3,12 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> + + + + diff --git a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt index dad93ca..6679a05 100644 --- a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt +++ b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt @@ -75,8 +75,8 @@ class PlayerFragment : BaseFragment(R.layout.fragment_pla when (event) { is PlayerEvent.ShowError -> showMessage(event.error.toMessageId()) is PlayerEvent.AddToPlaylist -> { - PlaylistBottomSheet(event.playlists.toUiModels()) - .show(parentFragmentManager, PlaylistBottomSheet.TAG) + val action = PlayerFragmentDirections.actionPlayerFragmentToPlaylistBottomSheet() + findNavController().navigate(action) } } } @@ -86,16 +86,4 @@ class PlayerFragment : BaseFragment(R.layout.fragment_pla fun NavController.navigateToPlayer() { this.navigate(R.id.player_nav_graph) -} - -private fun List.toUiModels(): List = this.map { it.toUiModel() } - -private fun Playlist.toUiModel(): PlaylistUiModel { - return PlaylistUiModel( - id = id, - title = title, - thumbnailUrl = thumbnailUrl, - trackSize = trackSize, - onClick = {} - ) } \ No newline at end of file diff --git a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt index 6e70df6..dc8263e 100644 --- a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt +++ b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt @@ -6,8 +6,6 @@ import com.ohdodok.catchytape.core.domain.model.CtErrorType import com.ohdodok.catchytape.core.domain.model.CtException import com.ohdodok.catchytape.core.domain.model.CurrentPlaylist import com.ohdodok.catchytape.core.domain.model.Music -import com.ohdodok.catchytape.core.domain.model.Playlist -import com.ohdodok.catchytape.core.domain.repository.PlaylistRepository import com.ohdodok.catchytape.core.domain.usecase.player.CurrentPlaylistUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.CoroutineExceptionHandler @@ -18,7 +16,6 @@ import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import javax.inject.Inject @@ -32,13 +29,12 @@ data class PlayerState( sealed interface PlayerEvent { data class ShowError(val error: CtErrorType) : PlayerEvent - data class AddToPlaylist(val playlists: List) : PlayerEvent + data object AddToPlaylist : PlayerEvent } @HiltViewModel class PlayerViewModel @Inject constructor( private val currentPlaylistUseCase: CurrentPlaylistUseCase, - private val playlistRepository: PlaylistRepository, ) : ViewModel(), PlayerEventListener { private val _currentPlaylist = MutableStateFlow(null) @@ -75,8 +71,7 @@ class PlayerViewModel @Inject constructor( fun addToPlaylist() { viewModelScope.launch(exceptionHandler) { - val playlists = playlistRepository.getPlaylists().first() - _events.emit(PlayerEvent.AddToPlaylist(playlists)) + _events.emit(PlayerEvent.AddToPlaylist) } } diff --git a/android/feature/player/src/main/res/navigation/player_navigation.xml b/android/feature/player/src/main/res/navigation/player_navigation.xml index fa9cca1..c7fb4c9 100644 --- a/android/feature/player/src/main/res/navigation/player_navigation.xml +++ b/android/feature/player/src/main/res/navigation/player_navigation.xml @@ -12,8 +12,16 @@ tools:layout="@layout/fragment_player"> - + + + \ No newline at end of file From 420f42c613da626045d72d91f75723c3c58fcf20 Mon Sep 17 00:00:00 2001 From: algosketch Date: Thu, 7 Dec 2023 01:09:21 +0900 Subject: [PATCH 07/11] =?UTF-8?q?refactor=20:=20ViewModel=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=B2=98=EB=A6=AC=ED=95=98=EB=8A=94=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84=20=EC=A0=9C=EA=B1=B0=20=EB=B0=8F=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=20=EC=B6=94=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchytape/feature/player/PlayerFragment.kt | 16 +++++++++------- .../catchytape/feature/player/PlayerViewModel.kt | 7 ------- .../src/main/res/layout/fragment_player.xml | 1 - 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt index 6679a05..987cc7a 100644 --- a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt +++ b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt @@ -7,10 +7,7 @@ import androidx.fragment.app.activityViewModels import androidx.media3.exoplayer.ExoPlayer import androidx.navigation.NavController import androidx.navigation.fragment.findNavController -import com.ohdodok.catchytape.core.domain.model.Playlist import com.ohdodok.catchytape.core.ui.BaseFragment -import com.ohdodok.catchytape.core.ui.PlaylistBottomSheet -import com.ohdodok.catchytape.core.ui.model.PlaylistUiModel import com.ohdodok.catchytape.core.ui.toMessageId import com.ohdodok.catchytape.feature.player.databinding.FragmentPlayerBinding import dagger.hilt.android.AndroidEntryPoint @@ -67,6 +64,10 @@ class PlayerFragment : BaseFragment(R.layout.fragment_pla binding.btnPrevious.setOnClickListener { player.movePreviousMedia() } + + binding.btnAddToPlaylist.setOnClickListener { + findNavController().showPlaylistBottomSheet() + } } private fun collectEvents() { @@ -74,10 +75,6 @@ class PlayerFragment : BaseFragment(R.layout.fragment_pla viewModel.events.collect { event -> when (event) { is PlayerEvent.ShowError -> showMessage(event.error.toMessageId()) - is PlayerEvent.AddToPlaylist -> { - val action = PlayerFragmentDirections.actionPlayerFragmentToPlaylistBottomSheet() - findNavController().navigate(action) - } } } } @@ -86,4 +83,9 @@ class PlayerFragment : BaseFragment(R.layout.fragment_pla fun NavController.navigateToPlayer() { this.navigate(R.id.player_nav_graph) +} + +fun NavController.showPlaylistBottomSheet() { + val action = PlayerFragmentDirections.actionPlayerFragmentToPlaylistBottomSheet() + this.navigate(action) } \ No newline at end of file diff --git a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt index dc8263e..e5df8f2 100644 --- a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt +++ b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt @@ -29,7 +29,6 @@ data class PlayerState( sealed interface PlayerEvent { data class ShowError(val error: CtErrorType) : PlayerEvent - data object AddToPlaylist : PlayerEvent } @HiltViewModel @@ -69,12 +68,6 @@ class PlayerViewModel @Inject constructor( } } - fun addToPlaylist() { - viewModelScope.launch(exceptionHandler) { - _events.emit(PlayerEvent.AddToPlaylist) - } - } - override fun onPlayingChanged(isPlaying: Boolean) { _uiState.update { it.copy(isPlaying = isPlaying) diff --git a/android/feature/player/src/main/res/layout/fragment_player.xml b/android/feature/player/src/main/res/layout/fragment_player.xml index 27daa7c..2200564 100644 --- a/android/feature/player/src/main/res/layout/fragment_player.xml +++ b/android/feature/player/src/main/res/layout/fragment_player.xml @@ -86,7 +86,6 @@ android:layout_marginEnd="@dimen/margin_horizontal" android:backgroundTint="@color/surface_bright" android:minWidth="0dp" - android:onClick="@{() -> viewModel.addToPlaylist()}" android:paddingHorizontal="12dp" android:paddingVertical="0dp" android:text="@string/save" From 65722da20641d29e30644d786cf5f6e38061be3b Mon Sep 17 00:00:00 2001 From: algosketch Date: Thu, 7 Dec 2023 01:24:15 +0900 Subject: [PATCH 08/11] =?UTF-8?q?feat=20:=20=EC=9E=AC=EC=83=9D=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=EC=97=90=20=EC=B6=94=EA=B0=80=ED=95=98=EB=8A=94=20API?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ohdodok/catchytape/core/data/api/PlaylistApi.kt | 7 +++++++ .../core/data/model/AddMusicToPlaylistRequest.kt | 8 ++++++++ .../core/data/repository/PlaylistRepositoryImpl.kt | 8 ++++++++ .../core/domain/repository/PlaylistRepository.kt | 2 ++ 4 files changed, 25 insertions(+) create mode 100644 android/core/data/src/main/java/com/ohdodok/catchytape/core/data/model/AddMusicToPlaylistRequest.kt diff --git a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/api/PlaylistApi.kt b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/api/PlaylistApi.kt index 962f3d9..b1a2329 100644 --- a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/api/PlaylistApi.kt +++ b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/api/PlaylistApi.kt @@ -1,5 +1,6 @@ package com.ohdodok.catchytape.core.data.api +import com.ohdodok.catchytape.core.data.model.AddMusicToPlaylistRequest import com.ohdodok.catchytape.core.data.model.MusicResponse import com.ohdodok.catchytape.core.data.model.PlaylistRequest import com.ohdodok.catchytape.core.data.model.PlaylistResponse @@ -22,4 +23,10 @@ interface PlaylistApi { suspend fun getPlaylist( @Path("playlistId")playlistId: Int ): List + + @POST("playlists/{playlistId}") + suspend fun postMusicToPlaylist( + @Path("playlistId")playlistId: Int, + @Body music: AddMusicToPlaylistRequest, + ) } \ No newline at end of file diff --git a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/model/AddMusicToPlaylistRequest.kt b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/model/AddMusicToPlaylistRequest.kt new file mode 100644 index 0000000..e0ad689 --- /dev/null +++ b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/model/AddMusicToPlaylistRequest.kt @@ -0,0 +1,8 @@ +package com.ohdodok.catchytape.core.data.model + +import kotlinx.serialization.Serializable + +@Serializable +data class AddMusicToPlaylistRequest( + val musicId: String +) \ No newline at end of file diff --git a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/repository/PlaylistRepositoryImpl.kt b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/repository/PlaylistRepositoryImpl.kt index 62c9cb3..c3e07b1 100644 --- a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/repository/PlaylistRepositoryImpl.kt +++ b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/repository/PlaylistRepositoryImpl.kt @@ -2,6 +2,7 @@ package com.ohdodok.catchytape.core.data.repository import com.ohdodok.catchytape.core.data.api.PlaylistApi import com.ohdodok.catchytape.core.data.api.UserApi +import com.ohdodok.catchytape.core.data.model.AddMusicToPlaylistRequest import com.ohdodok.catchytape.core.data.model.PlaylistRequest import com.ohdodok.catchytape.core.data.model.toDomains import com.ohdodok.catchytape.core.domain.model.Music @@ -35,6 +36,13 @@ class PlaylistRepositoryImpl @Inject constructor( val response = playlistApi.getPlaylist(playlistId) emit(response.toDomains()) } + + override suspend fun addMusicToPlaylist(playlistId: Int, musicId: String) { + playlistApi.postMusicToPlaylist( + playlistId = playlistId, + music = AddMusicToPlaylistRequest(musicId), + ) + } } diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/repository/PlaylistRepository.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/repository/PlaylistRepository.kt index 7d0dee0..c6f19e2 100644 --- a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/repository/PlaylistRepository.kt +++ b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/repository/PlaylistRepository.kt @@ -13,4 +13,6 @@ interface PlaylistRepository { fun getRecentPlaylist(): Flow> fun getPlaylist(playlistId: Int): Flow> + + suspend fun addMusicToPlaylist(playlistId: Int, musicId: String) } \ No newline at end of file From 9272a01bfe5f13b10bcdb9865ef71129df1827ab Mon Sep 17 00:00:00 2001 From: algosketch Date: Thu, 7 Dec 2023 01:32:27 +0900 Subject: [PATCH 09/11] =?UTF-8?q?feat=20:=20=EC=9E=AC=EC=83=9D=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=EC=97=90=20=EC=B6=94=EA=B0=80=20=EC=9A=94=EC=B2=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/ui/PlaylistBottomSheetViewModel.kt | 41 +++++++++++++------ .../feature/player/PlayerFragment.kt | 12 +++--- .../main/res/navigation/player_navigation.xml | 7 +++- 3 files changed, 42 insertions(+), 18 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 59a3e54..e951c1c 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 @@ -1,5 +1,6 @@ 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.Playlist @@ -15,9 +16,14 @@ import javax.inject.Inject @HiltViewModel class PlaylistBottomSheetViewModel @Inject constructor( + savedStateHandle: SavedStateHandle, private val playlistRepository: PlaylistRepository, ) : ViewModel() { + private val musicId: String = requireNotNull(savedStateHandle["musicId"]) { + "반드시 musicId를 받아야 합니다." + } + private val _playlists = MutableStateFlow(emptyList()) val playlists: StateFlow> = _playlists.asStateFlow() @@ -30,16 +36,27 @@ class PlaylistBottomSheetViewModel @Inject constructor( _playlists.value = playlistRepository.getPlaylists().first().toUiModels() } } -} - -private fun List.toUiModels(): List = this.map { it.toUiModel() } - -private fun Playlist.toUiModel(): PlaylistUiModel { - return PlaylistUiModel( - id = id, - title = title, - thumbnailUrl = thumbnailUrl, - trackSize = trackSize, - onClick = {} - ) + + private fun addMusicToPlaylist(playlistId: Int, musicId: String) { + viewModelScope.launch { + playlistRepository.addMusicToPlaylist(playlistId = playlistId, musicId = musicId) + } + } + + private fun List.toUiModels(): List = this.map { it.toUiModel() } + + private fun Playlist.toUiModel(): PlaylistUiModel { + return PlaylistUiModel( + id = id, + title = title, + thumbnailUrl = thumbnailUrl, + trackSize = trackSize, + onClick = { + addMusicToPlaylist( + playlistId = id, + musicId = musicId + ) + } + ) + } } \ No newline at end of file diff --git a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt index 987cc7a..9e68f55 100644 --- a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt +++ b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerFragment.kt @@ -79,13 +79,15 @@ class PlayerFragment : BaseFragment(R.layout.fragment_pla } } } + + private fun NavController.showPlaylistBottomSheet() { + val musicId = viewModel.uiState.value.currentMusic?.id ?: return + + val action = PlayerFragmentDirections.actionPlayerFragmentToPlaylistBottomSheet(musicId = musicId) + this.navigate(action) + } } fun NavController.navigateToPlayer() { this.navigate(R.id.player_nav_graph) } - -fun NavController.showPlaylistBottomSheet() { - val action = PlayerFragmentDirections.actionPlayerFragmentToPlaylistBottomSheet() - this.navigate(action) -} \ No newline at end of file diff --git a/android/feature/player/src/main/res/navigation/player_navigation.xml b/android/feature/player/src/main/res/navigation/player_navigation.xml index c7fb4c9..140f260 100644 --- a/android/feature/player/src/main/res/navigation/player_navigation.xml +++ b/android/feature/player/src/main/res/navigation/player_navigation.xml @@ -22,6 +22,11 @@ android:id="@+id/playlist_bottom_sheet" android:name="com.ohdodok.catchytape.core.ui.PlaylistBottomSheet" android:label="playlist bottom sheet" - tools:layout="@layout/bottom_sheet_playlist" /> + tools:layout="@layout/bottom_sheet_playlist"> + + + \ No newline at end of file From f689114a3c86ec2b49b57cc0cab2487fd6fa97a0 Mon Sep 17 00:00:00 2001 From: algosketch Date: Thu, 7 Dec 2023 01:44:06 +0900 Subject: [PATCH 10/11] =?UTF-8?q?feat=20:=20=EC=9E=AC=EC=83=9D=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=B6=94=EA=B0=80=20=ED=9B=84=20=EB=B0=94=ED=85=80?= =?UTF-8?q?=20=EC=8B=9C=ED=8A=B8=20=EB=8B=AB=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchytape/core/ui/PlaylistBottomSheet.kt | 17 +++++++++++++++++ .../core/ui/PlaylistBottomSheetViewModel.kt | 9 ++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) 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 56e848e..beefc37 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 @@ -5,9 +5,14 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup 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.ohdodok.catchytape.core.ui.databinding.BottomSheetPlaylistBinding import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.launch @AndroidEntryPoint class PlaylistBottomSheet : BottomSheetDialogFragment() { @@ -26,9 +31,21 @@ class PlaylistBottomSheet : BottomSheetDialogFragment() { binding.viewModel = viewModel binding.rvPlaylists.adapter = PlaylistAdapter() + observeEvent() + return binding.root } + private fun observeEvent() { + viewLifecycleOwner.lifecycleScope.launch { + repeatOnLifecycle(Lifecycle.State.STARTED) { + viewModel.closeEvent.collect { + findNavController().popBackStack() + } + } + } + } + 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 e951c1c..32da440 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 @@ -7,8 +7,11 @@ 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.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch @@ -21,12 +24,15 @@ class PlaylistBottomSheetViewModel @Inject constructor( ) : ViewModel() { private val musicId: String = requireNotNull(savedStateHandle["musicId"]) { - "반드시 musicId를 받아야 합니다." + "musicId 정보가 누락되었어요." } private val _playlists = MutableStateFlow(emptyList()) val playlists: StateFlow> = _playlists.asStateFlow() + private val _closeEvent = MutableSharedFlow() + val closeEvent: SharedFlow = _closeEvent.asSharedFlow() + init { fetchPlaylists() } @@ -40,6 +46,7 @@ class PlaylistBottomSheetViewModel @Inject constructor( private fun addMusicToPlaylist(playlistId: Int, musicId: String) { viewModelScope.launch { playlistRepository.addMusicToPlaylist(playlistId = playlistId, musicId = musicId) + _closeEvent.emit(Unit) } } From 5c6b96639b88030b0430bbc80cc0235811e438e3 Mon Sep 17 00:00:00 2001 From: algosketch Date: Thu, 7 Dec 2023 15:25:18 +0900 Subject: [PATCH 11/11] =?UTF-8?q?refactor=20:=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81=20=EA=B3=BC=EC=A0=95=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/feature/playlist/src/main/res/values/strings.xml | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 android/feature/playlist/src/main/res/values/strings.xml diff --git a/android/feature/playlist/src/main/res/values/strings.xml b/android/feature/playlist/src/main/res/values/strings.xml deleted file mode 100644 index 6fb9879..0000000 --- a/android/feature/playlist/src/main/res/values/strings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - 트랙 %d개 - \ No newline at end of file