[Android] Allow deleting an album

Nicolas Pomepuy git at videolan.org
Mon Apr 27 15:14:09 CEST 2020


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Apr 27 12:10:12 2020 +0200| [981f3230ef0ca18ba8497c65d3271113089bb617] | committer: Nicolas Pomepuy

Allow deleting an album

> https://code.videolan.org/videolan/vlc-android/commit/981f3230ef0ca18ba8497c65d3271113089bb617
---

 .../src/main/java/org/videolan/resources/Constants.kt        |  2 +-
 application/resources/src/main/res/values/strings.xml        |  1 +
 .../src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt       |  2 +-
 .../src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt | 12 +++++++++++-
 .../vlc-android/src/org/videolan/vlc/media/MediaUtils.kt     |  9 ++++++++-
 5 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/application/resources/src/main/java/org/videolan/resources/Constants.kt b/application/resources/src/main/java/org/videolan/resources/Constants.kt
index de4d9aae0..1c6cc2fe9 100644
--- a/application/resources/src/main/java/org/videolan/resources/Constants.kt
+++ b/application/resources/src/main/java/org/videolan/resources/Constants.kt
@@ -190,7 +190,7 @@ const val CTX_GROUP_SIMILAR = 1L shl 35
 const val CTX_VIDEO_FLAGS = CTX_APPEND or CTX_PLAY_NEXT or CTX_DELETE or CTX_DOWNLOAD_SUBTITLES or CTX_INFORMATION or CTX_PLAY_ALL or CTX_PLAY_AS_AUDIO or CTX_ADD_TO_PLAYLIST or CTX_SHARE
 const val CTX_TRACK_FLAGS = CTX_APPEND or CTX_PLAY_NEXT or CTX_DELETE or CTX_INFORMATION or CTX_PLAY_ALL or CTX_ADD_TO_PLAYLIST or CTX_SET_RINGTONE or CTX_SHARE
 const val CTX_AUDIO_FLAGS = CTX_PLAY or CTX_APPEND or CTX_PLAY_NEXT or CTX_ADD_TO_PLAYLIST or CTX_INFORMATION
-const val CTX_PLAYLIST_FLAGS = CTX_AUDIO_FLAGS or CTX_DELETE
+const val CTX_PLAYLIST_ALBUM_FLAGS = CTX_AUDIO_FLAGS or CTX_DELETE
 const val CTX_PLAYLIST_ITEM_FLAGS = CTX_APPEND or CTX_PLAY_NEXT or CTX_ADD_TO_PLAYLIST or CTX_INFORMATION or CTX_DELETE or CTX_SET_RINGTONE or CTX_SHARE
 const val CTX_VIDEO_GROUP_FLAGS = CTX_APPEND or CTX_PLAY_GROUP
 const val CTX_FOLDER_FLAGS = CTX_PLAY or CTX_APPEND or CTX_ADD_TO_PLAYLIST
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 6aee77456..87a786bca 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -55,6 +55,7 @@
     <string name="set_song_question">Set \'%1$s\' as ringtone?</string>
     <string name="info">Information</string>
     <string name="confirm_delete">Delete the file \'%1$s\'?</string>
