[Android] Replace array copies with a sublist

Robert Stone git at videolan.org
Fri Nov 13 07:31:03 CET 2020


vlc-android | branch: 3.3.x | Robert Stone <rhstone at gmail.com> | Sun Nov  1 19:34:42 2020 -0800| [0f9fb8116e493ba19991c9d2c1ab292d59610041] | committer: Nicolas Pomepuy

Replace array copies with a sublist

(cherry picked from commit 13fe216b108796565a0346453ea0b4c8855980fd)

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

 .../src/org/videolan/vlc/MediaSessionCallback.kt            | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
index d39a46c72..3967d21d5 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
@@ -16,7 +16,6 @@ import org.videolan.resources.MEDIALIBRARY_PAGE_SIZE
 import org.videolan.resources.util.getFromMl
 import org.videolan.vlc.extensions.ExtensionsManager
 import org.videolan.vlc.media.MediaSessionBrowser
-import org.videolan.vlc.media.MediaSessionBrowser.Companion.MAX_HISTORY_SIZE
 import org.videolan.vlc.util.VoiceSearchParams
 import org.videolan.vlc.util.awaitMedialibraryStarted
 import java.util.*
@@ -74,16 +73,16 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
                     }
                 }
                 mediaId == MediaSessionBrowser.ID_LAST_ADDED -> {
-                    val tracks = context.getFromMl { recentAudio }
-                    if (tracks.isNotEmpty() && isActive) {
-                        val mediaList = tracks.copyOfRange(0, tracks.size.coerceAtMost(MediaSessionBrowser.MAX_HISTORY_SIZE))
+                    val tracks = context.getFromMl { recentAudio?.toList() }
+                    if (!tracks.isNullOrEmpty() && isActive) {
+                        val mediaList = tracks.subList(0, tracks.size.coerceAtMost(MediaSessionBrowser.MAX_HISTORY_SIZE))
                         playbackService.load(mediaList, 0)
                     }
                 }
                 mediaId == MediaSessionBrowser.ID_HISTORY -> {
-                    val tracks = context.getFromMl { lastMediaPlayed() }
-                    if (tracks.isNotEmpty() && isActive) {
-                        val mediaList = tracks.copyOfRange(0, tracks.size.coerceAtMost(MediaSessionBrowser.MAX_HISTORY_SIZE))
+                    val tracks = context.getFromMl { lastMediaPlayed()?.toList() }
+                    if (!tracks.isNullOrEmpty() && isActive) {
+                        val mediaList = tracks.subList(0, tracks.size.coerceAtMost(MediaSessionBrowser.MAX_HISTORY_SIZE))
                         playbackService.load(mediaList, 0)
                     }
                 }



More information about the Android mailing list