Skip to content

Commit

Permalink
[Jetcaster] change the initial focus on the player screen for TV app (#…
Browse files Browse the repository at this point in the history
…1399)

- This pull request changes the initial d-pad focus on the player screen
of the TV app.
- This pull request also formats some files with spotlessApply.
  • Loading branch information
arriolac committed May 10, 2024
2 parents 17e91ef + c69d976 commit d0066c6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 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.glancewidget

import androidx.compose.material3.darkColorScheme
Expand Down Expand Up @@ -73,7 +89,6 @@ import com.example.jetcaster.designsystem.theme.tertiaryContainerLight
import com.example.jetcaster.designsystem.theme.tertiaryDark
import com.example.jetcaster.designsystem.theme.tertiaryLight


/**
* Todo, this is copied from the core module. Refactor colors out of that so we can reference them.
*/
Expand Down Expand Up @@ -154,4 +169,4 @@ internal val DarkJetcasterColors = darkColorScheme(
surfaceContainer = surfaceContainerDark,
surfaceContainerHigh = surfaceContainerHighDark,
surfaceContainerHighest = surfaceContainerHighestDark,
)
)
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 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.glancewidget

import android.content.Context
Expand Down Expand Up @@ -34,7 +50,6 @@ import androidx.glance.appwidget.components.SquareIconButton
import androidx.glance.appwidget.cornerRadius
import androidx.glance.appwidget.provideContent
import androidx.glance.background
import androidx.glance.material3.ColorProviders
import androidx.glance.layout.Alignment
import androidx.glance.layout.Box
import androidx.glance.layout.Column
Expand All @@ -44,6 +59,7 @@ import androidx.glance.layout.Spacer
import androidx.glance.layout.fillMaxSize
import androidx.glance.layout.padding
import androidx.glance.layout.size
import androidx.glance.material3.ColorProviders
import androidx.glance.text.FontWeight
import androidx.glance.text.Text
import androidx.glance.text.TextStyle
Expand All @@ -62,8 +78,6 @@ internal val TAG = "JetcasterAppWidegt"
class JetcasterAppWidgetReceiver : GlanceAppWidgetReceiver() {
override val glanceAppWidget: GlanceAppWidget
get() = JetcasterAppWidget()


}

data class JetcasterAppWidgetViewState(
Expand Down Expand Up @@ -103,26 +117,33 @@ class JetcasterAppWidget : GlanceAppWidget() {
override suspend fun provideGlance(context: Context, id: GlanceId) {

val testState = JetcasterAppWidgetViewState(
episodeTitle = "100 - Android 15 DP 1, Stable Studio Iguana, Cloud Photo Picker, and more!",
podcastTitle = "Now in Android",
episodeTitle =
"100 - Android 15 DP 1, Stable Studio Iguana, Cloud Photo Picker, and more!",
podcastTitle = "Now in Android",
isPlaying = false,
albumArtUri = "https://static.libsyn.com/p/assets/9/f/f/3/9ff3cb5dc6cfb3e2e5bbc093207a2619/NIA000_PodcastThumbnail.png",
albumArtUri = "https://static.libsyn.com/p/assets/9/f/f/3/" +
"9ff3cb5dc6cfb3e2e5bbc093207a2619/NIA000_PodcastThumbnail.png",
useDynamicColor = false
)


provideContent {
val sizeBucket = calculateSizeBucket()
val playPauseIcon = if (testState.isPlaying) PlayPauseIcon.Pause else PlayPauseIcon.Play
val artUri = Uri.parse(testState.albumArtUri)

GlanceTheme(colors = ColorProviders(light = lightColorScheme(), dark = darkColorScheme())) {
GlanceTheme(
colors = ColorProviders(
light = lightColorScheme(),
dark = darkColorScheme()
)
) {
when (sizeBucket) {
SizeBucket.Invalid -> WidgetUiInvalidSize()
SizeBucket.Narrow -> WidgetUiNarrow(
imageUri = artUri ,
imageUri = artUri,
playPauseIcon = playPauseIcon
)

SizeBucket.Normal -> WidgetUiNormal(
title = testState.episodeTitle,
subtitle = testState.podcastTitle,
Expand Down Expand Up @@ -223,7 +244,6 @@ private fun PlayPauseButton(state: PlayPauseIcon, onClick: () -> Unit) {

enum class PlayPauseIcon { Play, Pause }


/**
* Uses Coil to load images.
*/
Expand Down Expand Up @@ -260,7 +280,7 @@ private fun WidgetAsyncImage(
provider = ImageProvider(bitmap),
contentDescription = contentDescription,
contentScale = ContentScale.FillBounds,
modifier = modifier.cornerRadius(12.dp)// TODO: confirm radius with design
modifier = modifier.cornerRadius(12.dp) // TODO: confirm radius with design
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ private fun EpisodePlayerWithBackground(
) {
val episodePlayer = remember { FocusRequester() }

LaunchedEffect(Unit) {
episodePlayer.requestFocus()
}

BackgroundContainer(
playerEpisode = playerEpisode,
modifier = modifier,
Expand Down

0 comments on commit d0066c6

Please sign in to comment.