[Android] Forbid playlist reorder gesture when safe mode is locked

Nicolas Pomepuy git at videolan.org
Wed Jul 12 08:30:37 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Jul 10 14:15:36 2023 +0200| [25ff1521ac128fcfb883da879c647e0a99a5ef31] | committer: Duncan McNamara

Forbid playlist reorder gesture when safe mode is locked

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

 .../src/org/videolan/vlc/gui/HeaderMediaListActivity.kt           | 5 ++++-
 .../videolan/vlc/gui/helpers/SwipeDragItemTouchHelperCallback.kt  | 8 +++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
index 7908532341..a249d86da3 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
@@ -150,7 +150,10 @@ open class HeaderMediaListActivity : AudioPlayerContainerActivity(), IEventsHand
 
         if (isPlaylist) {
             audioBrowserAdapter = AudioBrowserAdapter(MediaLibraryItem.TYPE_MEDIA, this, this, isPlaylist)
-            itemTouchHelperCallback = SwipeDragItemTouchHelperCallback(audioBrowserAdapter)
+            itemTouchHelperCallback = SwipeDragItemTouchHelperCallback(audioBrowserAdapter, lockedInSafeMode = true)
+            itemTouchHelperCallback.swipeAttemptListener = {
+                lifecycleScope.launch { showPinIfNeeded() }
+            }
             itemTouchHelper = ItemTouchHelper(itemTouchHelperCallback)
             itemTouchHelper!!.attachToRecyclerView(binding.songs)
             binding.releaseDate.visibility = View.GONE
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/SwipeDragItemTouchHelperCallback.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/SwipeDragItemTouchHelperCallback.kt
index 1a57b7d3a5..6fc4601cff 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/SwipeDragItemTouchHelperCallback.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/SwipeDragItemTouchHelperCallback.kt
@@ -25,12 +25,14 @@ package org.videolan.vlc.gui.helpers
 
 import androidx.recyclerview.widget.ItemTouchHelper
 import androidx.recyclerview.widget.RecyclerView
+import org.videolan.vlc.gui.helpers.hf.PinCodeDelegate
 import org.videolan.vlc.interfaces.SwipeDragHelperAdapter
 
-class SwipeDragItemTouchHelperCallback(private val mAdapter: SwipeDragHelperAdapter, private val longPressDragEnable: Boolean = false) : ItemTouchHelper.Callback() {
+class SwipeDragItemTouchHelperCallback(private val mAdapter: SwipeDragHelperAdapter, private val longPressDragEnable: Boolean = false, private val lockedInSafeMode: Boolean = false) : ItemTouchHelper.Callback() {
     private var dragFrom = -1
     private var dragTo = -1
     var swipeEnabled = true
+    var swipeAttemptListener: (() -> Unit)? = null
 
     override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int {
         val dragFlags = ItemTouchHelper.UP or ItemTouchHelper.DOWN
@@ -39,6 +41,10 @@ class SwipeDragItemTouchHelperCallback(private val mAdapter: SwipeDragHelperAdap
     }
 
     override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
+        if (lockedInSafeMode && PinCodeDelegate.pinUnlocked.value == false) {
+            swipeAttemptListener?.invoke()
+            return false
+        }
         mAdapter.onItemMove(viewHolder.layoutPosition, target.layoutPosition)
         val fromPosition = viewHolder.layoutPosition
         val toPosition = target.layoutPosition



More information about the Android mailing list