[Android] Use sequences, as we may process large lists
Geoffrey Métais
git at videolan.org
Mon Feb 24 10:10:34 CET 2020
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Feb 21 18:32:48 2020 +0100| [587229dfd878b120e1fd7d4605c33df937fd982b] | committer: Geoffrey Métais
Use sequences, as we may process large lists
> https://code.videolan.org/videolan/vlc-android/commit/587229dfd878b120e1fd7d4605c33df937fd982b
---
.../vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt | 9 ++++-----
.../vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt | 2 +-
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index 8458fe2a2..c46d7d4d7 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -303,11 +303,10 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
binding.progressBar.progress = progress.time.toInt()
}
- val elapsedTracksTime = playlistModel.medias?.run {
- subList(0, playlistModel.currentMediaPosition).map {
- if (it.length != 0L) it.length else it.time
- }.sum()
- } ?: 0L
+ val elapsedTracksTime = playlistModel.medias?.asSequence()
+ ?.take(playlistModel.currentMediaPosition)
+ ?.map { if (it.length != 0L) it.length else it.time }
+ ?.sum() ?: 0L
val totalTime = elapsedTracksTime + progress.time
val currentProgressText = if (totalTime == 0L) "0s" else Tools.millisToString(totalTime, true, false, false)
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
index 55c206093..96f15b68b 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
@@ -226,7 +226,7 @@ class PlaylistModel : ViewModel(), PlaybackService.Callback by EmptyPBSCallback
}
private fun updateTotalTime() = viewModelScope.launch{
- val totalLength = medias?.map {
+ val totalLength = medias?.asSequence()?.map {
if (it.length != 0L) it.length else it.time
}?.sum() ?: 0L
totalTime = Tools.millisToString(totalLength, true, false, false)
More information about the Android
mailing list