[Android] Fix a DuplicateWarningDialog bug

Yashraj Singh Jadon git at videolan.org
Tue Feb 13 10:36:01 UTC 2024


vlc-android | branch: master | Yashraj Singh Jadon <yashr7651 at gmail.com> | Thu Feb  1 17:13:25 2024 +0530| [43d6c20c3148a5a9bbab61871d36e81904f30400] | committer: Nicolas Pomepuy

Fix a DuplicateWarningDialog bug

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

 .../resources/src/main/res/values/strings.xml      |  8 +++---
 application/vlc-android/res/layout/simple_item.xml |  3 ---
 .../src/org/videolan/vlc/gui/SimpleAdapter.kt      |  1 -
 .../vlc/gui/dialogs/DuplicationWarningDialog.kt    | 31 +++++++++++++++++-----
 4 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index c18721d345..5e76d1f264 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -1073,12 +1073,12 @@
     <string name="banned_tv">Banned folder</string>
     <string name="banned_parent">Banned by parent folder</string>
     <plurals name="duplication_two_options_secondary">
-        <item quantity="one">This item is already in <![CDATA[<b>\"%s\"</b>]]> playlist.</item>
-        <item quantity="other">These items are already in <![CDATA[<b>\"%s\"</b>]]>  playlist.</item>
+        <item quantity="one">This item is already in \"%s\" playlist.</item>
+        <item quantity="other">These items are already in \"%s\" playlist.</item>
     </plurals>
     <plurals name="duplication_three_options_secondary">
-        <item quantity="one">1 of the selected items is already in <![CDATA[<b>\"%s\"</b>]]> playlist.</item>
-        <item quantity="other">%d of the selected items are already in <![CDATA[<b>\"%s\"</b>]]> playlist.</item>
+        <item quantity="one">1 of the selected items is already in \"%s\" playlist.</item>
+        <item quantity="other">%d of the selected items are already in \"%s\" playlist.</item>
     </plurals>
     <string name="official_website">Official website</string>
     <string name="view_online">View online</string>
diff --git a/application/vlc-android/res/layout/simple_item.xml b/application/vlc-android/res/layout/simple_item.xml
index c94352b1b8..25ff5a218c 100644
--- a/application/vlc-android/res/layout/simple_item.xml
+++ b/application/vlc-android/res/layout/simple_item.xml
@@ -33,9 +33,6 @@
             name="position"
             type="int" />
 
-        <variable
-            name="holder"
-            type="org.videolan.vlc.gui.SimpleAdapter.ViewHolder" />
     </data>
 
     <androidx.constraintlayout.widget.ConstraintLayout
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/SimpleAdapter.kt b/application/vlc-android/src/org/videolan/vlc/gui/SimpleAdapter.kt
index 3b3c7e071b..03f904b3d5 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/SimpleAdapter.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/SimpleAdapter.kt
@@ -56,7 +56,6 @@ class SimpleAdapter(val handler: ClickHandler) : ListAdapter<MediaLibraryItem, S
     inner class ViewHolder(handler: ClickHandler,  binding: SimpleItemBinding) :  SelectorViewHolder<SimpleItemBinding>(binding) {
         init {
             binding.handler = handler
-            binding.holder = this
         }
 
         override fun selectView(selected: Boolean) {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/DuplicationWarningDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/DuplicationWarningDialog.kt
index 2b80d85b12..1246d833a1 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/DuplicationWarningDialog.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/DuplicationWarningDialog.kt
@@ -1,13 +1,19 @@
 package org.videolan.vlc.gui.dialogs
 
+import android.graphics.Color
+import android.graphics.Typeface
 import android.os.Bundle
-import android.text.Html
+import android.text.SpannableString
+import android.text.Spanned
+import android.text.style.ForegroundColorSpan
+import android.text.style.StyleSpan
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
 import androidx.core.os.bundleOf
 import androidx.fragment.app.setFragmentResult
 import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
+import com.google.android.material.color.MaterialColors
 import org.videolan.vlc.R
 import org.videolan.vlc.databinding.DialogDuplicationWarningBinding
 
@@ -48,13 +54,21 @@ class DuplicationWarningDialog : VLCBottomSheetDialogFragment(), View.OnClickLis
             binding.addAllButton.setOnClickListener(this)
             binding.addNewButton.setOnClickListener(this)
             binding.cancelButton.setOnClickListener(this)
-            setupSecondaryText(R.plurals.duplication_three_options_secondary)
+            val pluralSecondary = R.plurals.duplication_three_options_secondary
+            val secondaryMessage = if (duplicatesCount == 1)
+                resources.getQuantityString(pluralSecondary, duplicatesCount,playlistTitle)
+            else
+                resources.getQuantityString(pluralSecondary, duplicatesCount,duplicatesCount,playlistTitle)
+            setupSecondaryText(secondaryMessage)
         } else {
             binding.addNewButton.visibility = View.GONE
             binding.addAllButton.text = resources.getString(R.string.add_button)
             binding.addAllButton.setOnClickListener(this)
             binding.cancelButton.setOnClickListener(this)
-            setupSecondaryText(R.plurals.duplication_two_options_secondary)
+            val pluralSecondary = R.plurals.duplication_two_options_secondary
+            val secondaryMessage = resources.getQuantityString(pluralSecondary, duplicatesCount,playlistTitle)
+
+            setupSecondaryText(secondaryMessage)
         }
     }
 
@@ -78,9 +92,14 @@ class DuplicationWarningDialog : VLCBottomSheetDialogFragment(), View.OnClickLis
         dismiss()
     }
 
-    private fun setupSecondaryText(pluralSecondary: Int) {
-        val secondaryMessage = Html.fromHtml(resources.getQuantityString(pluralSecondary, duplicatesCount,playlistTitle))
-        binding.secondaryTextview.text = secondaryMessage
+    private fun setupSecondaryText(secondaryMessage: String) {
+        val searchTitle = "\"$playlistTitle\""
+        val styledText = SpannableString.valueOf(secondaryMessage)
+        val startIndex = styledText.indexOf(searchTitle)
+        val endIndex = startIndex + searchTitle.length
+        styledText.setSpan(StyleSpan(Typeface.BOLD), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
+        styledText.setSpan(ForegroundColorSpan(MaterialColors.getColor(requireContext(), R.attr.font_default, Color.BLACK)), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
+        binding.secondaryTextview.text = styledText
     }
 
     private fun shouldShowThreeOptions() = duplicatesCount < highlightsCount



More information about the Android mailing list