-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Wear]Add preview to latestEpisodes and refactoring (#1391)
- Uses #1377 - Add previews for latestEpisode screen - Refactor `MediaContent` for Queue and Podcasts (need a separate PR to see if it can be expanded for LatestEpisodes since it has additional play methods) - Moves the latestEpisodes screen title to the Composable - Add more data preview to create PlayerEpisode
- Loading branch information
Showing
12 changed files
with
323 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
Jetcaster/wear/src/main/java/com/example/jetcaster/ui/components/MediaContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2022 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.jetcaster.ui.components | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.painter.Painter | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.wear.compose.material.ChipDefaults | ||
import com.example.jetcaster.R | ||
import com.example.jetcaster.core.player.model.PlayerEpisode | ||
import com.google.android.horologist.compose.material.Chip | ||
import com.google.android.horologist.images.coil.CoilPaintable | ||
import java.time.format.DateTimeFormatter | ||
import java.time.format.FormatStyle | ||
|
||
@Composable | ||
fun MediaContent( | ||
episode: PlayerEpisode, | ||
episodeArtworkPlaceholder: Painter?, | ||
onItemClick: (PlayerEpisode) -> Unit, | ||
modifier: Modifier = Modifier | ||
) { | ||
val mediaTitle = episode.title | ||
val duration = episode.duration | ||
|
||
val secondaryLabel = when { | ||
duration != null -> { | ||
// If we have the duration, we combine the date/duration via a | ||
// formatted string | ||
stringResource( | ||
R.string.episode_date_duration, | ||
MediumDateFormatter.format(episode.published), | ||
duration.toMinutes().toInt() | ||
) | ||
} | ||
// Otherwise we just use the date | ||
else -> MediumDateFormatter.format(episode.published) | ||
} | ||
|
||
Chip( | ||
label = mediaTitle, | ||
onClick = { onItemClick(episode) }, | ||
secondaryLabel = secondaryLabel, | ||
icon = CoilPaintable(episode.podcastImageUrl, episodeArtworkPlaceholder), | ||
largeIcon = true, | ||
colors = ChipDefaults.secondaryChipColors(), | ||
modifier = modifier | ||
) | ||
} | ||
|
||
public val MediumDateFormatter: DateTimeFormatter by lazy { | ||
DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.