⭐️Favorite playlist added
This commit is contained in:
parent
b22b3a627f
commit
2769db3f17
5 changed files with 47 additions and 21 deletions
|
@ -17,7 +17,6 @@ import code.name.monkey.retromusic.fragments.artists.ArtistClickListener
|
|||
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment
|
||||
import code.name.monkey.retromusic.model.Album
|
||||
import code.name.monkey.retromusic.model.Artist
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.repository.RealRepository
|
||||
import kotlinx.android.synthetic.main.fragment_playlist_detail.*
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
|
@ -74,19 +73,20 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de
|
|||
|
||||
private fun loadFavorite() {
|
||||
toolbar.setTitle(R.string.favorites)
|
||||
lifecycleScope.launch(IO) {
|
||||
val songs = repository.favoritePlaylistHome()
|
||||
withContext(Main) {
|
||||
recyclerView.apply {
|
||||
adapter = SongAdapter(
|
||||
requireActivity(),
|
||||
songs.arrayList as MutableList<Song>,
|
||||
R.layout.item_list, null
|
||||
)
|
||||
layoutManager = linearLayoutManager()
|
||||
}
|
||||
}
|
||||
val songAdapter = SongAdapter(
|
||||
requireActivity(),
|
||||
mutableListOf(),
|
||||
R.layout.item_list, null
|
||||
)
|
||||
recyclerView.apply {
|
||||
adapter = songAdapter
|
||||
layoutManager = linearLayoutManager()
|
||||
}
|
||||
repository.favorites().observe(viewLifecycleOwner, Observer {
|
||||
println(it.size)
|
||||
val songs = it.map { songEntity -> songEntity.toSong() }
|
||||
songAdapter.swapDataSet(songs)
|
||||
})
|
||||
}
|
||||
|
||||
private fun loadArtists(title: Int, type: Int) {
|
||||
|
|
|
@ -164,7 +164,8 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
|
|||
lifecycleScope.launch(IO) {
|
||||
val playlist: PlaylistEntity = repository.favoritePlaylist().first()
|
||||
val songEntity = song.toSongEntity(playlist.playListId)
|
||||
if (repository.isFavoriteSong(songEntity).isNotEmpty()) {
|
||||
val isFavorite = repository.isFavoriteSong(songEntity).isNotEmpty()
|
||||
if (isFavorite) {
|
||||
repository.removeSongFromPlaylist(songEntity)
|
||||
} else {
|
||||
repository.insertSongs(listOf(song.toSongEntity(playlist.playListId)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue