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

Replacement of tv-foudation from the dependencies of the TV app #1428

Merged
merged 7 commits into from
Sep 9, 2024
2 changes: 0 additions & 2 deletions Jetcaster/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ androidx-test = "1.6.1"
androidx-test-espresso = "3.6.1"
androidx-test-ext-junit = "1.2.1"
androidx-test-ext-truth = "1.5.0"
androidx-tv-foundation = "1.0.0-alpha11"
androidx-tv-material = "1.0.0"
androidx-wear-compose = "1.3.1"
androidx-window = "1.3.0"
Expand Down Expand Up @@ -122,7 +121,6 @@ androidx-test-ext-truth = { module = "androidx.test.ext:truth", version.ref = "a
androidx-test-rules = { module = "androidx.test:rules", version.ref = "androidx-test" }
androidx-test-runner = "androidx.test:runner:1.6.2"
androidx-test-uiautomator = { module = "androidx.test.uiautomator:uiautomator", version.ref = "androix-test-uiautomator" }
androidx-tv-foundation = { module = "androidx.tv:tv-foundation", version.ref = "androidx-tv-foundation" }
androidx-tv-material = { module = "androidx.tv:tv-material", version.ref = "androidx-tv-material" }
androidx-wear-compose-foundation = { module = "androidx.wear.compose:compose-foundation", version.ref = "androidx-wear-compose" }
androidx-wear-compose-material = { module = "androidx.wear.compose:compose-material", version.ref = "androidx-wear-compose" }
Expand Down
1 change: 0 additions & 1 deletion Jetcaster/tv/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ dependencies {
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.material.iconsExtended)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.androidx.tv.foundation)
implementation(libs.androidx.tv.material)
implementation(libs.androidx.lifecycle.runtime)
implementation(libs.androidx.lifecycle.runtime.compose)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,15 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.tooling.preview.Preview
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.Surface
import androidx.tv.material3.Text
import com.example.jetcaster.tv.ui.JetcasterApp
import com.example.jetcaster.tv.ui.theme.JetcasterTheme
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
@OptIn(ExperimentalTvMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Expand All @@ -49,20 +44,3 @@ class MainActivity : ComponentActivity() {
}
}
}

@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
JetcasterTheme {
Greeting("Android")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

package com.example.jetcaster.tv.model

import androidx.compose.runtime.Immutable
import com.example.jetcaster.core.model.PodcastInfo

@Immutable
data class PodcastList(
val member: List<PodcastInfo>
) : List<PodcastInfo> by member
typealias PodcastList = List<PodcastInfo>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.example.jetcaster.tv.ui

import androidx.compose.foundation.focusable
import androidx.compose.foundation.focusGroup
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -33,8 +33,8 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
Expand Down Expand Up @@ -76,16 +76,16 @@ private fun GlobalNavigationContainer(
Column(
modifier = Modifier
.padding(JetcasterAppDefaults.overScanMargin.drawer.intoPaddingValues())
.onFocusChanged { focusState ->
if (focusState.isFocused) {
.focusProperties {
enter = {
when (currentRoute) {
Screen.Discover.route -> discover
Screen.Library.route -> library
else -> FocusRequester.Default
}.requestFocus()
}
}
}
.focusable()
.focusGroup()
) {
NavigationDrawerItem(
selected = isClosed && currentRoute == Screen.Profile.route,
Expand All @@ -94,21 +94,34 @@ private fun GlobalNavigationContainer(
) {
Column {
Text(text = "Name")
Text(text = "Switch Account", style = MaterialTheme.typography.labelSmall)
Text(
text = "Switch Account",
style = MaterialTheme.typography.labelSmall
)
}
}
Spacer(modifier = Modifier.weight(1f))
NavigationDrawerItem(
selected = isClosed && currentRoute == Screen.Search.route,
onClick = jetcasterAppState::navigateToSearch,
leadingContent = { Icon(Icons.Default.Search, contentDescription = null) }
leadingContent = {
Icon(
Icons.Default.Search,
contentDescription = null
)
}
) {
Text(text = "Search")
}
NavigationDrawerItem(
selected = isClosed && currentRoute == Screen.Discover.route,
onClick = jetcasterAppState::navigateToDiscover,
leadingContent = { Icon(Icons.Default.Home, contentDescription = null) },
leadingContent = {
Icon(
Icons.Default.Home,
contentDescription = null
)
},
modifier = Modifier.focusRequester(discover)
) {
Text(text = "Discover")
Expand Down Expand Up @@ -137,7 +150,7 @@ private fun GlobalNavigationContainer(
}
},
content = content,
modifier = modifier,
modifier = modifier
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.tv.material3.ButtonDefaults
import androidx.tv.material3.ButtonScale
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.Icon
import androidx.tv.material3.IconButton
import com.example.jetcaster.tv.R

@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
internal fun PlayButton(
onClick: () -> Unit,
Expand All @@ -53,7 +51,6 @@ internal fun PlayButton(
scale = scale
)

@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
internal fun EnqueueButton(
onClick: () -> Unit,
Expand All @@ -67,7 +64,6 @@ internal fun EnqueueButton(
}
}

@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
internal fun InfoButton(
onClick: () -> Unit,
Expand All @@ -81,7 +77,6 @@ internal fun InfoButton(
}
}

@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
internal fun PreviousButton(
onClick: () -> Unit,
Expand All @@ -95,7 +90,6 @@ internal fun PreviousButton(
}
}

@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
internal fun NextButton(
onClick: () -> Unit,
Expand All @@ -109,7 +103,6 @@ internal fun NextButton(
}
}

@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
internal fun PlayPauseButton(
isPlaying: Boolean,
Expand All @@ -126,7 +119,6 @@ internal fun PlayPauseButton(
}
}

@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
internal fun RewindButton(
onClick: () -> Unit,
Expand All @@ -140,7 +132,6 @@ internal fun RewindButton(
}
}

@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
internal fun SkipButton(
onClick: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.tv.foundation.lazy.list.TvLazyColumn
import androidx.tv.foundation.lazy.list.TvLazyListState
import androidx.tv.foundation.lazy.list.TvLazyRow
import androidx.tv.foundation.lazy.list.itemsIndexed
import androidx.tv.foundation.lazy.list.rememberTvLazyListState
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import com.example.jetcaster.core.model.PodcastInfo
Expand All @@ -55,10 +51,10 @@ internal fun Catalog(
onPodcastSelected: (PodcastInfo) -> Unit,
onEpisodeSelected: (PlayerEpisode) -> Unit,
modifier: Modifier = Modifier,
state: TvLazyListState = rememberTvLazyListState(),
state: LazyListState = rememberLazyListState(),
header: (@Composable () -> Unit)? = null,
) {
TvLazyColumn(
LazyColumn(
modifier = modifier,
contentPadding = JetcasterAppDefaults.overScanMargin.catalog.intoPaddingValues(),
verticalArrangement =
Expand Down Expand Up @@ -121,7 +117,6 @@ private fun LatestEpisodeSection(
}
}

@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
private fun Section(
modifier: Modifier = Modifier,
Expand Down Expand Up @@ -151,23 +146,20 @@ private fun PodcastRow(
horizontalArrangement: Arrangement.Horizontal =
Arrangement.spacedBy(JetcasterAppDefaults.gap.podcastRow),
) {
val (focusRequester, firstItem) = remember { FocusRequester.createRefs() }
var previousPodcastListHash by remember { mutableIntStateOf(podcastList.hashCode()) }
val isSamePodcastList = previousPodcastListHash == podcastList.hashCode()
val (focusRequester, firstItem) = remember(podcastList) { FocusRequester.createRefs() }

TvLazyRow(
LazyRow(
contentPadding = contentPadding,
horizontalArrangement = horizontalArrangement,
modifier = modifier
.focusRequester(focusRequester)
.focusProperties {
exit = {
previousPodcastListHash = podcastList.hashCode()
focusRequester.saveFocusedChild()
FocusRequester.Default
}
enter = {
if (isSamePodcastList && focusRequester.restoreFocusedChild()) {
if (focusRequester.restoreFocusedChild()) {
FocusRequester.Cancel
} else {
firstItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import androidx.compose.ui.unit.dp
import androidx.tv.material3.Card
import androidx.tv.material3.CardDefaults
import androidx.tv.material3.CardScale
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import androidx.tv.material3.WideCardContainer
Expand Down Expand Up @@ -63,7 +62,6 @@ internal fun EpisodeCard(
)
}

@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
private fun EpisodeThumbnail(
playerEpisode: PlayerEpisode,
Expand All @@ -82,7 +80,6 @@ private fun EpisodeThumbnail(
}
}

@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
private fun EpisodeMetaData(
playerEpisode: PlayerEpisode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ package com.example.jetcaster.tv.ui.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
Expand All @@ -28,9 +31,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.tv.foundation.lazy.list.TvLazyListState
import androidx.tv.foundation.lazy.list.TvLazyRow
import androidx.tv.foundation.lazy.list.itemsIndexed
import com.example.jetcaster.core.player.model.PlayerEpisode
import com.example.jetcaster.tv.model.EpisodeList
import com.example.jetcaster.tv.ui.theme.JetcasterAppDefaults
Expand All @@ -45,13 +45,13 @@ internal fun EpisodeRow(
Arrangement.spacedBy(JetcasterAppDefaults.gap.item),
contentPadding: PaddingValues = JetcasterAppDefaults.padding.episodeRowContentPadding,
focusRequester: FocusRequester = remember { FocusRequester() },
lazyListState: TvLazyListState = remember(playerEpisodeList) { TvLazyListState() }
lazyListState: LazyListState = remember(playerEpisodeList) { LazyListState() }
) {
val firstItem = remember { FocusRequester() }
var previousEpisodeListHash by remember { mutableIntStateOf(playerEpisodeList.hashCode()) }
val isSameList = previousEpisodeListHash == playerEpisodeList.hashCode()

TvLazyRow(
LazyRow(
state = lazyListState,
modifier = Modifier
.focusRequester(focusRequester)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package com.example.jetcaster.tv.ui.discover

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
Expand All @@ -29,8 +31,6 @@ import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.tv.foundation.lazy.list.TvLazyListState
import androidx.tv.foundation.lazy.list.rememberTvLazyListState
import androidx.tv.material3.Tab
import androidx.tv.material3.TabRow
import androidx.tv.material3.Text
Expand Down Expand Up @@ -94,7 +94,7 @@ private fun CatalogWithCategorySelection(
onEpisodeSelected: (PlayerEpisode) -> Unit,
onCategorySelected: (CategoryInfo) -> Unit,
modifier: Modifier = Modifier,
state: TvLazyListState = rememberTvLazyListState(),
state: LazyListState = rememberLazyListState(),
) {
val (focusRequester, selectedTab) = remember {
FocusRequester.createRefs()
Expand Down
Loading