[Android] Equalizer: Fix NPE

Geoffrey Métais git at videolan.org
Fri Jul 19 16:21:52 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jul 19 16:21:34 2019 +0200| [3b2a4179baf6f13f6963056b1528256643c48ef3] | committer: Geoffrey Métais

Equalizer: Fix NPE

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

 .../src/org/videolan/vlc/gui/audio/EqualizerFragment.kt       | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 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 b628f271d..df33944ab 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.kt
@@ -288,7 +288,7 @@ class EqualizerFragment : VLCBottomSheetDialogFragment() {
         input.setText(oldName)
         input.setSelectAllOnFocus(true)
 
-        val container = FrameLayout(context)
+        val container = FrameLayout(requireContext())
         val klNormal = resources.getDimension(R.dimen.kl_normal).toInt()
         container.setPadding(klNormal, 0, klNormal, 0)
 
@@ -321,16 +321,17 @@ class EqualizerFragment : VLCBottomSheetDialogFragment() {
         saveEqualizer.setOnShowListener { dialog ->
             val positiveButton = (dialog as AlertDialog).getButton(AlertDialog.BUTTON_POSITIVE)
             positiveButton.setOnClickListener {
+                val ctx = activity ?: return at setOnClickListener
                 val newName = input.text.toString()
                 if (newName.contains("_") || TextUtils.equals(newName, newPresetName)) {
-                    Toast.makeText(context, VLCApplication.appContext.resources.getString(R.string.custom_set_wrong_input), Toast.LENGTH_SHORT).show()
+                    Toast.makeText(ctx, VLCApplication.appContext.resources.getString(R.string.custom_set_wrong_input), Toast.LENGTH_SHORT).show()
                 } else if (allSets.contains(newName) && !TextUtils.equals(newName, oldName)) {
-                    Toast.makeText(context, VLCApplication.appContext.resources.getString(R.string.custom_set_already_exist), Toast.LENGTH_SHORT).show()
+                    Toast.makeText(ctx, VLCApplication.appContext.resources.getString(R.string.custom_set_already_exist), Toast.LENGTH_SHORT).show()
                 } else {
-                    VLCOptions.saveCustomSet(requireActivity(), temporarySet, newName)
+                    VLCOptions.saveCustomSet(ctx, temporarySet, newName)
                     if (onPause) {
                         if (binding.equalizerButton.isChecked)
-                            VLCOptions.saveEqualizerInSettings(requireActivity(), temporarySet, newName, true, true)
+                            VLCOptions.saveEqualizerInSettings(ctx, temporarySet, newName, true, true)
                     } else {
                         if (TextUtils.equals(newName, oldName)) {
                             if (displayedByUser) {



More information about the Android mailing list