Skip to content

Commit

Permalink
Twelve: Don't support nullable audios in playlist
Browse files Browse the repository at this point in the history
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
  • Loading branch information
luca020400 committed Nov 28, 2024
1 parent 4265a30 commit 19afe0b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MediaRequestStatus<Pair<Playlist, List<Audio?>>>>
fun playlist(playlistUri: Uri): Flow<MediaRequestStatus<Pair<Playlist, List<Audio>>>>

/**
* Get an audio status within all playlists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Audio?>
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 19afe0b

Please sign in to comment.