Commit f1bb3f03 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Geoffrey Métais
Browse files

Allow long click to batch select

parent da59cfb0
......@@ -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))
......
......@@ -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
}
......
......@@ -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
}
......
......@@ -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
......
......@@ -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()
}
}
......
......@@ -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
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment