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

Android Auto: Update the progress bar in the browse view #2945

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* New Features
* Add sleep timer settings to sleep timer bottom sheet
([#2829](https://github.com/Automattic/pocket-casts-android/pull/2829))
* Add a progress bar in the browse view on Android Auto
([#2945](https://github.com/Automattic/pocket-casts-android/pull/2945))

7.73
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import android.view.KeyEvent
import androidx.annotation.DrawableRes
import androidx.core.content.IntentCompat
import androidx.core.os.bundleOf
import androidx.media.utils.MediaConstants.PLAYBACK_STATE_EXTRAS_KEY_MEDIA_ID
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsEvent
import au.com.shiftyjelly.pocketcasts.analytics.EpisodeAnalytics
import au.com.shiftyjelly.pocketcasts.analytics.SourceView
Expand Down Expand Up @@ -249,7 +250,12 @@ class MediaSessionManager(
val stateBuilder = PlaybackStateCompat.Builder()
.setState(state, playbackState.positionMs.toLong(), currentSpeed.toFloat(), SystemClock.elapsedRealtime())
.setActions(getSupportedActions(playbackState))
.setExtras(bundleOf(EXTRA_TRANSIENT to playbackState.transientLoss))
.setExtras(
bundleOf(
PLAYBACK_STATE_EXTRAS_KEY_MEDIA_ID to currentEpisode.uuid,
EXTRA_TRANSIENT to playbackState.transientLoss,
),
)

// Do not add custom actions on Wear OS because there is a bug in Wear 3.5 that causes
// this to make the Wear OS media notification stop working. This bug was fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.support.v4.media.MediaDescriptionCompat.STATUS_NOT_DOWNLOADED
import androidx.annotation.DrawableRes
import androidx.core.graphics.drawable.toBitmap
import androidx.core.os.bundleOf
import androidx.media.utils.MediaConstants.DESCRIPTION_EXTRAS_KEY_COMPLETION_PERCENTAGE
import androidx.media.utils.MediaConstants.DESCRIPTION_EXTRAS_KEY_COMPLETION_STATUS
import androidx.media.utils.MediaConstants.DESCRIPTION_EXTRAS_VALUE_COMPLETION_STATUS_FULLY_PLAYED
import androidx.media.utils.MediaConstants.DESCRIPTION_EXTRAS_VALUE_COMPLETION_STATUS_NOT_PLAYED
Expand Down Expand Up @@ -213,15 +214,27 @@ object AutoConverter {
private fun extrasForEpisode(episode: BaseEpisode): Bundle {
val downloadStatus = if (episode.isDownloaded) STATUS_DOWNLOADED else STATUS_NOT_DOWNLOADED

val completionStatus = when (episode.playingStatus) {
EpisodePlayingStatus.NOT_PLAYED -> DESCRIPTION_EXTRAS_VALUE_COMPLETION_STATUS_NOT_PLAYED
EpisodePlayingStatus.IN_PROGRESS -> DESCRIPTION_EXTRAS_VALUE_COMPLETION_STATUS_PARTIALLY_PLAYED
EpisodePlayingStatus.COMPLETED -> DESCRIPTION_EXTRAS_VALUE_COMPLETION_STATUS_FULLY_PLAYED
val completionStatus: Int
val completionPercentage: Double
when (episode.playingStatus) {
EpisodePlayingStatus.NOT_PLAYED -> {
completionStatus = DESCRIPTION_EXTRAS_VALUE_COMPLETION_STATUS_NOT_PLAYED
completionPercentage = 0.0
}
EpisodePlayingStatus.IN_PROGRESS -> {
completionStatus = DESCRIPTION_EXTRAS_VALUE_COMPLETION_STATUS_PARTIALLY_PLAYED
completionPercentage = if (episode.duration == 0.0) 0.0 else (episode.playedUpTo / episode.duration).coerceIn(0.0, 1.0)
}
EpisodePlayingStatus.COMPLETED -> {
completionStatus = DESCRIPTION_EXTRAS_VALUE_COMPLETION_STATUS_FULLY_PLAYED
completionPercentage = 1.0
}
}

return bundleOf(
EXTRA_DOWNLOAD_STATUS to downloadStatus,
DESCRIPTION_EXTRAS_KEY_COMPLETION_STATUS to completionStatus,
DESCRIPTION_EXTRAS_KEY_COMPLETION_PERCENTAGE to completionPercentage,
)
}
}