+    <string name="confirm_delete_album">Delete the album \'%1$s\'?</string>
     <string name="confirm_delete_several_media">Delete these %1$d media?</string>
     <string name="confirm_delete_folder">Delete the folder \'%1$s\' and all its contents?</string>
     <string name="confirm_delete_playlist">Delete playlist \'%1$s\'?</string>
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
index a398f9997..e715f852b 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
@@ -320,7 +320,7 @@ abstract class BaseAudioBrowser<T : MedialibraryViewModel> : MediaBrowserFragmen
     override fun onCtxClick(v: View, position: Int, item: MediaLibraryItem) {
         val flags: Long = when (item.itemType) {
             MediaLibraryItem.TYPE_MEDIA -> CTX_TRACK_FLAGS
-            MediaLibraryItem.TYPE_PLAYLIST -> CTX_PLAYLIST_FLAGS
+            MediaLibraryItem.TYPE_PLAYLIST, MediaLibraryItem.TYPE_ALBUM -> CTX_PLAYLIST_ALBUM_FLAGS
             else -> CTX_AUDIO_FLAGS
         }
         if (actionMode == null) showContext(requireActivity(), this, position, item.title, flags)
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 e4fbfe32a..c1a99781a 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
@@ -36,6 +36,7 @@ import androidx.transition.ChangeBounds
 import androidx.transition.TransitionManager
 import kotlinx.coroutines.*
 import org.videolan.medialibrary.interfaces.Medialibrary
+import org.videolan.medialibrary.interfaces.media.Album
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
 import org.videolan.medialibrary.interfaces.media.Playlist
 import org.videolan.medialibrary.media.MediaLibraryItem
@@ -137,7 +138,7 @@ abstract class MediaBrowserFragment<T : SortableModel> : BaseFragment(), Filtera
         val view = view ?: return false
         when (item) {
             is Playlist -> lifecycleScope.snackerConfirm(view, getString(R.string.confirm_delete_playlist, item.title)) { MediaUtils.deletePlaylist(item) }
-            is MediaWrapper -> {
+            is MediaWrapper-> {
                 val deleteAction = Runnable {
                     if (isStarted()) lifecycleScope.launch {
                         if (!MediaUtils.deleteMedia(item, null)) onDeleteFailed(item)
@@ -146,6 +147,15 @@ abstract class MediaBrowserFragment<T : SortableModel> : BaseFragment(), Filtera
                 val resid = if (item.type == MediaWrapper.TYPE_DIR) R.string.confirm_delete_folder else R.string.confirm_delete
                 lifecycleScope.snackerConfirm(view, getString(resid, item.getTitle())) { if (Permissions.checkWritePermission(requireActivity(), item, deleteAction)) deleteAction.run() }
             }
+            is Album -> {
+                val deleteAction = Runnable {
+                    if (isStarted()) lifecycleScope.launch {
+                        if (!MediaUtils.deleteMedia(item, null)) onDeleteFailed(item)
+                    }
+                }
+                val resid = R.string.confirm_delete_album
+                lifecycleScope.snackerConfirm(view, getString(resid, item.getTitle())) { if (item.tracks.any { Permissions.checkWritePermission(requireActivity(), it, deleteAction) }) deleteAction.run() }
+            }
             else -> return false
         }
         return true
diff --git a/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt b/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
index eb26de7d2..9ee66c250 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
@@ -35,13 +35,13 @@ import org.videolan.tools.safeOffer
 import org.videolan.vlc.PlaybackService
 import org.videolan.vlc.R
 import org.videolan.vlc.gui.DialogActivity
-import org.videolan.vlc.gui.InfoActivity
 import org.videolan.vlc.gui.dialogs.SubtitleDownloaderDialogFragment
 import org.videolan.vlc.providers.medialibrary.FoldersProvider
 import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
 import org.videolan.vlc.providers.medialibrary.VideoGroupsProvider
 import org.videolan.vlc.util.FileUtils
 import org.videolan.vlc.util.Permissions
+import java.io.File
 import java.util.*
 import kotlin.collections.ArrayList
 import kotlin.math.min
@@ -89,6 +89,13 @@ object MediaUtils {
         }
         val mediaLibrary = Medialibrary.getInstance()
         for (folder in foldersToReload) mediaLibrary.reload(folder)
+        if (mw is Album) {
+            foldersToReload.forEach {
+                if (File(it).list().isNullOrEmpty()) {
+                    FileUtils.deleteFile(it)
+                }
+            }
+        }
         if (mediaPaths.isEmpty()) {
             failCB?.run()
             false



More information about the Android mailing list