moving track deleting from context to activity extension
This commit is contained in:
parent
ff974f747c
commit
f909efe0e5
2 changed files with 22 additions and 19 deletions
|
@ -1,11 +1,14 @@
|
|||
package com.simplemobiletools.musicplayer.extensions
|
||||
|
||||
import android.app.Activity
|
||||
import android.provider.MediaStore
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.musicplayer.dialogs.SelectPlaylistDialog
|
||||
import com.simplemobiletools.musicplayer.helpers.RoomHelper
|
||||
import com.simplemobiletools.musicplayer.models.Events
|
||||
import com.simplemobiletools.musicplayer.models.Track
|
||||
import com.simplemobiletools.musicplayer.services.MusicService
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
fun Activity.addTracksToPlaylist(tracks: List<Track>, callback: () -> Unit) {
|
||||
SelectPlaylistDialog(this) { playlistId ->
|
||||
|
@ -39,3 +42,20 @@ fun Activity.addTracksToQueue(tracks: List<Track>, callback: () -> Unit) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Activity.deleteTracks(tracks: List<Track>, callback: () -> Unit) {
|
||||
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) {
|
||||
}
|
||||
}
|
||||
|
||||
removeQueueItems(tracks) {}
|
||||
EventBus.getDefault().post(Events.TrackDeleted())
|
||||
callback()
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ import com.simplemobiletools.musicplayer.helpers.*
|
|||
import com.simplemobiletools.musicplayer.interfaces.*
|
||||
import com.simplemobiletools.musicplayer.models.*
|
||||
import com.simplemobiletools.musicplayer.services.MusicService
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.io.File
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
|
@ -134,7 +133,8 @@ fun Context.getAlbumsSync(artist: Artist): ArrayList<Album> {
|
|||
Audio.Albums._ID,
|
||||
Audio.Albums.ARTIST,
|
||||
Audio.Albums.FIRST_YEAR,
|
||||
Audio.Albums.ALBUM)
|
||||
Audio.Albums.ALBUM
|
||||
)
|
||||
|
||||
var selection = "${Audio.Albums.ARTIST} = ?"
|
||||
var selectionArgs = arrayOf(artist.title)
|
||||
|
@ -263,23 +263,6 @@ fun Context.removeQueueItems(tracks: List<Track>, callback: () -> Unit) {
|
|||
}
|
||||
}
|
||||
|
||||
fun Context.deleteTracks(tracks: List<Track>, callback: () -> Unit) {
|
||||
tracks.forEach { track ->
|
||||
try {
|
||||
val where = "${Audio.Media._ID} = ?"
|
||||
val args = arrayOf(track.mediaStoreId.toString())
|
||||
val uri = Audio.Media.EXTERNAL_CONTENT_URI
|
||||
contentResolver.delete(uri, where, args)
|
||||
tracksDAO.removeTrack(track.mediaStoreId)
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
removeQueueItems(tracks) {}
|
||||
EventBus.getDefault().post(Events.TrackDeleted())
|
||||
callback()
|
||||
}
|
||||
|
||||
fun Context.getAllInitialTracks(): ArrayList<Track> {
|
||||
val allTracks = ArrayList<Track>()
|
||||
getArtistsSync().forEach { artist ->
|
||||
|
|
Loading…
Reference in a new issue