[Android] Allow long click to batch select

Nicolas Pomepuy git at videolan.org
Thu Jun 27 11:02:32 CEST 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Wed Jun 26 10:59:37 2019 +0200| [f1bb3f032ad6c33532e1f50f76c21131a43e1b19] | committer: Geoffrey Métais

Allow long click to batch select

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

 tools/src/main/java/org/videolan/tools/MultiSelectHelper.kt    |  4 ++--
 vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt       | 10 ++--------
 vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt |  5 ++---
 .../src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt    |  8 ++------
 .../src/org/videolan/vlc/gui/folders/FoldersFragment.kt        |  2 +-
 .../src/org/videolan/vlc/gui/video/VideoGridFragment.kt        |  7 +------
 6 files changed, 10 insertions(+), 26 deletions(-)

diff --git a/tools/src/main/java/org/videolan/tools/MultiSelectHelper.kt b/tools/src/main/java/org/videolan/tools/MultiSelectHelper.kt
index aeaacda64..c27c79e5d 100644
--- a/tools/src/main/java/org/videolan/tools/MultiSelectHelper.kt
+++ b/tools/src/main/java/org/videolan/tools/MultiSelectHelper.kt
@@ -19,8 +19,8 @@ class MultiSelectHelper<T>(val adapter: MultiSelectAdapter<T>, private val paylo
     @MainThread
     fun getSelectionCount() = selectionMap.size()
 
-    fun toggleSelection(position: Int) {
-        if (KeyHelper.isShiftPressed && selectionMap.size() != 0) {
+    fun toggleSelection(position: Int, forceShift: Boolean = false) {
+        if ((KeyHelper.isShiftPressed || forceShift) && selectionMap.size() != 0) {
             val positions = HashSet<Int>()
             for (i in 0 until selectionMap.size()) {
                 positions.add(selectionMap.keyAt(i))
diff --git a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt
index 390fd766b..a4c433239 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt
@@ -50,7 +50,6 @@ import kotlinx.coroutines.*
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.medialibrary.media.MediaWrapper
 import org.videolan.medialibrary.media.Playlist
-import org.videolan.tools.KeyHelper
 import org.videolan.tools.isStarted
 import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.R
@@ -169,10 +168,6 @@ open class PlaylistActivity : AudioPlayerContainerActivity(), IEventsHandler, IL
     }
 
     override fun onClick(v: View, position: Int, item: MediaLibraryItem) {
-        if (KeyHelper.isShiftPressed && actionMode == null) {
-            onLongClick(v, position, item)
-            return
-        }
         if (actionMode != null) {
             audioBrowserAdapter.multiSelectHelper.toggleSelection(position)
             invalidateActionMode()
@@ -181,9 +176,8 @@ open class PlaylistActivity : AudioPlayerContainerActivity(), IEventsHandler, IL
     }
 
     override fun onLongClick(v: View, position: Int, item: MediaLibraryItem): Boolean {
-        if (actionMode != null) return false
-        audioBrowserAdapter.multiSelectHelper.toggleSelection(position)
-        startActionMode()
+        audioBrowserAdapter.multiSelectHelper.toggleSelection(position, true)
+        if (actionMode == null) startActionMode()
         return true
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt b/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
index df792d6cd..5f570f7e8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
@@ -217,9 +217,8 @@ abstract class BaseAudioBrowser<T : SortableModel> : MediaBrowserFragment<T>(),
     }
 
     override fun onLongClick(v: View, position: Int, item: MediaLibraryItem): Boolean {
-        if (actionMode != null) return false
-        getCurrentAdapter()?.multiSelectHelper?.toggleSelection(position)
-        startActionMode()
+        getCurrentAdapter()?.multiSelectHelper?.toggleSelection(position, true)
+        if (actionMode == null) startActionMode()
         return true
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
index 9fca01b22..69c2507a4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
@@ -40,7 +40,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
 import kotlinx.coroutines.*
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.medialibrary.media.MediaWrapper
-import org.videolan.tools.KeyHelper
 import org.videolan.vlc.R
 import org.videolan.vlc.databinding.DirectoryBrowserBinding
 import org.videolan.vlc.gui.AudioPlayerContainerActivity
@@ -388,10 +387,7 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
     }
 
     override fun onClick(v: View, position: Int, item: MediaLibraryItem) {
-        if (KeyHelper.isShiftPressed && actionMode == null) {
-            onLongClick(v, position, item)
-            return
-        }
+
 
         val mediaWrapper = item as MediaWrapper
         if (actionMode != null) {
@@ -415,7 +411,7 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
                 mediaWrapper.type == MediaWrapper.TYPE_VIDEO ||
                 mediaWrapper.type == MediaWrapper.TYPE_DIR) {
             if (actionMode != null) return false
-            adapter.multiSelectHelper.toggleSelection(position)
+            adapter.multiSelectHelper.toggleSelection(position, true)
             startActionMode()
         } else onCtxClick(v, position, item)
         return true
diff --git a/vlc-android/src/org/videolan/vlc/gui/folders/FoldersFragment.kt b/vlc-android/src/org/videolan/vlc/gui/folders/FoldersFragment.kt
index 5fc148774..272acca38 100644
--- a/vlc-android/src/org/videolan/vlc/gui/folders/FoldersFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/folders/FoldersFragment.kt
@@ -45,8 +45,8 @@ class FoldersFragment : MediaBrowserFragment<FoldersViewModel>(), CtxActionRecei
                 }
             }
             is FolderLongClick -> {
+                adapter.multiSelectHelper.toggleSelection(action.position, true)
                 if (actionMode == null) {
-                    adapter.multiSelectHelper.toggleSelection(action.position)
                     startActionMode()
                 }
             }
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
index f5620587e..a3586c1f9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
@@ -42,7 +42,6 @@ import org.videolan.medialibrary.Medialibrary
 import org.videolan.medialibrary.media.Folder
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.medialibrary.media.MediaWrapper
-import org.videolan.tools.KeyHelper
 import org.videolan.tools.MultiSelectHelper
 import org.videolan.vlc.R
 import org.videolan.vlc.databinding.VideoGridBinding
@@ -313,10 +312,6 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
     }
 
     override fun onClick(v: View, position: Int, item: MediaLibraryItem) {
-        if (KeyHelper.isShiftPressed && actionMode == null) {
-            onLongClick(v, position, item)
-            return
-        }
         val media = item as MediaWrapper
         if (actionMode != null) {
             multiSelectHelper.toggleSelection(position)
@@ -341,7 +336,7 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
 
     override fun onLongClick(v: View, position: Int, item: MediaLibraryItem): Boolean {
         if (actionMode != null) return false
-        multiSelectHelper.toggleSelection(position)
+        multiSelectHelper.toggleSelection(position, true)
         startActionMode()
         return true
     }



More information about the Android mailing list