Properly handle deleting tracks without media store id

This commit is contained in:
Naveen 2023-07-17 08:19:20 +05:30
parent 95d6c29c3d
commit 5dd8c60f46
No known key found for this signature in database
GPG key ID: 0E155DAD31671DA3

View file

@ -7,15 +7,13 @@ import android.net.Uri
import android.provider.MediaStore
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.PropertiesDialog
import com.simplemobiletools.commons.extensions.getMediaContent
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isRPlus
import com.simplemobiletools.musicplayer.R
import com.simplemobiletools.musicplayer.dialogs.SelectPlaylistDialog
import com.simplemobiletools.musicplayer.helpers.EDIT
import com.simplemobiletools.musicplayer.helpers.EDITED_TRACK
import com.simplemobiletools.musicplayer.helpers.REFRESH_LIST
import com.simplemobiletools.musicplayer.helpers.RoomHelper
import com.simplemobiletools.musicplayer.helpers.*
import com.simplemobiletools.musicplayer.models.Events
import com.simplemobiletools.musicplayer.models.Track
import com.simplemobiletools.musicplayer.services.MusicService
@ -57,11 +55,11 @@ fun Activity.addTracksToQueue(tracks: List<Track>, callback: () -> Unit) {
fun BaseSimpleActivity.deleteTracks(tracks: List<Track>, callback: () -> Unit) {
val uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
if (isRPlus()) {
val uris = arrayListOf<Uri>()
tracks.forEach { track ->
val newUri = ContentUris.withAppendedId(uri, track.mediaStoreId)
uris.add(newUri)
}
val (tracksWithoutId, tracksWithId) = tracks.partition { (it.flags and FLAG_MANUAL_CACHE) != 0 }
val uris = tracksWithId.map { ContentUris.withAppendedId(uri, it.mediaStoreId) } as ArrayList<Uri>
val contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
uris += tracksWithoutId.mapNotNull { getMediaContent(it.path, contentUri) }
deleteSDK30Uris(uris) { success ->
if (success) {