[Android] Videos: block banning root folder

Duncan McNamara git at videolan.org
Tue Mar 5 08:39:27 UTC 2024


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Thu Feb 22 18:41:08 2024 +0100| [89a2d54718f5019d15f7bb1ae3243777c57e9b9f] | committer: Nicolas Pomepuy

Videos: block banning root folder

Since the addition the ban folder feature to the video section through
context actions, it became possible to ban root folder which wasn't
possible from the "Media library folders" view.

This means that once banned, it isn't possible to unban a root folder.
Because of this, it should be blocked at the context action level, by
checking a path being banned with all root paths in the medialibrary.

Fixes #3042

> https://code.videolan.org/videolan/vlc-android/commit/89a2d54718f5019d15f7bb1ae3243777c57e9b9f
---

 application/resources/src/main/res/values/strings.xml    |  1 +
 .../src/org/videolan/vlc/gui/video/VideoGridFragment.kt  | 16 +++++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 0715670a61..a450b6d068 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -151,6 +151,7 @@
     <string name="nosubfolder">No subfolder</string>
     <string name="directorynotfound">The directory path \'%1$s\' was not found.</string>
     <string name="nohistory">You have no playback history yet.</string>
+    <string name="cant_ban_root">You can\'t ban a root folder</string>
 
     <string name="cover_art">Cover art</string>
     <string name="shuffle_all_title">Shuffle all</string>
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
index 0dc4356445..0ce0a0bdb2 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
@@ -569,7 +569,21 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
 
     private fun banFolder(folder: Folder) {
         folder.mMrl.toUri().path?.let { path ->
-            MedialibraryUtils.banDir(path.removePrefix("file://"))
+            lifecycleScope.launch(Dispatchers.IO) {
+                val roots: Array<String> = Medialibrary.getInstance().foldersList
+                val strippedPath = path.removePrefix("file://")
+                for (root in roots) {
+                    if (root.removePrefix("file://") == strippedPath) {
+                        Log.w(TAG, "banFolder: trying to ban root: $root")
+                        lifecycleScope.launch(Dispatchers.Main) {
+                            UiTools.snacker(requireActivity(), getString(R.string.cant_ban_root))
+                        }
+                        return at launch
+                    }
+                }
+                MedialibraryUtils.banDir(strippedPath)
+            }
+
         } ?: Log.e(TAG, "banFolder: path is null")
     }
 



More information about the Android mailing list