Added MediaStore delete for A11

This commit is contained in:
Prathamesh More 2021-07-25 10:40:13 +05:30
parent e9b7b5a203
commit 4eb2f68da5
2 changed files with 17 additions and 1 deletions

View file

@ -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)

View file

@ -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<Song>) {
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)
}