From 19afe0b663fdc9c98bd01e55fb1ef7c8071df96d Mon Sep 17 00:00:00 2001 From: Luca Stefani Date: Thu, 28 Nov 2024 11:40:10 +0100 Subject: [PATCH] Twelve: Don't support nullable audios in playlist We weren't handling it at all, we submitted the list and that was it! If we ever want to handle the media remocal case we need to add a routine to sync local playlist items with media provider. For now having stale entries is good enough. Change-Id: I790cabe57ed9b002eae259c099f05a900013e61d --- .../java/org/lineageos/twelve/datasources/LocalDataSource.kt | 2 +- .../java/org/lineageos/twelve/datasources/MediaDataSource.kt | 3 +-- .../org/lineageos/twelve/datasources/SubsonicDataSource.kt | 2 +- .../java/org/lineageos/twelve/fragments/PlaylistFragment.kt | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/lineageos/twelve/datasources/LocalDataSource.kt b/app/src/main/java/org/lineageos/twelve/datasources/LocalDataSource.kt index 0299b8f9..2a46f717 100644 --- a/app/src/main/java/org/lineageos/twelve/datasources/LocalDataSource.kt +++ b/app/src/main/java/org/lineageos/twelve/datasources/LocalDataSource.kt @@ -535,7 +535,7 @@ class LocalDataSource(context: Context, private val database: TwelveDatabase) : audios(playlistWithItems.items.map(Item::audioUri)) .mapLatest { items -> - RequestStatus.Success<_, MediaError>(playlist to items) + RequestStatus.Success<_, MediaError>(playlist to items.filterNotNull()) } } ?: flowOf( RequestStatus.Error( diff --git a/app/src/main/java/org/lineageos/twelve/datasources/MediaDataSource.kt b/app/src/main/java/org/lineageos/twelve/datasources/MediaDataSource.kt index bb3216fb..389f3a93 100644 --- a/app/src/main/java/org/lineageos/twelve/datasources/MediaDataSource.kt +++ b/app/src/main/java/org/lineageos/twelve/datasources/MediaDataSource.kt @@ -95,9 +95,8 @@ interface MediaDataSource { /** * Get the playlist information and all the tracks of the given playlist. - * If the playlist contains an audio that is unavailable, it will be mapped to null. */ - fun playlist(playlistUri: Uri): Flow>>> + fun playlist(playlistUri: Uri): Flow>>> /** * Get an audio status within all playlists. diff --git a/app/src/main/java/org/lineageos/twelve/datasources/SubsonicDataSource.kt b/app/src/main/java/org/lineageos/twelve/datasources/SubsonicDataSource.kt index 9e22f294..2fbb8967 100644 --- a/app/src/main/java/org/lineageos/twelve/datasources/SubsonicDataSource.kt +++ b/app/src/main/java/org/lineageos/twelve/datasources/SubsonicDataSource.kt @@ -288,7 +288,7 @@ class SubsonicDataSource(arguments: Bundle, cache: Cache? = null) : MediaDataSou subsonicClient.getPlaylist(playlistUri.lastPathSegment!!.toInt()).toRequestStatus { toPlaylist().toMediaItem() to entry.orEmpty().map { it.toMediaItem() - } as List + } } } diff --git a/app/src/main/java/org/lineageos/twelve/fragments/PlaylistFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/PlaylistFragment.kt index 939ec528..8237bd76 100644 --- a/app/src/main/java/org/lineageos/twelve/fragments/PlaylistFragment.kt +++ b/app/src/main/java/org/lineageos/twelve/fragments/PlaylistFragment.kt @@ -253,7 +253,7 @@ class PlaylistFragment : Fragment(R.layout.fragment_playlist) { ) val totalDurationMs = audios.sumOf { audio -> - audio?.durationMs ?: 0 + audio.durationMs } val totalDurationMinutes = (totalDurationMs / 1000 / 60).toInt()