-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
features/playlist/src/main/java/com/m3u/features/playlist/components/TvChannelGallery.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.m3u.features.playlist.components | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
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.material3.MaterialTheme | ||
import androidx.tv.material3.Text | ||
import com.m3u.data.database.model.Channel | ||
import com.m3u.features.playlist.PlaylistViewModel | ||
import com.m3u.material.model.LocalSpacing | ||
|
||
@Composable | ||
internal fun TvChannelGallery( | ||
categoryWithChannels: List<PlaylistViewModel.CategoryWithChannels>, | ||
maxBrowserHeight: Dp, | ||
isSpecifiedSort: Boolean, | ||
isVodOrSeriesPlaylist: Boolean, | ||
onClick: (Channel) -> Unit, | ||
onLongClick: (Channel) -> Unit, | ||
onFocus: (Channel) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
val spacing = LocalSpacing.current | ||
val multiCategories = categoryWithChannels.size > 1 | ||
|
||
LazyColumn( | ||
verticalArrangement = Arrangement.spacedBy(spacing.medium), | ||
contentPadding = PaddingValues(vertical = spacing.medium), | ||
modifier = Modifier | ||
.heightIn(max = maxBrowserHeight) | ||
.fillMaxWidth() | ||
.then(modifier) | ||
) { | ||
items(categoryWithChannels) { (category, flow) -> | ||
val channels = flow.collectAsLazyPagingItems() | ||
if (multiCategories && channels.itemCount > 0) { | ||
Text( | ||
text = category, | ||
style = MaterialTheme.typography.headlineMedium, | ||
modifier = Modifier.padding(spacing.medium) | ||
) | ||
} | ||
LazyRow( | ||
horizontalArrangement = Arrangement.spacedBy(spacing.medium), | ||
contentPadding = PaddingValues(horizontal = spacing.medium), | ||
modifier = Modifier.fillMaxWidth() | ||
) { | ||
items(channels.itemCount) { index -> | ||
val channel = channels[index] | ||
if (channel != null) { | ||
TvChannelItem( | ||
channel = channel, | ||
isVodOrSeriesPlaylist = isVodOrSeriesPlaylist, | ||
isGridLayout = false, | ||
onClick = { onClick(channel) }, | ||
onLongClick = { onLongClick(channel) }, | ||
modifier = Modifier.onFocusChanged { | ||
if (it.hasFocus) { | ||
onFocus(channel) | ||
} | ||
} | ||
) | ||
} else { | ||
// TODO: placeholder | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |