[Android] Use seauences, as we may process large lists
Geoffrey Métais
git at videolan.org
Mon Feb 24 07:23:49 CET 2020
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Feb 21 18:32:48 2020 +0100| [450c24c41820058b3012aab2ca64ea6ae22bcea7] | committer: Geoffrey Métais
Use seauences, as we may process large lists
> https://code.videolan.org/videolan/vlc-android/commit/450c24c41820058b3012aab2ca64ea6ae22bcea7
---
.../vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt | 8 +++-----
.../vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt | 2 +-
2 files changed, 4 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..e95261a3f 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,9 @@ 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+1)?.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