Skip to content

Commit

Permalink
Remove tv-foundation.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed May 31, 2024
1 parent 5088b53 commit 04cd6f2
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 360 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,16 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.tv.foundation.lazy.grid.TvGridCells
import androidx.tv.foundation.lazy.grid.TvGridItemSpan
import androidx.tv.foundation.lazy.grid.TvLazyVerticalGrid
import androidx.tv.foundation.lazy.grid.items
import androidx.tv.material3.Card as TvCard
import androidx.tv.material3.CardDefaults as TvCardDefaults
import androidx.tv.material3.Glow as TvGlow
import com.m3u.core.util.basic.title
import com.m3u.core.wrapper.Resource
import com.m3u.data.database.model.Stream
import com.m3u.i18n.R.string
import com.m3u.material.ktx.isTelevision
import com.m3u.material.ktx.plus
import com.m3u.material.model.LocalSpacing
import androidx.tv.material3.Card as TvCard
import androidx.tv.material3.CardDefaults as TvCardDefaults
import androidx.tv.material3.Glow as TvGlow
import androidx.tv.material3.MaterialTheme as TvMaterialTheme
import androidx.tv.material3.Text as TvText

Expand All @@ -62,6 +58,7 @@ internal fun FavouriteGallery(
onClickRandomTips: () -> Unit,
modifier: Modifier = Modifier
) {
val spacing = LocalSpacing.current
Box(modifier) {
when (streamsResource) {
Resource.Loading -> {
Expand All @@ -73,99 +70,41 @@ internal fun FavouriteGallery(
}

is Resource.Success -> {
FavouriteGalleryImpl(
contentPadding = contentPadding,
streams = streamsResource.data,
zapping = zapping,
recently = recently,
rowCount = rowCount,
onClick = onClick,
onLongClick = onLongClick,
onClickRandomTips = onClickRandomTips
)
val streams = streamsResource.data
LazyVerticalStaggeredGrid(
columns = StaggeredGridCells.Fixed(rowCount),
verticalItemSpacing = spacing.medium,
horizontalArrangement = Arrangement.spacedBy(spacing.large),
contentPadding = PaddingValues(spacing.medium) + contentPadding,
modifier = modifier.fillMaxSize(),
) {
item(span = StaggeredGridItemSpan.FullLine) {
RandomTips(
onClick = onClickRandomTips
)
}
items(
items = streams,
key = { it.id },
contentType = { it.cover.isNullOrEmpty() }
) { stream ->
FavoriteItem(
stream = stream,
zapping = zapping == stream,
onClick = { onClick(stream) },
onLongClick = { onLongClick(stream) },
recently = recently,
modifier = Modifier.fillMaxWidth()
)
}
}
}

is Resource.Failure -> {}
}
}
}

@Composable
private fun FavouriteGalleryImpl(
contentPadding: PaddingValues,
streams: List<Stream>,
zapping: Stream?,
recently: Boolean,
rowCount: Int,
onClick: (Stream) -> Unit,
onLongClick: (Stream) -> Unit,
onClickRandomTips: () -> Unit,
modifier: Modifier = Modifier
) {
val spacing = LocalSpacing.current
val tv = isTelevision()
if (!tv) {
LazyVerticalStaggeredGrid(
columns = StaggeredGridCells.Fixed(rowCount),
verticalItemSpacing = spacing.medium,
horizontalArrangement = Arrangement.spacedBy(spacing.large),
contentPadding = PaddingValues(spacing.medium) + contentPadding,
modifier = modifier.fillMaxSize(),
) {
item(span = StaggeredGridItemSpan.FullLine) {
RandomTips(
onClick = onClickRandomTips
)
}
items(
items = streams,
key = { it.id },
contentType = { it.cover.isNullOrEmpty() }
) { stream ->
FavoriteItem(
stream = stream,
zapping = zapping == stream,
onClick = { onClick(stream) },
onLongClick = { onLongClick(stream) },
recently = recently,
modifier = Modifier.fillMaxWidth()
)
}
}
} else {
TvLazyVerticalGrid(
columns = TvGridCells.Fixed(rowCount),
verticalArrangement = Arrangement.spacedBy(spacing.large),
horizontalArrangement = Arrangement.spacedBy(spacing.large),
contentPadding = PaddingValues(
vertical = spacing.medium,
horizontal = spacing.large
) + contentPadding,
modifier = modifier.fillMaxSize(),
) {
item(span = { TvGridItemSpan(rowCount) }) {
RandomTips(
onClick = onClickRandomTips
)
}
items(
items = streams,
key = { it.id },
contentType = { it.cover.isNullOrEmpty() }
) { stream ->
FavoriteItem(
stream = stream,
zapping = zapping == stream,
recently = recently,
onClick = { onClick(stream) },
onLongClick = { onLongClick(stream) },
modifier = Modifier.fillMaxWidth()
)
}
}
}
}

@Composable
private fun RandomTips(
onClick: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.tv.foundation.lazy.grid.TvGridCells
import androidx.tv.foundation.lazy.grid.TvGridItemSpan
import androidx.tv.foundation.lazy.grid.TvLazyVerticalGrid
import androidx.tv.foundation.lazy.grid.itemsIndexed
import com.m3u.data.database.model.DataSource
import com.m3u.data.database.model.Playlist
import com.m3u.data.database.model.PlaylistWithCount
import com.m3u.data.database.model.fromLocal
import com.m3u.data.database.model.type
import com.m3u.i18n.R.string
import com.m3u.material.ktx.isTelevision
import com.m3u.material.ktx.plus
import com.m3u.material.model.LocalSpacing

Expand All @@ -37,43 +32,6 @@ internal fun PlaylistGallery(
modifier: Modifier = Modifier,
contentPadding: PaddingValues = PaddingValues(),
header: (@Composable () -> Unit)? = null
) {
val tv = isTelevision()
if (!tv) {
SmartphonePlaylistGalleryImpl(
rowCount = rowCount,
playlistCounts = playlistCounts,
subscribingPlaylistUrls = subscribingPlaylistUrls,
onClick = onClick,
onLongClick = onLongClick,
contentPadding = contentPadding,
modifier = modifier,
header = header
)
} else {
TvPlaylistGalleryImpl(
rowCount = rowCount,
playlistCounts = playlistCounts,
subscribingPlaylistUrls = subscribingPlaylistUrls,
onClick = onClick,
onLongClick = onLongClick,
contentPadding = contentPadding,
modifier = modifier,
header = header
)
}
}

@Composable
private fun SmartphonePlaylistGalleryImpl(
rowCount: Int,
playlistCounts: List<PlaylistWithCount>,
subscribingPlaylistUrls: List<String>,
onClick: (Playlist) -> Unit,
onLongClick: (Playlist) -> Unit,
contentPadding: PaddingValues,
modifier: Modifier = Modifier,
header: (@Composable () -> Unit)? = null
) {
val spacing = LocalSpacing.current
LazyVerticalGrid(
Expand Down Expand Up @@ -125,65 +83,6 @@ private fun SmartphonePlaylistGalleryImpl(
}
}

@Composable
private fun TvPlaylistGalleryImpl(
rowCount: Int,
playlistCounts: List<PlaylistWithCount>,
subscribingPlaylistUrls: List<String>,
onClick: (Playlist) -> Unit,
onLongClick: (Playlist) -> Unit,
contentPadding: PaddingValues,
modifier: Modifier = Modifier,
header: (@Composable () -> Unit)? = null
) {
val spacing = LocalSpacing.current
TvLazyVerticalGrid(
columns = TvGridCells.Fixed(rowCount),
contentPadding = PaddingValues(vertical = spacing.medium) + contentPadding,
verticalArrangement = Arrangement.spacedBy(spacing.large),
horizontalArrangement = Arrangement.spacedBy(spacing.large),
modifier = modifier
) {
if (header != null) {
item(span = { TvGridItemSpan(rowCount) }) {
header()
}
}
itemsIndexed(
items = playlistCounts,
key = { _, it -> it.playlist.url }
) { index, playlistCount ->
PlaylistItem(
label = PlaylistGalleryDefaults.calculateUiTitle(
title = playlistCount.playlist.title,
fromLocal = playlistCount.playlist.fromLocal
),
type = with(playlistCount.playlist) {
when (source) {
DataSource.M3U -> "$source"
DataSource.Xtream -> "$source $type"
else -> null
}
},
count = playlistCount.count,
subscribing = playlistCount.playlist.url in subscribingPlaylistUrls,
local = playlistCount.playlist.fromLocal,
onClick = { onClick(playlistCount.playlist) },
onLongClick = { onLongClick(playlistCount.playlist) },
modifier = Modifier
.fillMaxWidth()
.padding(
PlaylistGalleryDefaults.calculateItemHorizontalPadding(
rowCount = rowCount,
index = index,
padding = spacing.large
)
)
)
}
}
}

private object PlaylistGalleryDefaults {
@Composable
fun calculateUiTitle(title: String, fromLocal: Boolean): String {
Expand Down
3 changes: 0 additions & 3 deletions features/playlist/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ dependencies {
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.runtime.compose)

implementation(libs.androidx.tv.foundation)
implementation(libs.androidx.tv.material)

implementation(libs.google.dagger.hilt)
implementation(libs.androidx.hilt.navigation.compose)
implementation(libs.androidx.hilt.work)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.unit.Dp
import androidx.paging.compose.collectAsLazyPagingItems
import androidx.tv.foundation.lazy.list.TvLazyColumn
import androidx.tv.foundation.lazy.list.TvLazyRow
import androidx.tv.foundation.lazy.list.items
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import com.m3u.data.database.model.Stream
Expand All @@ -33,7 +33,7 @@ internal fun TvStreamGallery(
val spacing = LocalSpacing.current
val multiCategories = channels.size > 1

TvLazyColumn(
LazyColumn(
verticalArrangement = Arrangement.spacedBy(spacing.medium),
contentPadding = PaddingValues(vertical = spacing.medium),
modifier = Modifier
Expand All @@ -50,7 +50,7 @@ internal fun TvStreamGallery(
modifier = Modifier.padding(spacing.medium)
)
}
TvLazyRow(
LazyRow(
horizontalArrangement = Arrangement.spacedBy(spacing.medium),
contentPadding = PaddingValues(horizontal = spacing.medium),
modifier = Modifier.fillMaxWidth()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.rounded.Shortcut
Expand All @@ -27,7 +28,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.tv.foundation.lazy.list.TvLazyColumn
import androidx.tv.material3.DenseListItem
import com.m3u.core.architecture.preferences.hiltPreferences
import com.m3u.data.database.model.Programme
Expand Down Expand Up @@ -182,7 +182,7 @@ private fun MenuFullScreenDialog(
.fillMaxWidth(0.4f)
.align(Alignment.CenterEnd)
) {
TvLazyColumn(
LazyColumn(
Modifier
.fillMaxHeight()
.background(TvMaterialTheme.colorScheme.surfaceVariant)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.m3u.features.setting

enum class BackingUpAndRestoringState {
internal enum class BackingUpAndRestoringState {
NONE, BACKING_UP, RESTORING, BOTH;

companion object {
Expand Down
Loading

0 comments on commit 04cd6f2

Please sign in to comment.