[Android] Fix equalizer crash + improve workflow

Nicolas Pomepuy git at videolan.org
Wed Jul 31 15:21:01 CEST 2019


vlc-android | branch: 3.2.x | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Tue Jul 30 08:25:19 2019 +0200| [0201e4883925bedabaf93a8be42a5f1c9cc70216] | committer: Geoffrey Métais

Fix equalizer crash + improve workflow

(cherry picked from commit 1b81e6bc101a018ed70ec210fb13f41211adc3cd)

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

 vlc-android/res/layout/audio_player.xml            |  2 +-
 .../videolan/vlc/gui/audio/EqualizerFragment.kt    | 46 +++++++++++-----------
 2 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/vlc-android/res/layout/audio_player.xml b/vlc-android/res/layout/audio_player.xml
index 80d028d39..13422fd2b 100644
--- a/vlc-android/res/layout/audio_player.xml
+++ b/vlc-android/res/layout/audio_player.xml
@@ -119,7 +119,7 @@
                     android:scaleType="fitXY"
                     android:onClick="@{fragment::onSearchClick}"
                     android:contentDescription="@string/search"
-                    android:src="?attr/ic_menu_search"/>
+                    app:srcCompat="?attr/ic_menu_search"/>
 
             <ImageView
                     android:id="@+id/playlist_switch"
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 df33944ab..d44c3d068 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.kt
@@ -20,6 +20,7 @@
  *****************************************************************************/
 package org.videolan.vlc.gui.audio
 
+import android.content.DialogInterface
 import android.os.Bundle
 import android.text.TextUtils
 import android.view.LayoutInflater
@@ -47,8 +48,6 @@ import org.videolan.vlc.gui.view.EqualizerBar
 import org.videolan.vlc.interfaces.OnEqualizerBarChangeListener
 import org.videolan.vlc.util.Settings
 import org.videolan.vlc.util.VLCOptions
-import java.util.*
-import kotlin.collections.ArrayList
 
 @ObsoleteCoroutinesApi
 @ExperimentalCoroutinesApi
@@ -73,7 +72,7 @@ class EqualizerFragment : VLCBottomSheetDialogFragment() {
 
     private val eqBandsViews = ArrayList<EqualizerBar>()
 
-    private val mSetListener = object : OnItemSelectedListener {
+    private val setListener = object : OnItemSelectedListener {
         override fun onItemSelected(parent: AdapterView<*>, view: View, pos: Int, id: Long) {
             if (!binding.equalizerButton.isChecked && !updateAlreadyHandled)
                 binding.equalizerButton.isChecked = true
@@ -128,7 +127,7 @@ class EqualizerFragment : VLCBottomSheetDialogFragment() {
 
         allSets.clear()
         allSets = ArrayList()
-        allSets.addAll(Arrays.asList(*presets))
+        allSets.addAll(listOf(*presets))
         presetCount = allSets.size
         for ((key) in Settings.getInstance(requireActivity()).all) {
             if (key.startsWith("custom_equalizer_")) {
@@ -151,26 +150,13 @@ class EqualizerFragment : VLCBottomSheetDialogFragment() {
         adapter = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_dropdown_item, allSets)
         binding.equalizerPresets.adapter = adapter
 
-        // Set the default selection asynchronously to prevent a layout initialization bug.
-        binding.equalizerPresets.post {
-            binding.equalizerPresets.onItemSelectedListener = mSetListener
-            val pos = allSets.indexOf(VLCOptions.getEqualizerNameFromSettings(requireActivity()))
-            state.update(pos, VLCOptions.getEqualizerSavedState(requireActivity()))
-            updateAlreadyHandled = true
-            if (binding.equalizerButton.isChecked || !state.saved) {
-                savePos = pos
-                revertPos = if (getEqualizerType(pos) == TYPE_CUSTOM) pos else 0
-                binding.equalizerPresets.setSelection(pos)
-            } else {
-                updateEqualizer(0)
-            }
-        }
-
         // preamp
         binding.equalizerPreamp.max = 40
         binding.equalizerPreamp.progress = equalizer.preAmp.toInt() + 20
         binding.equalizerPreamp.setOnSeekBarChangeListener(mPreampListener)
 
+        eqBandsViews.clear()
+        binding.equalizerBands.removeAllViews()
         // bands
         for (i in 0 until BAND_COUNT) {
             val band = MediaPlayer.Equalizer.getBandFrequency(i)
@@ -179,10 +165,8 @@ class EqualizerFragment : VLCBottomSheetDialogFragment() {
             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)
@@ -191,6 +175,21 @@ class EqualizerFragment : VLCBottomSheetDialogFragment() {
         eqBandsViews[0].nextFocusLeftId = R.id.equalizer_preamp
         eqBandsViews[eqBandsViews.size - 1].nextFocusRightId = R.id.snapBands
 
+        // Set the default selection asynchronously to prevent a layout initialization bug.
+        binding.equalizerPresets.post {
+            binding.equalizerPresets.onItemSelectedListener = setListener
+            val pos = allSets.indexOf(VLCOptions.getEqualizerNameFromSettings(requireActivity()))
+            state.update(pos, VLCOptions.getEqualizerSavedState(requireActivity()))
+            updateAlreadyHandled = true
+            if (binding.equalizerButton.isChecked || !state.saved) {
+                savePos = pos
+                revertPos = if (getEqualizerType(pos) == TYPE_CUSTOM) pos else 0
+                binding.equalizerPresets.setSelection(pos)
+            } else {
+                updateEqualizer(0)
+            }
+        }
+
     }
 
     override fun onResume() {
@@ -203,13 +202,16 @@ class EqualizerFragment : VLCBottomSheetDialogFragment() {
         binding.equalizerButton.setOnCheckedChangeListener(null)
         binding.equalizerPresets.onItemSelectedListener = null
         binding.equalizerPreamp.setOnSeekBarChangeListener(null)
-        binding.equalizerBands.removeAllViews()
         if (binding.equalizerButton.isChecked) {
             val pos = binding.equalizerPresets.selectedItemPosition
             VLCOptions.saveEqualizerInSettings(requireActivity(), equalizer, allSets[pos], true, state.saved)
         } else {
             VLCOptions.saveEqualizerInSettings(requireActivity(), MediaPlayer.Equalizer.createFromPreset(0), allSets[0], false, true)
         }
+    }
+
+    override fun onDismiss(dialog: DialogInterface) {
+        super.onDismiss(dialog)
         if (!state.saved)
             createSaveCustomSetDialog(binding.equalizerPresets.selectedItemPosition, displayedByUser = false, onPause = true)
     }



More information about the Android mailing list