[Android] Allow changing the video media favorite state in action mode

Nicolas Pomepuy git at videolan.org
Mon Apr 3 11:56:44 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Mar 13 10:49:30 2023 +0100| [e05a514e26dd4a1e088dffa60efbca1502c2c3ac] | committer: Duncan McNamara

Allow changing the video media favorite state in action mode

Fixes #2880

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

 application/vlc-android/res/menu/action_mode_video.xml         | 10 ++++++++++
 application/vlc-android/res/menu/action_mode_video_group.xml   | 10 ++++++++++
 .../src/org/videolan/vlc/gui/video/VideoGridFragment.kt        |  8 ++++++++
 3 files changed, 28 insertions(+)

diff --git a/application/vlc-android/res/menu/action_mode_video.xml b/application/vlc-android/res/menu/action_mode_video.xml
index aac275fa18..da0905f3fc 100644
--- a/application/vlc-android/res/menu/action_mode_video.xml
+++ b/application/vlc-android/res/menu/action_mode_video.xml
@@ -61,4 +61,14 @@
             android:icon="@drawable/ic_am_folder"
             android:visible="false"
             app:showAsAction="ifRoom" />
+    <item
+        android:orderInCategory="6"
+        android:title="@string/favorites_add"
+        app:showAsAction="never"
+        android:id="@+id/action_mode_favorite_add" />
+    <item
+        android:orderInCategory="6"
+        android:title="@string/favorites_remove"
+        app:showAsAction="never"
+        android:id="@+id/action_mode_favorite_remove" />
 </menu>
\ No newline at end of file
diff --git a/application/vlc-android/res/menu/action_mode_video_group.xml b/application/vlc-android/res/menu/action_mode_video_group.xml
index ce14b06129..db4a959405 100644
--- a/application/vlc-android/res/menu/action_mode_video_group.xml
+++ b/application/vlc-android/res/menu/action_mode_video_group.xml
@@ -49,4 +49,14 @@
             android:icon="@drawable/ic_am_folder"
             android:visible="false"
             app:showAsAction="ifRoom" />
+    <item
+            android:orderInCategory="6"
+            android:title="@string/favorites_add"
+            app:showAsAction="never"
+            android:id="@+id/action_mode_favorite_add" />
+    <item
+            android:orderInCategory="6"
+            android:title="@string/favorites_remove"
+            app:showAsAction="never"
+            android:id="@+id/action_mode_favorite_remove" />
 </menu>
\ No newline at end of file
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 73771d3c2b..debe275966 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
@@ -386,6 +386,8 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
             }
             else -> {}
         }
+        menu.findItem(R.id.action_mode_favorite_add).isVisible = multiSelectHelper.getSelection().none { it.isFavorite }
+        menu.findItem(R.id.action_mode_favorite_remove).isVisible = multiSelectHelper.getSelection().none { !it.isFavorite }
         return true
     }
 
@@ -418,6 +420,8 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
                         R.id.action_ungroup -> viewModel.ungroup(list)
                         R.id.action_add_to_group -> addToGroup(list)
                         R.id.action_mode_go_to_folder -> (list.first() as? MediaWrapper)?.let { showParentFolder(it) }
+                        R.id.action_mode_favorite_add -> lifecycleScope.launch { viewModel.changeFavorite(list, true)}
+                        R.id.action_mode_favorite_remove -> lifecycleScope.launch { viewModel.changeFavorite(list, false)}
                         else -> {
                             stopActionMode()
                             return false
@@ -435,6 +439,8 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
                     R.id.action_folder_append -> viewModel.appendFoldersSelection(selection)
                     R.id.action_folder_add_playlist -> lifecycleScope.launch { requireActivity().addToPlaylist(withContext(Dispatchers.Default) { selection.getAll() }) }
                     R.id.action_video_delete -> removeItems(selection.getAll())
+                    R.id.action_mode_favorite_add -> lifecycleScope.launch { viewModel.changeFavorite(selection.getAll(), true)}
+                    R.id.action_mode_favorite_remove -> lifecycleScope.launch { viewModel.changeFavorite(selection.getAll(), false)}
                     else -> return false
                 }
             }
@@ -450,6 +456,8 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
                     R.id.action_add_to_group -> addToGroup(selection)
                     R.id.action_mode_go_to_folder -> (selection.first() as? MediaWrapper)?.let { showParentFolder(it) }
                     R.id.action_video_delete -> removeItems(selection.getAll())
+                    R.id.action_mode_favorite_add -> lifecycleScope.launch { viewModel.changeFavorite(selection.getAll(), true)}
+                    R.id.action_mode_favorite_remove -> lifecycleScope.launch { viewModel.changeFavorite(selection.getAll(), false)}
                     else -> return false
                 }
             }



More information about the Android mailing list