[Android] Fix leak on the bookmark list delegate in the video player

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:27:16 2023 +0200| [c23f97f77d13489a2c79821b31811c35e71fccaf] | committer: Duncan McNamara

Fix leak on the bookmark list delegate in the video player

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

 .../videolan/vlc/gui/video/VideoPlayerActivity.kt  |  1 +
 .../vlc/gui/video/VideoPlayerOverlayDelegate.kt    | 27 ++++++++++++----------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index 1a58b81ca6..b6b7228fc8 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -855,6 +855,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
             onCleared()
         }
         optionsDelegate = null
+        overlayDelegate.onDestroy()
 
         // Dismiss the presentation when the activity is not visible.
         displayManager.release()
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerOverlayDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerOverlayDelegate.kt
index caebc94b35..1c2321ffd1 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerOverlayDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerOverlayDelegate.kt
@@ -113,7 +113,7 @@ class VideoPlayerOverlayDelegate (private val player: VideoPlayerActivity) {
     private var hingeSnackShown: Boolean = false
 
     var enableSubs = true
-    private lateinit var bookmarkListDelegate: BookmarkListDelegate
+    private var bookmarkListDelegate: BookmarkListDelegate? = null
 
     fun isHudBindingInitialized() = ::hudBinding.isInitialized
     fun isHudRightBindingInitialized() = ::hudRightBinding.isInitialized
@@ -430,7 +430,7 @@ class VideoPlayerOverlayDelegate (private val player: VideoPlayerActivity) {
                         player.handler.sendMessageDelayed(player.handler.obtainMessage(VideoPlayerActivity.FADE_OUT), overlayTimeout.toLong())
                     hudBinding.playerOverlayPlay.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
                     if (isBookmarkShown())try {
-                        if (player.isTalkbackIsEnabled()) bookmarkListDelegate.addBookmarButton.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
+                        if (player.isTalkbackIsEnabled()) bookmarkListDelegate?.addBookmarButton?.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
                     } catch (e: Exception) {
                     }
                 }
@@ -980,36 +980,39 @@ class VideoPlayerOverlayDelegate (private val player: VideoPlayerActivity) {
 
     fun showBookmarks() {
         player.service?.let {
-            if (!this::bookmarkListDelegate.isInitialized) {
+            if (bookmarkListDelegate == null) {
                 bookmarkListDelegate = BookmarkListDelegate(player, it, player.bookmarkModel)
-                bookmarkListDelegate.markerContainer = hudBinding.bookmarkMarkerContainer
-                bookmarkListDelegate.visibilityListener = {
-                    if (bookmarkListDelegate.visible) showOverlayTimeout(VideoPlayerActivity.OVERLAY_INFINITE)
+                bookmarkListDelegate?.markerContainer = hudBinding.bookmarkMarkerContainer
+                bookmarkListDelegate?.visibilityListener = {
+                    if (bookmarkListDelegate?.visible == true) showOverlayTimeout(VideoPlayerActivity.OVERLAY_INFINITE)
                     else showOverlayTimeout(Settings.videoHudDelay * 1000)
                 }
             }
-            bookmarkListDelegate.show()
+            bookmarkListDelegate?.show()
             val top = hudBinding.playerOverlaySeekbar.top
-            bookmarkListDelegate.setProgressHeight((top + 12.dp).toFloat())
+            bookmarkListDelegate?.setProgressHeight((top + 12.dp).toFloat())
         }
     }
 
     fun rotateBookmarks() {
-        if (::bookmarkListDelegate.isInitialized && isBookmarkShown()) {
+        if (bookmarkListDelegate != null && isBookmarkShown()) {
             //make sure the rotation is complete and layout is done before resetting the bookmarks' layout
             hudBinding.progressOverlay.post {
-                bookmarkListDelegate.hide()
+                bookmarkListDelegate?.hide()
                 showBookmarks()
             }
         }
     }
 
-    fun isBookmarkShown() = ::bookmarkListDelegate.isInitialized && bookmarkListDelegate.visible
+    fun isBookmarkShown() = bookmarkListDelegate != null && bookmarkListDelegate?.visible == true
     fun hideBookmarks() {
-        bookmarkListDelegate.hide()
+        bookmarkListDelegate?.hide()
     }
 
     fun getOverlayBrightness() = if (::playerOverlayBrightness.isInitialized) playerOverlayBrightness else null
 
     fun getOverlayVolume() = if (::playerOverlayVolume.isInitialized) playerOverlayVolume else null
+    fun onDestroy() {
+        bookmarkListDelegate = null
+    }
 }
\ No newline at end of file



More information about the Android mailing list