Directly ask for permission from user to delete a file instead of showing a confirmation dialog and then asking for permission

This commit is contained in:
Prathamesh More 2021-11-26 13:37:02 +05:30
parent 4e10acf5c2
commit 50c04b6d97

View file

@ -60,6 +60,11 @@ class DeleteSongsDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
libraryViewModel = activity?.getViewModel() as LibraryViewModel libraryViewModel = activity?.getViewModel() as LibraryViewModel
val songs = extraNotNull<List<Song>>(EXTRA_SONG).value val songs = extraNotNull<List<Song>>(EXTRA_SONG).value
if (VersionUtils.hasR()) {
dismiss()
MusicUtil.deleteTracksR(requireActivity(), songs)
reloadTabs()
}
val pair = if (songs.size > 1) { val pair = if (songs.size > 1) {
Pair( Pair(
R.string.delete_songs_title, R.string.delete_songs_title,
@ -90,11 +95,7 @@ class DeleteSongsDialog : DialogFragment() {
if ((songs.size == 1) && MusicPlayerRemote.isPlaying(songs[0])) { if ((songs.size == 1) && MusicPlayerRemote.isPlaying(songs[0])) {
MusicPlayerRemote.playNextSong() MusicPlayerRemote.playNextSong()
} }
if (VersionUtils.hasR()) { if (!SAFUtil.isSAFRequiredForSongs(songs)) {
dismiss()
MusicUtil.deleteTracksR(requireActivity(), songs)
reloadTabs()
} else if (!SAFUtil.isSAFRequiredForSongs(songs)) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
dismiss() dismiss()
MusicUtil.deleteTracks(requireContext(), songs) MusicUtil.deleteTracks(requireContext(), songs)