Skip to content

Commit

Permalink
🎨 节目单、收藏等优化
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxieyoulei committed Jun 20, 2024
1 parent 8d87795 commit 6e4be73
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 125 deletions.
28 changes: 28 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ data class IptvList(
val value: List<Iptv> = emptyList(),
) : List<Iptv> by value {
companion object {
val EXAMPLE = IptvList(List(10) { Iptv.EXAMPLE })
val EXAMPLE = IptvList(List(10) { i -> Iptv.EXAMPLE.copy(name = "CCTV-$i") })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -41,6 +43,7 @@ import top.yogiczy.mytv.ui.rememberLeanbackChildPadding
import top.yogiczy.mytv.ui.screens.leanback.classicpanel.components.LeanbackClassicPanelEpgList
import top.yogiczy.mytv.ui.screens.leanback.classicpanel.components.LeanbackClassicPanelIptvGroupList
import top.yogiczy.mytv.ui.screens.leanback.classicpanel.components.LeanbackClassicPanelIptvList
import top.yogiczy.mytv.ui.screens.leanback.components.LeanbackVisible
import top.yogiczy.mytv.ui.screens.leanback.panel.PanelAutoCloseState
import top.yogiczy.mytv.ui.screens.leanback.panel.rememberPanelAutoCloseState
import top.yogiczy.mytv.ui.screens.leanback.toast.LeanbackToastState
Expand All @@ -55,6 +58,7 @@ fun LeanbackClassicPanelScreen(
epgList: EpgList = EpgList(),
currentIptvProvider: () -> Iptv = { Iptv() },
showProgrammeProgressProvider: () -> Boolean = { false },
iptvFavoriteEnableProvider: () -> Boolean = { true },
iptvFavoriteListProvider: () -> ImmutableList<String> = { persistentListOf() },
iptvFavoriteListVisibleProvider: () -> Boolean = { false },
onIptvFavoriteListVisibleChange: (Boolean) -> Unit = {},
Expand Down Expand Up @@ -90,7 +94,7 @@ fun LeanbackClassicPanelScreen(
.padding(
top = childPadding.top,
start = childPadding.start / 2,
end = childPadding.end,
end = childPadding.end / 2,
),
) {
var favoriteListVisible by remember { mutableStateOf(iptvFavoriteListVisibleProvider()) }
Expand Down Expand Up @@ -132,11 +136,13 @@ fun LeanbackClassicPanelScreen(
}
},
onUserAction = { autoCloseState.active() },
iptvFavoriteEnableProvider = iptvFavoriteEnableProvider,
)
}
}
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
private fun LeanbackClassicPanelIptvGroup(
modifier: Modifier = Modifier,
Expand All @@ -148,7 +154,9 @@ private fun LeanbackClassicPanelIptvGroup(
onIptvFavoriteToggle: (Iptv) -> Unit = {},
onToFavorite: () -> Unit = {},
onUserAction: () -> Unit = {},
iptvFavoriteEnableProvider: () -> Boolean = { true },
) {
val iptvFavoriteEnable = iptvFavoriteEnableProvider()
var focusedIptvGroup by remember {
mutableStateOf(
iptvGroupList[max(0, iptvGroupList.iptvGroupIdx(currentIptvProvider()))]
Expand All @@ -158,27 +166,19 @@ private fun LeanbackClassicPanelIptvGroup(
var focusedIptv by remember { mutableStateOf(currentIptvProvider()) }
var focusedIptvFocusRequester by remember { mutableStateOf(FocusRequester.Default) }

var inIptvGroupTab by remember { mutableStateOf(true) }
var epgListVisible by remember { mutableStateOf(false) }

Row(modifier = modifier, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
Column(
modifier = Modifier
.fillMaxHeight()
.pointerInput(Unit) {
detectTapGestures(onTap = { onToFavorite() })
},
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
"向左查看收藏列表".map {
Text(text = it.toString(), style = MaterialTheme.typography.labelSmall)
}
if (iptvFavoriteEnable) {
LeanbackClassicPanelVerticalTip(
text = "向左查看收藏列表",
onTap = onToFavorite,
)
}

LeanbackClassicPanelIptvGroupList(
modifier = Modifier.handleLeanbackKeyEvents(
onLeft = onToFavorite,
onLeft = { if (iptvFavoriteEnable) onToFavorite() },
),
iptvGroupListProvider = { iptvGroupList },
initialIptvGroupProvider = {
Expand All @@ -187,18 +187,26 @@ private fun LeanbackClassicPanelIptvGroup(
},
onIptvGroupFocused = { focusedIptvGroup = it },
exitFocusRequesterProvider = { focusedIptvFocusRequester },
onFocusEnter = {
inIptvGroupTab = true
epgListVisible = false
},
onFocusExit = { inIptvGroupTab = false },
onFocusEnter = { epgListVisible = false },
onUserAction = onUserAction,
)

LeanbackClassicPanelIptvList(
modifier = Modifier.handleLeanbackKeyEvents(
onRight = { epgListVisible = true },
),
modifier = Modifier
.handleLeanbackKeyEvents(
onRight = { epgListVisible = true },
onLeft = { epgListVisible = false }
)
.focusProperties {
exit = {
if (epgListVisible && it == FocusDirection.Left) {
epgListVisible = false
FocusRequester.Cancel
} else {
FocusRequester.Default
}
}
},
iptvListProvider = { focusedIptvGroup.iptvList },
epgListProvider = { epgList },
initialIptvProvider = currentIptvProvider,
Expand All @@ -212,16 +220,19 @@ private fun LeanbackClassicPanelIptvGroup(
onUserAction = onUserAction,
)

LeanbackClassicPanelEpgList(
visibleProvider = { epgListVisible },
onVisibleChanged = { epgListVisible = it },
epgProvider = {
if (inIptvGroupTab) null
else epgList.firstOrNull { it.channel == focusedIptv.channelName }
},
exitFocusRequesterProvider = { focusedIptvFocusRequester },
onUserAction = onUserAction,
)
LeanbackVisible({ epgListVisible }) {
LeanbackClassicPanelEpgList(
epgProvider = { epgList.firstOrNull { it.channel == focusedIptv.channelName } },
exitFocusRequesterProvider = { focusedIptvFocusRequester },
onUserAction = onUserAction,
)
}
LeanbackVisible({ !epgListVisible }) {
LeanbackClassicPanelVerticalTip(
text = "向右查看节目单",
onTap = { epgListVisible = true },
)
}
}
}

Expand Down Expand Up @@ -266,9 +277,13 @@ fun LeanbackClassicPanelFavoriteIptv(

LeanbackClassicPanelIptvList(
modifier = Modifier.handleLeanbackKeyEvents(
onLeft = onClose,
onLeft = {
if (epgListVisible) epgListVisible = false
else onClose()
},
onRight = { epgListVisible = true },
),
title = "收藏列表",
iptvListProvider = { iptvList },
epgListProvider = { epgList },
initialIptvProvider = {
Expand Down Expand Up @@ -299,17 +314,44 @@ fun LeanbackClassicPanelFavoriteIptv(
onUserAction = onUserAction,
)

LeanbackClassicPanelEpgList(
visibleProvider = { epgListVisible },
onVisibleChanged = { epgListVisible = it },
epgProvider = { epgList.firstOrNull { it.channel == focusedIptv.channelName } },
exitFocusRequesterProvider = { focusedIptvFocusRequester },
onUserAction = onUserAction,
)
LeanbackVisible({ epgListVisible }) {
LeanbackClassicPanelEpgList(
epgProvider = { epgList.firstOrNull { it.channel == focusedIptv.channelName } },
exitFocusRequesterProvider = { focusedIptvFocusRequester },
onUserAction = onUserAction,
)
}
LeanbackVisible({ !epgListVisible }) {
LeanbackClassicPanelVerticalTip(
text = "向右查看节目单",
onTap = { epgListVisible = true },
)
}
}
}

@Composable
private fun LeanbackClassicPanelVerticalTip(
modifier: Modifier = Modifier,
text: String,
onTap: () -> Unit = {},
) {
Column(
modifier = modifier
.fillMaxHeight()
.pointerInput(Unit) {
detectTapGestures(onTap = { onTap() })
},
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
text.map {
Text(text = it.toString(), style = MaterialTheme.typography.labelSmall)
}
}
}

@Preview
@Preview(device = "id:Android TV (720p)")
@Composable
private fun LeanbackClassicPanelScreenPreview() {
LeanbackTheme {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package top.yogiczy.mytv.ui.screens.leanback.classicpanel.components

import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.PlayArrow
Expand All @@ -20,14 +18,13 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
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.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.tv.foundation.lazy.list.TvLazyColumn
Expand All @@ -50,33 +47,15 @@ import kotlin.math.max
@Composable
fun LeanbackClassicPanelEpgList(
modifier: Modifier = Modifier,
visibleProvider: () -> Boolean = { true },
epgProvider: () -> Epg? = { Epg() },
exitFocusRequesterProvider: () -> FocusRequester = { FocusRequester.Default },
onVisibleChanged: (Boolean) -> Unit = {},
onUserAction: () -> Unit = {},
) {
val childPadding = rememberLeanbackChildPadding()

val epg = epgProvider()
val visible = visibleProvider()

if (!visible && epg != null && epg.programmes.isNotEmpty()) {
Column(
modifier = Modifier
.fillMaxHeight()
.pointerInput(Unit) {
detectTapGestures(onTap = { onVisibleChanged(true) })
},
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
"向右查看节目单".map {
Text(text = it.toString(), style = MaterialTheme.typography.labelSmall)
}
}

} else if (epg != null && epg.programmes.isNotEmpty()) {
if (epg != null && epg.programmes.isNotEmpty()) {
val listState = remember(epg) {
TvLazyListState(max(0, epg.programmes.indexOfFirst { it.isLive() } - 2))
}
Expand Down Expand Up @@ -157,7 +136,11 @@ private fun LeanbackClassicPanelEpgItem(
overlineContent = {
val start = timeFormat.format(programme.startAt)
val end = timeFormat.format(programme.endAt)
Text(text = "$start ~ $end")
Text(
text = "$start ~ $end",
style = MaterialTheme.typography.labelMedium,
modifier = Modifier.alpha(0.8f),
)
},
trailingContent = {
if (programme.isLive()) {
Expand Down
Loading

0 comments on commit 6e4be73

Please sign in to comment.