Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add up next icon to episode chip #914

Merged
merged 3 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package au.com.shiftyjelly.pocketcasts.wear.ui.component

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Arrangement.Absolute.spacedBy
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -20,6 +23,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.PlatformTextStyle
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextOverflow
Expand All @@ -33,8 +37,10 @@ import au.com.shiftyjelly.pocketcasts.compose.components.EpisodeImage
import au.com.shiftyjelly.pocketcasts.images.R
import au.com.shiftyjelly.pocketcasts.localization.helper.TimeHelper
import au.com.shiftyjelly.pocketcasts.models.entity.BaseEpisode
import au.com.shiftyjelly.pocketcasts.repositories.playback.UpNextQueue
import au.com.shiftyjelly.pocketcasts.utils.extensions.toLocalizedFormatPattern
import au.com.shiftyjelly.pocketcasts.wear.theme.theme
import au.com.shiftyjelly.pocketcasts.localization.R as LR

@Composable
fun EpisodeChip(episode: BaseEpisode, onClick: () -> Unit) {
Expand All @@ -57,9 +63,19 @@ fun EpisodeChip(episode: BaseEpisode, onClick: () -> Unit) {
.observeByUuid(episode)
.collectAsState()

Row {
val queueState by viewModel.upNextQueue.collectAsState(UpNextQueue.State.Empty)
val upNextQueue = (queueState as? UpNextQueue.State.Loaded)
?.queue
?: emptyList()
val isInUpNextQueue = upNextQueue.any { it.uuid == episode.uuid }

Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.height(IntrinsicSize.Max)
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {

EpisodeImage(
Expand All @@ -69,14 +85,29 @@ fun EpisodeChip(episode: BaseEpisode, onClick: () -> Unit) {
.clip(RoundedCornerShape(4.dp)),
)

if (episode.isDownloaded) {
Spacer(Modifier.height(4.dp))
Icon(
painter = painterResource(R.drawable.ic_downloaded),
contentDescription = null,
tint = MaterialTheme.theme.colors.support02,
modifier = Modifier.size(12.dp),
)
if (episode.isDownloaded || isInUpNextQueue) {
Row(
horizontalArrangement = spacedBy(4.dp),
modifier = Modifier.padding(top = 4.dp)
) {
if (isInUpNextQueue) {
Icon(
painter = painterResource(R.drawable.ic_upnext),
contentDescription = stringResource(LR.string.episode_in_up_next),
tint = MaterialTheme.theme.colors.support01,
modifier = Modifier.size(12.dp),
)
}

if (episode.isDownloaded) {
Icon(
painter = painterResource(R.drawable.ic_downloaded),
contentDescription = stringResource(LR.string.downloaded),
tint = MaterialTheme.theme.colors.support02,
modifier = Modifier.size(12.dp),
)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@ package au.com.shiftyjelly.pocketcasts.wear.ui.component
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import au.com.shiftyjelly.pocketcasts.models.entity.BaseEpisode
import au.com.shiftyjelly.pocketcasts.repositories.playback.PlaybackManager
import au.com.shiftyjelly.pocketcasts.repositories.playback.UpNextQueue
import au.com.shiftyjelly.pocketcasts.repositories.podcast.EpisodeManager
import au.com.shiftyjelly.pocketcasts.repositories.podcast.PodcastManager
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.rx2.asFlow
import javax.inject.Inject

@HiltViewModel
class EpisodeChipViewModel @Inject constructor(
private val episodeManager: EpisodeManager,
playbackManager: PlaybackManager,
podcastManager: PodcastManager,
) : ViewModel() {

val upNextQueue: Flow<UpNextQueue.State> = playbackManager
.upNextQueue
.getChangesObservableWithLiveCurrentEpisode(episodeManager, podcastManager)
.asFlow()

fun observeByUuid(episode: BaseEpisode): StateFlow<BaseEpisode> =
episodeManager
.observeEpisodeByUuid(episode.uuid)
Expand Down