From 4eb2f68da5b1da3169b9089e3b24b026e7692f70 Mon Sep 17 00:00:00 2001 From: Prathamesh More Date: Sun, 25 Jul 2021 10:40:13 +0530 Subject: [PATCH] Added MediaStore delete for A11 --- .../monkey/retromusic/dialogs/DeleteSongsDialog.kt | 7 ++++++- .../code/name/monkey/retromusic/util/MusicUtil.kt | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/DeleteSongsDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/DeleteSongsDialog.kt index 1a528412..dc643849 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/DeleteSongsDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/DeleteSongsDialog.kt @@ -21,6 +21,7 @@ import android.os.Bundle import androidx.core.os.bundleOf import androidx.core.text.HtmlCompat import androidx.fragment.app.DialogFragment +import code.name.monkey.appthemehelper.util.VersionUtils import code.name.monkey.retromusic.EXTRA_SONG import code.name.monkey.retromusic.R import code.name.monkey.retromusic.activities.saf.SAFGuideActivity @@ -89,7 +90,11 @@ class DeleteSongsDialog : DialogFragment() { if ((songs.size == 1) && MusicPlayerRemote.isPlaying(songs[0])) { MusicPlayerRemote.playNextSong() } - if (!SAFUtil.isSAFRequiredForSongs(songs)) { + if (VersionUtils.hasQ()) { + dismiss() + MusicUtil.deleteTracksQ(requireActivity(), songs) + reloadTabs() + } else if (!SAFUtil.isSAFRequiredForSongs(songs)) { CoroutineScope(Dispatchers.IO).launch { dismiss() MusicUtil.deleteTracks(requireContext(), songs) diff --git a/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.kt b/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.kt index 9971afb7..ff21dbb3 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.kt +++ b/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.kt @@ -1,17 +1,20 @@ package code.name.monkey.retromusic.util +import android.app.Activity import android.content.ContentUris import android.content.ContentValues import android.content.Context import android.content.Intent import android.database.Cursor import android.net.Uri +import android.os.Build import android.os.Environment import android.provider.BaseColumns import android.provider.MediaStore import android.text.TextUtils import android.util.Log import android.widget.Toast +import androidx.annotation.RequiresApi import androidx.core.content.FileProvider import androidx.fragment.app.FragmentActivity import code.name.monkey.retromusic.R @@ -517,6 +520,14 @@ object MusicUtil : KoinComponent { } } + @RequiresApi(Build.VERSION_CODES.Q) + fun deleteTracksQ(activity: Activity, songs: List) { + val pendingIntent = MediaStore.createDeleteRequest(activity.contentResolver, songs.map { + getSongFileUri(it.id) + }) + activity.startIntentSenderForResult(pendingIntent.intentSender, 45, null, 0, 0, 0, null); + } + fun songByGenre(genreId: Long): Song { return repository.getSongByGenre(genreId) }