[Android] Check the PIN in the file deletion dialog

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


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jun 27 10:14:56 2023 +0200| [ab811aca339d0346ff3b054207f78e78d287418a] | committer: Duncan McNamara

Check the PIN in the file deletion dialog

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

 .../videolan/vlc/gui/HeaderMediaListActivity.kt    | 26 ++++++++++------------
 .../vlc/gui/dialogs/ConfirmDeleteDialog.kt         |  5 ++++-
 2 files changed, 16 insertions(+), 15 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 ba66263049..fe8a0b6c7f 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
@@ -488,23 +488,21 @@ open class HeaderMediaListActivity : AudioPlayerContainerActivity(), IEventsHand
         }
     }
 
-    private suspend fun removeItems(items: List<MediaWrapper>) {
-        if (checkPIN()){
-            val dialog = ConfirmDeleteDialog.newInstance(ArrayList(items))
-            dialog.show(supportFragmentManager, ConfirmDeleteDialog::class.simpleName)
-            dialog.setListener {
-                lifecycleScope.launch {
-                    for (item in items) {
-                        val deleteAction = kotlinx.coroutines.Runnable {
-                            lifecycleScope.launch {
-                                MediaUtils.deleteItem(this at HeaderMediaListActivity, item) {
-                                    UiTools.snacker(this at HeaderMediaListActivity, getString(R.string.msg_delete_failed, it.title))
-                                }
-                                if (isStarted()) viewModel.refresh()
+    private fun removeItems(items: List<MediaWrapper>) {
+        val dialog = ConfirmDeleteDialog.newInstance(ArrayList(items))
+        dialog.show(supportFragmentManager, ConfirmDeleteDialog::class.simpleName)
+        dialog.setListener {
+            lifecycleScope.launch {
+                for (item in items) {
+                    val deleteAction = kotlinx.coroutines.Runnable {
+                        lifecycleScope.launch {
+                            MediaUtils.deleteItem(this at HeaderMediaListActivity, item) {
+                                UiTools.snacker(this at HeaderMediaListActivity, getString(R.string.msg_delete_failed, it.title))
                             }
+                            if (isStarted()) viewModel.refresh()
                         }
-                        if (Permissions.checkWritePermission(this at HeaderMediaListActivity, item, deleteAction)) deleteAction.run()
                     }
+                    if (Permissions.checkWritePermission(this at HeaderMediaListActivity, item, deleteAction)) deleteAction.run()
                 }
             }
         }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/ConfirmDeleteDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/ConfirmDeleteDialog.kt
index e05b374eae..8733f894cf 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/ConfirmDeleteDialog.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/ConfirmDeleteDialog.kt
@@ -30,16 +30,18 @@ import android.widget.Button
 import android.widget.ImageView
 import android.widget.TextView
 import androidx.core.os.bundleOf
+import androidx.lifecycle.lifecycleScope
 import androidx.vectordrawable.graphics.drawable.Animatable2Compat
 import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
 import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
+import kotlinx.coroutines.launch
 import org.videolan.medialibrary.interfaces.media.Album
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
 import org.videolan.medialibrary.interfaces.media.Playlist
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.resources.util.parcelableList
 import org.videolan.vlc.R
-import java.lang.IllegalStateException
+import org.videolan.vlc.gui.helpers.hf.checkPIN
 
 const val CONFIRM_DELETE_DIALOG_MEDIALIST = "CONFIRM_DELETE_DIALOG_MEDIALIST"
 const val CONFIRM_DELETE_DIALOG_TITLE = "CONFIRM_DELETE_DIALOG_TITLE"
@@ -80,6 +82,7 @@ class ConfirmDeleteDialog : VLCBottomSheetDialogFragment() {
     }
 
     override fun onCreate(savedInstanceState: Bundle?) {
+        lifecycleScope.launch { if (!requireActivity().checkPIN()) dismiss() }
         mediaList = arguments?.parcelableList(CONFIRM_DELETE_DIALOG_MEDIALIST) ?: listOf()
         titleString = arguments?.getString(CONFIRM_DELETE_DIALOG_TITLE)
         descriptionString = arguments?.getString(CONFIRM_DELETE_DIALOG_DESCRIPTION)



More information about the Android mailing list