Skip to content

Commit

Permalink
DraggableScrollbar #172
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed Jul 7, 2024
1 parent a75453d commit 530a584
Show file tree
Hide file tree
Showing 2 changed files with 418 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package com.m3u.feature.playlist.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridState
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
Expand All @@ -20,10 +22,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.paging.compose.collectAsLazyPagingItems
import com.m3u.core.architecture.preferences.hiltPreferences
import com.m3u.data.database.model.Programme
import com.m3u.data.database.model.Channel
import com.m3u.data.database.model.Programme
import com.m3u.feature.playlist.PlaylistViewModel
import com.m3u.material.components.CircularProgressIndicator
import com.m3u.material.components.VerticalDraggableScrollbar
import com.m3u.material.ktx.plus
import com.m3u.material.model.LocalSpacing

Expand Down Expand Up @@ -52,41 +55,54 @@ internal fun SmartphoneChannelGallery(

val channels = categoryWithChannels?.channels?.collectAsLazyPagingItems()

LazyVerticalStaggeredGrid(
state = state,
columns = StaggeredGridCells.Fixed(actualRowCount),
verticalItemSpacing = spacing.medium,
horizontalArrangement = Arrangement.spacedBy(spacing.medium),
contentPadding = PaddingValues(spacing.medium) + contentPadding,
modifier = modifier.fillMaxSize()
Row(
modifier = modifier
.fillMaxSize()
.padding(start = spacing.medium),
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
items(channels?.itemCount ?: 0) { index ->
val channel = channels?.get(index)
if (channel != null) {
var programme: Programme? by remember { mutableStateOf(null) }
LaunchedEffect(channel.originalId) {
programme = getProgrammeCurrently(channel.originalId.orEmpty())
}
SmartphoneChannelItem(
channel = channel,
programme = programme,
recently = recently,
zapping = zapping == channel,
isVodOrSeriesPlaylist = isVodOrSeriesPlaylist,
onClick = { onClick(channel) },
onLongClick = { onLongClick(channel) },
modifier = Modifier.fillMaxWidth()
)
} else {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f)
) {
CircularProgressIndicator()
LazyVerticalStaggeredGrid(
state = state,
columns = StaggeredGridCells.Fixed(actualRowCount),
verticalItemSpacing = spacing.medium,
horizontalArrangement = Arrangement.spacedBy(spacing.medium),
contentPadding = PaddingValues(vertical = spacing.medium) + contentPadding,
modifier = Modifier
.fillMaxSize()
.weight(1f)
) {
items(channels?.itemCount ?: 0) { index ->
val channel = channels?.get(index)
if (channel != null) {
var programme: Programme? by remember { mutableStateOf(null) }
LaunchedEffect(channel.originalId) {
programme = getProgrammeCurrently(channel.originalId.orEmpty())
}
SmartphoneChannelItem(
channel = channel,
programme = programme,
recently = recently,
zapping = zapping == channel,
isVodOrSeriesPlaylist = isVodOrSeriesPlaylist,
onClick = { onClick(channel) },
onLongClick = { onLongClick(channel) },
modifier = Modifier.fillMaxWidth()
)
} else {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f)
) {
CircularProgressIndicator()
}
}
}
}
VerticalDraggableScrollbar(
lazyStaggeredGridState = state,
modifier = Modifier.padding(5.dp)
)
}
}
Loading

0 comments on commit 530a584

Please sign in to comment.