[Android] Fix removeItems
js6pak
git at videolan.org
Mon Jan 10 07:14:23 UTC 2022
vlc-android | branch: master | js6pak <kubastaron at hotmail.com> | Mon Jan 3 13:56:11 2022 +0100| [dd2a1c098af36aec84e10eda5f77065f847a91a7] | committer: Nicolas Pomepuy
Fix removeItems
> https://code.videolan.org/videolan/vlc-android/commit/dd2a1c098af36aec84e10eda5f77065f847a91a7
---
.../vlc/gui/browser/MediaBrowserFragment.kt | 48 ++++++++++------------
1 file changed, 21 insertions(+), 27 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
index 84d5e20d3..264e32db3 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
@@ -120,6 +120,24 @@ abstract class MediaBrowserFragment<T : SortableModel> : BaseFragment(), Filtera
abstract fun onRefresh()
open fun clear() {}
+ private fun deleteItem(item: MediaLibraryItem) {
+ val deletionAction = when (item) {
+ is MediaWrapper, is Album -> Runnable {
+ if (isStarted()) lifecycleScope.launch {
+ if (!MediaUtils.deleteMedia(item, null)) onDeleteFailed(item)
+ }
+ }
+ is Playlist -> Runnable { MediaUtils.deletePlaylist(item) }
+ else -> Runnable { onDeleteFailed(item) }
+ }
+
+ if (item is MediaWrapper) {
+ if (Permissions.checkWritePermission(requireActivity(), item, deletionAction)) deletionAction.run()
+ } else {
+ deletionAction.run()
+ }
+ }
+
protected open fun removeItems(items: List<MediaLibraryItem>) {
if (items.size == 1) {
removeItem(items[0])
@@ -128,41 +146,17 @@ abstract class MediaBrowserFragment<T : SortableModel> : BaseFragment(), Filtera
val dialog = ConfirmDeleteDialog.newInstance(ArrayList(items))
dialog.show(requireActivity().supportFragmentManager, ConfirmDeleteDialog::class.simpleName)
dialog.setListener {
- lifecycleScope.launch {
- for (item in items) {
- if (!isStarted()) break
- when(item) {
- is MediaWrapper -> if (getWritePermission(item.uri)) MediaUtils.deleteMedia(item)
- is Playlist -> withContext(Dispatchers.IO) { item.delete() }
- }
- }
+ for (item in items) {
+ deleteItem(item)
}
}
}
protected open fun removeItem(item: MediaLibraryItem): Boolean {
- val deletionAction = when (item) {
- is Playlist -> Runnable {
- MediaUtils.deletePlaylist(item)
- }
- is MediaWrapper-> Runnable {
- if (isStarted()) lifecycleScope.launch {
- if (!MediaUtils.deleteMedia(item, null)) onDeleteFailed(item)
- }
- }
-
- is Album -> Runnable {
- if (isStarted()) lifecycleScope.launch {
- if (!MediaUtils.deleteMedia(item, null)) onDeleteFailed(item)
- }
- }
- else -> return false
- }
val dialog = ConfirmDeleteDialog.newInstance(arrayListOf(item))
dialog.show(requireActivity().supportFragmentManager, ConfirmDeleteDialog::class.simpleName)
dialog.setListener {
- if (item is MediaWrapper) if (Permissions.checkWritePermission(requireActivity(), item, deletionAction)) deletionAction.run() else deletionAction.run()
- else deletionAction.run()
+ deleteItem(item)
}
return true
}
More information about the Android
mailing list