[Android] Make the ConfirmDeleteDialog usable for non media destruction

Nicolas Pomepuy git at videolan.org
Thu Jun 10 11:24:07 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jun  1 07:56:38 2021 +0200| [b356ccf333f5f1b959c41d839685772dd878659d] | committer: Nicolas Pomepuy

Make the ConfirmDeleteDialog usable for non media destruction

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

 .../vlc/gui/dialogs/ConfirmDeleteDialog.kt         | 30 +++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

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 326031980..f9a061846 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
@@ -43,6 +43,9 @@ import org.videolan.vlc.R
 import java.lang.IllegalStateException
 
 const val CONFIRM_DELETE_DIALOG_MEDIALIST = "CONFIRM_DELETE_DIALOG_MEDIALIST"
+const val CONFIRM_DELETE_DIALOG_TITLE = "CONFIRM_DELETE_DIALOG_TITLE"
+const val CONFIRM_DELETE_DIALOG_DESCRIPTION = "CONFIRM_DELETE_DIALOG_DESCRIPTION"
+const val CONFIRM_DELETE_DIALOG_BUTTON_TEXT = "CONFIRM_DELETE_DIALOG_BUTTON_TEXT"
 
 @ObsoleteCoroutinesApi
 @ExperimentalCoroutinesApi
@@ -51,14 +54,26 @@ class ConfirmDeleteDialog : VLCBottomSheetDialogFragment() {
     private lateinit var listener: () -> Unit
     private lateinit var deleteAnimation: ImageView
     private lateinit var title: TextView
+    private lateinit var description: TextView
+    private lateinit var deleteButton: Button
     private lateinit var mediaList: List<MediaLibraryItem>
+    private var titleString: String? = null
+    private var descriptionString: String? = null
+    private var buttonText: String? = null
 
     companion object {
 
-        fun newInstance(medias: ArrayList<MediaLibraryItem>): ConfirmDeleteDialog {
+        /**
+         * Create a new ConfirmDeleteDialog
+         * @param medias the list of media used to create the title. If not relevant, use [title], [description] and [buttonText]
+         * @param title the title to be used
+         * @param description the description to be used
+         * @param buttonText the button's text to be used
+         */
+        fun newInstance(medias: ArrayList<MediaLibraryItem> = arrayListOf(), title:String ="", description:String ="", buttonText:String=""): ConfirmDeleteDialog {
 
             return ConfirmDeleteDialog().apply {
-                arguments = bundleOf(CONFIRM_DELETE_DIALOG_MEDIALIST to medias)
+                arguments = bundleOf(CONFIRM_DELETE_DIALOG_MEDIALIST to medias,CONFIRM_DELETE_DIALOG_TITLE to title,CONFIRM_DELETE_DIALOG_DESCRIPTION to description, CONFIRM_DELETE_DIALOG_BUTTON_TEXT to buttonText)
             }
         }
     }
@@ -68,7 +83,10 @@ class ConfirmDeleteDialog : VLCBottomSheetDialogFragment() {
     }
 
     override fun onCreate(savedInstanceState: Bundle?) {
-        mediaList = arguments?.getParcelableArrayList(CONFIRM_DELETE_DIALOG_MEDIALIST) ?: throw IllegalStateException("List cannot be empty")
+        mediaList = arguments?.getParcelableArrayList(CONFIRM_DELETE_DIALOG_MEDIALIST) ?: listOf()
+        titleString = arguments?.getString(CONFIRM_DELETE_DIALOG_TITLE)
+        descriptionString = arguments?.getString(CONFIRM_DELETE_DIALOG_DESCRIPTION)
+        buttonText = arguments?.getString(CONFIRM_DELETE_DIALOG_BUTTON_TEXT)
         super.onCreate(savedInstanceState)
     }
 
@@ -76,6 +94,8 @@ class ConfirmDeleteDialog : VLCBottomSheetDialogFragment() {
         val view = inflater.inflate(R.layout.dialog_confirm_delete, container)
         deleteAnimation = view.findViewById(R.id.delete_animation)
         title = view.findViewById(R.id.title)
+        description = view.findViewById(R.id.message)
+        deleteButton = view.findViewById(R.id.delete_button)
         view.findViewById<Button>(R.id.delete_button).setOnClickListener {
             listener.invoke()
             dismiss()
@@ -85,6 +105,7 @@ class ConfirmDeleteDialog : VLCBottomSheetDialogFragment() {
         }
 
         title.text = when {
+            mediaList.isEmpty() -> titleString
             mediaList.size > 1 && mediaList.filterIsInstance<MediaWrapper>().size == mediaList.size -> {
                 //folders and files
                 val nbFiles = mediaList.filter { it is MediaWrapper && it.type != MediaWrapper.TYPE_DIR }.size
@@ -102,6 +123,9 @@ class ConfirmDeleteDialog : VLCBottomSheetDialogFragment() {
             else -> getString(R.string.confirm_delete_several_media, mediaList.size)
         }
 
+        if (descriptionString?.isNotEmpty() == true) description.text = descriptionString
+        if (buttonText?.isNotEmpty() == true) deleteButton.text = buttonText
+
 
         val anim = AnimatedVectorDrawableCompat.create(requireActivity(), R.drawable.anim_delete)!!
         deleteAnimation.setImageDrawable(anim)



More information about the Android mailing list