Skip to content

Commit

Permalink
Remove unneeded null wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
JolandaVerhoef committed Oct 29, 2024
1 parent 68e4c95 commit 6ef36de
Showing 1 changed file with 57 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,71 +50,68 @@ fun UampMediaPlayerScreen(
val volumeUiState by volumeViewModel.volumeUiState.collectAsStateWithLifecycle()
val audioOutput by volumeViewModel.audioOutput.collectAsStateWithLifecycle()
val settingsState by mediaPlayerScreenViewModel.settingsState.collectAsStateWithLifecycle()
val playerState by mediaPlayerScreenViewModel.playerState.collectAsStateWithLifecycle()

playerState?.let { player ->
PlayerScreen(
modifier = modifier,
background = {
val artworkColor = (it.media as? MediaUiModel.Ready)?.artworkColor
if (artworkColor != null) {
ColorBackground(
color = artworkColor,
modifier = Modifier.fillMaxSize(),
)
} else {
ArtworkColorBackground(
paintable = (it.media as? MediaUiModel.Ready)?.artwork as? CoilPaintable,
defaultColor = MaterialTheme.colors.primary,
modifier = Modifier.fillMaxSize(),
)
}
},
playerViewModel = mediaPlayerScreenViewModel,
volumeViewModel = volumeViewModel,
mediaDisplay = { playerUiState ->
PlayerScreen(
modifier = modifier,
background = {
val artworkColor = (it.media as? MediaUiModel.Ready)?.artworkColor
if (artworkColor != null) {
ColorBackground(
color = artworkColor,
modifier = Modifier.fillMaxSize(),
)
} else {
ArtworkColorBackground(
paintable = (it.media as? MediaUiModel.Ready)?.artwork as? CoilPaintable,
defaultColor = MaterialTheme.colors.primary,
modifier = Modifier.fillMaxSize(),
)
}
},
playerViewModel = mediaPlayerScreenViewModel,
volumeViewModel = volumeViewModel,
mediaDisplay = { playerUiState ->
if (settingsState.animated) {
AnimatedMediaInfoDisplay(
media = playerUiState.media,
loading = !playerUiState.connected || playerUiState.media is MediaUiModel.Loading,
)
} else {
DefaultMediaInfoDisplay(playerUiState)
}
},
buttons = { state ->
UampSettingsButtons(
volumeUiState = volumeUiState,
audioOutputUi = audioOutput.toAudioOutputUi(),
onVolumeClick = onVolumeClick,
enabled = state.connected && state.media != null,
)
},
controlButtons = { playerUiController, playerUiState ->
if (settingsState.podcastControls) {
PlayerScreenPodcastControlButtons(playerUiController, playerUiState)
} else {
if (settingsState.animated) {
AnimatedMediaInfoDisplay(
media = playerUiState.media,
loading = !playerUiState.connected || playerUiState.media is MediaUiModel.Loading,
AnimatedMediaControlButtons(
onPlayButtonClick = { playerUiController.play() },
onPauseButtonClick = { playerUiController.pause() },
playPauseButtonEnabled = playerUiState.playPauseEnabled,
playing = playerUiState.playing,
onSeekToPreviousButtonClick = { playerUiController.skipToPreviousMedia() },
onSeekToPreviousLongRepeatableClick = { playerUiController.seekBack() },
seekToPreviousButtonEnabled = playerUiState.seekToPreviousEnabled,
onSeekToNextButtonClick = { playerUiController.skipToNextMedia() },
onSeekToNextLongRepeatableClick = { playerUiController.seekForward() },
seekToNextButtonEnabled = playerUiState.seekToNextEnabled,
trackPositionUiModel = playerUiState.trackPositionUiModel,
)
} else {
DefaultMediaInfoDisplay(playerUiState)
}
},
buttons = { state ->
UampSettingsButtons(
volumeUiState = volumeUiState,
audioOutputUi = audioOutput.toAudioOutputUi(),
onVolumeClick = onVolumeClick,
enabled = state.connected && state.media != null,
)
},
controlButtons = { playerUiController, playerUiState ->
if (settingsState.podcastControls) {
PlayerScreenPodcastControlButtons(playerUiController, playerUiState)
} else {
if (settingsState.animated) {
AnimatedMediaControlButtons(
onPlayButtonClick = { playerUiController.play() },
onPauseButtonClick = { playerUiController.pause() },
playPauseButtonEnabled = playerUiState.playPauseEnabled,
playing = playerUiState.playing,
onSeekToPreviousButtonClick = { playerUiController.skipToPreviousMedia() },
onSeekToPreviousLongRepeatableClick = { playerUiController.seekBack() },
seekToPreviousButtonEnabled = playerUiState.seekToPreviousEnabled,
onSeekToNextButtonClick = { playerUiController.skipToNextMedia() },
onSeekToNextLongRepeatableClick = { playerUiController.seekForward() },
seekToNextButtonEnabled = playerUiState.seekToNextEnabled,
trackPositionUiModel = playerUiState.trackPositionUiModel,
)
} else {
DefaultPlayerScreenControlButtons(playerUiController, playerUiState)
}
DefaultPlayerScreenControlButtons(playerUiController, playerUiState)
}
},
)
}
}
},
)

ReportDrawnAfter {
mediaPlayerScreenViewModel.playerState.filterNotNull().first()
Expand Down

0 comments on commit 6ef36de

Please sign in to comment.