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

Nicolas Pomepuy git at videolan.org
Wed Dec 18 10:13:53 CET 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Wed Dec 18 08:21:46 2019 +0100| [32b5077baf4daa077e6735ea1c68efe524ce1abc] | committer: Nicolas Pomepuy

Equalizer: delay setting band listener to avoid IndexOutOfBoundsException

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

 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 2813cd661..4677bbdf8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.kt
@@ -182,13 +182,13 @@ class EqualizerFragment : VLCBottomSheetDialogFragment() {
 
             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
@@ -230,6 +230,7 @@ class EqualizerFragment : VLCBottomSheetDialogFragment() {
     }
 
     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