[Android] Fix leak on the audio player options delegate

Nicolas Pomepuy git at videolan.org
Wed Oct 11 16:41:42 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Oct 11 09:11:29 2023 +0200| [b62757195cefc8d4332b9349554ffe87b97869fa] | committer: Duncan McNamara

Fix leak on the audio player options delegate

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

 .../television/ui/audioplayer/AudioPlayerActivity.kt    | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/application/television/src/main/java/org/videolan/television/ui/audioplayer/AudioPlayerActivity.kt b/application/television/src/main/java/org/videolan/television/ui/audioplayer/AudioPlayerActivity.kt
index bd3d79ec4f..93731083a0 100644
--- a/application/television/src/main/java/org/videolan/television/ui/audioplayer/AudioPlayerActivity.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/audioplayer/AudioPlayerActivity.kt
@@ -73,7 +73,7 @@ class AudioPlayerActivity : BaseTvActivity(),KeycodeListener  {
     private var settings: SharedPreferences? = null
     private lateinit var pauseToPlay: AnimatedVectorDrawableCompat
     private lateinit var playToPause: AnimatedVectorDrawableCompat
-    private lateinit var optionsDelegate: PlayerOptionsDelegate
+    private var optionsDelegate: PlayerOptionsDelegate? = null
     lateinit var bookmarkModel: BookmarkModel
     private lateinit var bookmarkListDelegate: BookmarkListDelegate
     private val playerKeyListenerDelegate: PlayerKeyListenerDelegate by lazy(LazyThreadSafetyMode.NONE) { PlayerKeyListenerDelegate(this at AudioPlayerActivity) }
@@ -130,8 +130,8 @@ class AudioPlayerActivity : BaseTvActivity(),KeycodeListener  {
         bookmarkModel = BookmarkModel.get(this)
         onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
             override fun handleOnBackPressed() {
-                if (this at AudioPlayerActivity::optionsDelegate.isInitialized && optionsDelegate.isShowing()) {
-                    optionsDelegate.hide()
+                if (optionsDelegate?.isShowing() == true) {
+                    optionsDelegate?.hide()
                     return
                 }
                 if (::bookmarkListDelegate.isInitialized && bookmarkListDelegate.visible) {
@@ -143,6 +143,11 @@ class AudioPlayerActivity : BaseTvActivity(),KeycodeListener  {
         })
     }
 
+    override fun onDestroy() {
+        super.onDestroy()
+        optionsDelegate = null
+    }
+
     private var timelineListener: SeekBar.OnSeekBarChangeListener = object : SeekBar.OnSeekBarChangeListener {
 
         override fun onStopTrackingTouch(seekBar: SeekBar) {}
@@ -311,14 +316,14 @@ class AudioPlayerActivity : BaseTvActivity(),KeycodeListener  {
     }
 
     private fun showAdvancedOptions(@Suppress("UNUSED_PARAMETER") v: View?) {
-        if (!this::optionsDelegate.isInitialized) {
+        if (optionsDelegate == null) {
             val service = model.service ?: return
             optionsDelegate = PlayerOptionsDelegate(this, service, false)
-            optionsDelegate.setBookmarkClickedListener {
+            optionsDelegate?.setBookmarkClickedListener {
                 lifecycleScope.launch { if (!showPinIfNeeded()) showBookmarks() }
             }
         }
-        optionsDelegate.show()
+        optionsDelegate?.show()
     }
 
     /**



More information about the Android mailing list