Exit Playlist page when playlist is deleted
This commit is contained in:
parent
0c4cabc755
commit
b4dc50306f
5 changed files with 22 additions and 15 deletions
|
@ -64,4 +64,7 @@ interface PlaylistDao {
|
|||
|
||||
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id= :playlistId")
|
||||
fun favoritesSongs(playlistId: Long): List<SongEntity>
|
||||
|
||||
@Query("SELECT EXISTS(SELECT * FROM PlaylistEntity WHERE playlist_id = :playlistId)")
|
||||
fun checkPlaylistExists(playlistId: Long): LiveData<Boolean>
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import androidx.activity.addCallback
|
|||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.doOnPreDraw
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
@ -58,7 +59,6 @@ class PlaylistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playli
|
|||
enterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, true).addTarget(view)
|
||||
returnTransition = MaterialSharedAxis(MaterialSharedAxis.Z, false)
|
||||
setHasOptionsMenu(true)
|
||||
mainActivity.addMusicServiceEventListener(viewModel)
|
||||
mainActivity.setSupportActionBar(binding.toolbar)
|
||||
ViewCompat.setTransitionName(binding.container, "playlist")
|
||||
playlist = arguments.extraPlaylist
|
||||
|
@ -67,6 +67,11 @@ class PlaylistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playli
|
|||
viewModel.getSongs().observe(viewLifecycleOwner) {
|
||||
songs(it.toSongs())
|
||||
}
|
||||
viewModel.playlistExists().observe(viewLifecycleOwner) {
|
||||
if (!it) {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
}
|
||||
postponeEnterTransition()
|
||||
requireView().doOnPreDraw { startPostponedEnterTransition() }
|
||||
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner) {
|
||||
|
|
|
@ -22,24 +22,15 @@ import code.name.monkey.retromusic.db.SongEntity
|
|||
import code.name.monkey.retromusic.interfaces.IMusicServiceEventListener
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.repository.RealRepository
|
||||
import code.name.monkey.retromusic.repository.RealRoomRepository
|
||||
|
||||
class PlaylistDetailsViewModel(
|
||||
private val realRepository: RealRepository,
|
||||
private var playlist: PlaylistWithSongs
|
||||
) : ViewModel(), IMusicServiceEventListener {
|
||||
|
||||
private val playListSongs = MutableLiveData<List<Song>>()
|
||||
|
||||
) : ViewModel() {
|
||||
fun getSongs(): LiveData<List<SongEntity>> =
|
||||
realRepository.playlistSongs(playlist.playlistEntity.playListId)
|
||||
|
||||
override fun onMediaStoreChanged() {}
|
||||
override fun onServiceConnected() {}
|
||||
override fun onServiceDisconnected() {}
|
||||
override fun onQueueChanged() {}
|
||||
override fun onPlayingMetaChanged() {}
|
||||
override fun onPlayStateChanged() {}
|
||||
override fun onRepeatModeChanged() {}
|
||||
override fun onShuffleModeChanged() {}
|
||||
override fun onFavoriteStateChanged() {}
|
||||
fun playlistExists(): LiveData<Boolean> =
|
||||
realRepository.checkPlaylistExists(playlist.playlistEntity.playListId)
|
||||
}
|
||||
|
|
|
@ -111,6 +111,7 @@ interface Repository {
|
|||
suspend fun searchAlbums(query: String): List<Album>
|
||||
suspend fun isSongFavorite(songId: Long): Boolean
|
||||
fun getSongByGenre(genreId: Long): Song
|
||||
fun checkPlaylistExists(playListId: Long): LiveData<Boolean>
|
||||
}
|
||||
|
||||
class RealRepository(
|
||||
|
@ -277,6 +278,9 @@ class RealRepository(
|
|||
override suspend fun checkPlaylistExists(playlistName: String): List<PlaylistEntity> =
|
||||
roomRepository.checkPlaylistExists(playlistName)
|
||||
|
||||
override fun checkPlaylistExists(playListId: Long): LiveData<Boolean> =
|
||||
roomRepository.checkPlaylistExists(playListId)
|
||||
|
||||
override suspend fun createPlaylist(playlistEntity: PlaylistEntity): Long =
|
||||
roomRepository.createPlaylist(playlistEntity)
|
||||
|
||||
|
@ -377,7 +381,7 @@ class RealRepository(
|
|||
}
|
||||
|
||||
override suspend fun suggestions(): List<Song> {
|
||||
if (!PreferenceUtil.homeSuggestions) return listOf<Song>()
|
||||
if (!PreferenceUtil.homeSuggestions) return listOf()
|
||||
return NotPlayedPlaylist().songs().shuffled().takeIf {
|
||||
it.size > 9
|
||||
} ?: emptyList()
|
||||
|
|
|
@ -49,6 +49,7 @@ interface RoomRepository {
|
|||
suspend fun blackListPaths(): List<BlackListStoreEntity>
|
||||
suspend fun deleteSongs(songs: List<Song>)
|
||||
suspend fun isSongFavorite(context: Context, songId: Long): Boolean
|
||||
fun checkPlaylistExists(playListId: Long): LiveData<Boolean>
|
||||
}
|
||||
|
||||
class RealRoomRepository(
|
||||
|
@ -97,6 +98,9 @@ class RealRoomRepository(
|
|||
override fun getSongs(playListId: Long): LiveData<List<SongEntity>> =
|
||||
playlistDao.songsFromPlaylist(playListId)
|
||||
|
||||
override fun checkPlaylistExists(playListId: Long): LiveData<Boolean> =
|
||||
playlistDao.checkPlaylistExists(playListId)
|
||||
|
||||
override suspend fun deletePlaylistEntities(playlistEntities: List<PlaylistEntity>) =
|
||||
playlistDao.deletePlaylists(playlistEntities)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue