[Android] Fix NPE if playlist is null

Robert Stone git at videolan.org
Mon Jun 26 07:45:43 UTC 2023


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Mon Jun  5 21:10:28 2023 -0700| [75880b0516e587cad876a2727b401a7a308ae46a] | committer: Robert Stone

Fix NPE if playlist is null

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

 .../src/org/videolan/vlc/gui/HeaderMediaListActivity.kt       | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
index 08668cf221..de3f04d2f4 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
@@ -129,16 +129,11 @@ open class HeaderMediaListActivity : AudioPlayerContainerActivity(), IEventsHand
 
         viewModel.playlistLiveData.observe(this) { playlist ->
             binding.btnFavorite.setImageDrawable(
-                ContextCompat.getDrawable(
-                    this,
-                    if (playlist.isFavorite) R.drawable.ic_header_media_favorite else R.drawable.ic_header_media_favorite_outline
+                ContextCompat.getDrawable(this,
+                    if (playlist?.isFavorite == true) R.drawable.ic_header_media_favorite else R.drawable.ic_header_media_favorite_outline
                 )
             )
-
-            var totalDuration = 0L
-            for (item in playlist.tracks)
-                totalDuration += item.length
-            binding.totalDuration = totalDuration
+            binding.totalDuration = playlist?.tracks?.sumOf { it.length } ?: 0
 
             if (playlist is Album) {
                 val releaseYear = playlist.releaseYear



More information about the Android mailing list