Properly handle deleting tracks without media store id
This commit is contained in:
parent
95d6c29c3d
commit
5dd8c60f46
1 changed files with 7 additions and 9 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue