[Android] Equalizer: delay setting band listener to avoid IndexOutOfBoundsException

Nicolas Pomepuy git at videolan.org
Wed Dec 18 10:14:40 CET 2019


vlc-android | branch: 3.2.x | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Wed Dec 18 07:21:46 2019 +0000| [3997671b20ffc21a06ee5ff8b104b4bfa70ba320] | committer: Geoffrey Métais

Equalizer: delay setting band listener to avoid IndexOutOfBoundsException


(cherry picked from commit 32b5077baf4daa077e6735ea1c68efe524ce1abc)

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

 vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.kt | 3 ++-
 vlc-android/src/org/videolan/vlc/gui/view/EqualizerBar.kt       | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.kt b/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.kt
index 5c9c3037a..ab544ba2f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.kt
@@ -181,13 +181,13 @@ class EqualizerFragment : VLCBottomSheetDialogFragment(), CoroutineScope by Main
 
             val bar = EqualizerBar(requireContext(), band)
             bar.setValue(equalizer.getAmp(i))
-            bar.setListener(BandListener(i))
 
             binding.equalizerBands.addView(bar)
 
             val params = LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1f)
             bar.layoutParams = params
             eqBandsViews.add(bar)
+            bar.setListener(BandListener(i))
         }
 
         eqBandsViews[0].nextFocusLeftId = org.videolan.vlc.R.id.equalizer_preamp
@@ -229,6 +229,7 @@ class EqualizerFragment : VLCBottomSheetDialogFragment(), CoroutineScope by Main
     }
 
     override fun onDismiss(dialog: DialogInterface) {
+        eqBandsViews.forEach { it.setListener(null) }
         super.onDismiss(dialog)
         if (!state.saved)
             createSaveCustomSetDialog(binding.equalizerPresets.selectedItemPosition, displayedByUser = false, onPause = true)
diff --git a/vlc-android/src/org/videolan/vlc/gui/view/EqualizerBar.kt b/vlc-android/src/org/videolan/vlc/gui/view/EqualizerBar.kt
index a9166e2c5..f02bf0efb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/view/EqualizerBar.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/view/EqualizerBar.kt
@@ -98,7 +98,7 @@ class EqualizerBar : LinearLayout {
         verticalSeekBar.progress = (value * PRECISION + RANGE).toInt()
     }
 
-    fun setListener(listener: OnEqualizerBarChangeListener) {
+    fun setListener(listener: OnEqualizerBarChangeListener?) {
         this.listener = listener
     }
 



More information about the Android mailing list