Show toast when adding songs to an existing playlist
This commit is contained in:
parent
d8d1cff659
commit
fce3844ed5
1 changed files with 14 additions and 2 deletions
|
@ -17,6 +17,7 @@ package code.name.monkey.retromusic.dialogs
|
|||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Toast
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
|
@ -33,6 +34,7 @@ import code.name.monkey.retromusic.fragments.ReloadType.Playlists
|
|||
import code.name.monkey.retromusic.model.Song
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
|
||||
|
||||
class AddToPlaylistDialog : DialogFragment() {
|
||||
|
@ -78,8 +80,18 @@ class AddToPlaylistDialog : DialogFragment() {
|
|||
} else {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val songEntities = songs.toSongsEntity(playlistEntities[which - 1])
|
||||
if (songEntities.isNotEmpty()) {
|
||||
libraryViewModel.insertSongs(songEntities)
|
||||
libraryViewModel.forceReload(Playlists)
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(
|
||||
requireContext(), getString(R.string.added_song_count_to_playlist,
|
||||
songEntities.size,
|
||||
playlistEntities[which - 1].playlistName
|
||||
), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dialog.dismiss()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue