add handling for deleting files on Android 11
This commit is contained in:
parent
3eeccc0ad7
commit
a5c60bceb8
3 changed files with 47 additions and 22 deletions
|
@ -62,7 +62,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:a74ec200da'
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:3e78714205'
|
||||
implementation 'org.greenrobot:eventbus:3.2.0'
|
||||
implementation 'androidx.media:media:1.3.1'
|
||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
||||
|
|
|
@ -5,25 +5,25 @@ import com.simplemobiletools.musicplayer.R
|
|||
|
||||
open class SimpleActivity : BaseSimpleActivity() {
|
||||
override fun getAppIconIDs() = arrayListOf(
|
||||
R.mipmap.ic_launcher_red,
|
||||
R.mipmap.ic_launcher_pink,
|
||||
R.mipmap.ic_launcher_purple,
|
||||
R.mipmap.ic_launcher_deep_purple,
|
||||
R.mipmap.ic_launcher_indigo,
|
||||
R.mipmap.ic_launcher_blue,
|
||||
R.mipmap.ic_launcher_light_blue,
|
||||
R.mipmap.ic_launcher_cyan,
|
||||
R.mipmap.ic_launcher_teal,
|
||||
R.mipmap.ic_launcher_green,
|
||||
R.mipmap.ic_launcher_light_green,
|
||||
R.mipmap.ic_launcher_lime,
|
||||
R.mipmap.ic_launcher_yellow,
|
||||
R.mipmap.ic_launcher_amber,
|
||||
R.mipmap.ic_launcher,
|
||||
R.mipmap.ic_launcher_deep_orange,
|
||||
R.mipmap.ic_launcher_brown,
|
||||
R.mipmap.ic_launcher_blue_grey,
|
||||
R.mipmap.ic_launcher_grey_black
|
||||
R.mipmap.ic_launcher_red,
|
||||
R.mipmap.ic_launcher_pink,
|
||||
R.mipmap.ic_launcher_purple,
|
||||
R.mipmap.ic_launcher_deep_purple,
|
||||
R.mipmap.ic_launcher_indigo,
|
||||
R.mipmap.ic_launcher_blue,
|
||||
R.mipmap.ic_launcher_light_blue,
|
||||
R.mipmap.ic_launcher_cyan,
|
||||
R.mipmap.ic_launcher_teal,
|
||||
R.mipmap.ic_launcher_green,
|
||||
R.mipmap.ic_launcher_light_green,
|
||||
R.mipmap.ic_launcher_lime,
|
||||
R.mipmap.ic_launcher_yellow,
|
||||
R.mipmap.ic_launcher_amber,
|
||||
R.mipmap.ic_launcher,
|
||||
R.mipmap.ic_launcher_deep_orange,
|
||||
R.mipmap.ic_launcher_brown,
|
||||
R.mipmap.ic_launcher_blue_grey,
|
||||
R.mipmap.ic_launcher_grey_black
|
||||
)
|
||||
|
||||
override fun getAppLauncherName() = getString(R.string.app_launcher_name)
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
package com.simplemobiletools.musicplayer.extensions
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ContentUris
|
||||
import android.net.Uri
|
||||
import android.provider.MediaStore
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
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.RoomHelper
|
||||
import com.simplemobiletools.musicplayer.models.Events
|
||||
|
@ -43,12 +49,31 @@ fun Activity.addTracksToQueue(tracks: List<Track>, callback: () -> Unit) {
|
|||
}
|
||||
}
|
||||
|
||||
fun Activity.deleteTracks(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)
|
||||
}
|
||||
|
||||
deleteSDK30Uris(uris) { success ->
|
||||
if (success) {
|
||||
removeQueueItems(tracks) {}
|
||||
EventBus.getDefault().post(Events.TrackDeleted())
|
||||
callback()
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
tracks.forEach { track ->
|
||||
try {
|
||||
val where = "${MediaStore.Audio.Media._ID} = ?"
|
||||
val args = arrayOf(track.mediaStoreId.toString())
|
||||
val uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
|
||||
contentResolver.delete(uri, where, args)
|
||||
tracksDAO.removeTrack(track.mediaStoreId)
|
||||
} catch (ignored: Exception) {
|
||||
|
|
Loading…
Reference in a new issue