Skip to content

Commit

Permalink
🎨 优化
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxieyoulei committed Apr 19, 2024
1 parent be0a872 commit 0ef245a
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 23 deletions.
16 changes: 9 additions & 7 deletions app/src/main/java/top/yogiczy/mytv/data/entities/EpgList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ data class EpgList(
) : List<Epg> by value {
companion object {

fun EpgList.currentProgrammes(iptv: Iptv): Pair<String?, String?> {
val epg = firstOrNull { it.channel == iptv.channelName } ?: return Pair(null, null)
fun EpgList.currentProgrammes(iptv: Iptv): EpgProgrammeCurrent? {
val epg = firstOrNull { it.channel == iptv.channelName } ?: return null

val currentProgramme =
epg.programmes.firstOrNull { it.startAt <= System.currentTimeMillis() && it.endAt >= System.currentTimeMillis() }
?: return Pair(null, null)
?: return null

return Pair(
currentProgramme.title,
epg.programmes.indexOf(currentProgramme).let { index ->
if (index + 1 < epg.programmes.size) epg.programmes[index + 1].title else null
return EpgProgrammeCurrent(
now = currentProgramme,
next = epg.programmes.indexOf(currentProgramme).let { index ->
if (index + 1 < epg.programmes.size) {
epg.programmes[index + 1]
} else null
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package top.yogiczy.mytv.data.entities
import kotlinx.serialization.Serializable

/**
* 频道界面
* 频道节目
*/
@Serializable
data class EpgProgramme(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package top.yogiczy.mytv.data.entities

data class EpgProgrammeCurrent(
/**
* 当前正在播放
*/
val now: EpgProgramme?,

/**
* 稍后播放
*/
val next: EpgProgramme?,
) {
companion object {
val EXAMPLE = EpgProgrammeCurrent(
now = EpgProgramme(
startAt = 0,
endAt = 0,
title = "实况录像-2023/2024赛季中国男子篮球职业联赛季后赛12进8第五场",
),
next = null,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ fun HomeContent(
channelNo = iptvGroupList.iptvIdx(state.currentIptv) + 1,
currentIptv = state.currentIptv,
playerError = playerState.error,
programmes = epgList.currentProgrammes(state.currentIptv),
currentProgrammes = epgList.currentProgrammes(state.currentIptv),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.NonInteractiveSurfaceDefaults
import androidx.tv.material3.Surface
import top.yogiczy.mytv.data.entities.EpgProgramme
import top.yogiczy.mytv.data.entities.EpgProgrammeCurrent
import top.yogiczy.mytv.data.entities.Iptv
import top.yogiczy.mytv.ui.rememberChildPadding
import top.yogiczy.mytv.ui.screens.panel.components.PanelChannelNo
Expand All @@ -27,7 +29,7 @@ fun IptvTempPanel(
channelNo: Int = 0,
currentIptv: Iptv = Iptv.EMPTY,
playerError: Boolean = false,
programmes: Pair<String?, String?> = Pair(null, null),
currentProgrammes: EpgProgrammeCurrent? = null,
) {
val childPadding = rememberChildPadding()

Expand All @@ -53,7 +55,7 @@ fun IptvTempPanel(
.sizeIn(maxWidth = 500.dp),
iptv = currentIptv,
playerError = playerError,
programmes = programmes,
currentProgrammes = currentProgrammes,
)
}
}
Expand All @@ -67,9 +69,17 @@ private fun IptvTempPanelPreview() {
channelNo = 1,
currentIptv = Iptv.EXAMPLE,
playerError = true,
programmes = Pair(
"实况录像-2023/2024赛季中国男子篮球职业联赛季后赛12进8第五场",
"实况录像-2023/2024赛季中国男子篮球职业联赛季后赛12进8第五场"
currentProgrammes = EpgProgrammeCurrent(
now = EpgProgramme(
startAt = 0,
endAt = 0,
title = "实况录像-2023/2024赛季中国男子篮球职业联赛季后赛12进8第五场"
),
next = EpgProgramme(
startAt = 0,
endAt = 0,
title = "实况录像-2023/2024赛季中国男子篮球职业联赛季后赛12进8第五场"
),
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fun PanelBottom(
Column(modifier = Modifier.align(Alignment.BottomStart)) {
PanelIptvInfo(
iptv = currentIptv,
programmes = epgList.currentProgrammes(currentIptv),
currentProgrammes = epgList.currentProgrammes(currentIptv),
playerError = playerState.error,
modifier = Modifier.padding(start = childPadding.start),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.ui.unit.dp
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import top.yogiczy.mytv.data.entities.EpgProgrammeCurrent
import top.yogiczy.mytv.data.entities.Iptv
import top.yogiczy.mytv.ui.theme.MyTVTheme

Expand All @@ -20,7 +21,7 @@ import top.yogiczy.mytv.ui.theme.MyTVTheme
fun PanelIptvInfo(
modifier: Modifier = Modifier,
iptv: Iptv = Iptv.EMPTY,
programmes: Pair<String?, String?> = Pair(null, null),
currentProgrammes: EpgProgrammeCurrent? = null,
playerError: Boolean = false,
) {
Column(modifier = modifier) {
Expand All @@ -44,27 +45,27 @@ fun PanelIptvInfo(
}
}
Text(
text = "正在播放:${programmes.first ?: "无节目"}",
text = "正在播放:${currentProgrammes?.now?.title ?: "无节目"}",
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.8f),
maxLines = 1,
)
Text(
text = "正在播放:${programmes.second ?: "无节目"}",
text = "正在播放:${currentProgrammes?.next?.title ?: "无节目"}",
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.8f),
maxLines = 1,
)
}
}

@Preview
@Preview(device = "id:Android TV (720p)")
@Composable
private fun PanelIptvInfoPreview() {
MyTVTheme {
PanelIptvInfo(
iptv = Iptv.EXAMPLE,
programmes = Pair("实况录像-2023/2024赛季中国男子篮球职业联赛季后赛12进8第五场", null),
currentProgrammes = EpgProgrammeCurrent.EXAMPLE,
playerError = true,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.tv.material3.CardDefaults
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import top.yogiczy.mytv.data.entities.EpgProgrammeCurrent
import top.yogiczy.mytv.data.entities.Iptv
import top.yogiczy.mytv.ui.theme.MyTVTheme

Expand All @@ -35,7 +36,7 @@ fun PanelIptvItem(
modifier: Modifier = Modifier,
iptv: Iptv = Iptv.EMPTY,
onIptvSelected: () -> Unit = {},
programmes: Pair<String?, String?> = Pair(null, null),
currentProgrammes: EpgProgrammeCurrent? = null,
) {
var isFocused by remember { mutableStateOf(false) }
val focusRequester = remember { FocusRequester() }
Expand Down Expand Up @@ -77,7 +78,7 @@ fun PanelIptvItem(
)

Text(
text = programmes.first ?: "",
text = currentProgrammes?.now?.title ?: "",
style = MaterialTheme.typography.labelSmall,
maxLines = 1,
modifier = Modifier.alpha(0.8f),
Expand All @@ -92,6 +93,7 @@ private fun PanelIptvItemPreview() {
MyTVTheme {
PanelIptvItem(
iptv = Iptv.EXAMPLE,
currentProgrammes = EpgProgrammeCurrent.EXAMPLE,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fun PanelIptvList(
items(iptvList) {
PanelIptvItem(
iptv = it,
programmes = epgList.currentProgrammes(it),
currentProgrammes = epgList.currentProgrammes(it),
onIptvSelected = { onIptvSelected(it) },
)
}
Expand Down

0 comments on commit 0ef245a

Please sign in to comment.