[Android] Replace array copies with a sublist
Robert Stone
git at videolan.org
Thu Nov 5 06:55:10 CET 2020
vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Sun Nov 1 19:34:42 2020 -0800| [13fe216b108796565a0346453ea0b4c8855980fd] | committer: Nicolas Pomepuy
Replace array copies with a sublist
> https://code.videolan.org/videolan/vlc-android/commit/13fe216b108796565a0346453ea0b4c8855980fd
---
.../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