Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lsongdev committed Aug 29, 2024
1 parent 2c59a4e commit 27e07da
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 202 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/me/lsong/mytv/epg/Epg.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package me.lsong.mytv.epg

import androidx.compose.runtime.Immutable
import kotlinx.serialization.Serializable
import me.lsong.mytv.iptv.TVChannel
import me.lsong.mytv.providers.TVChannel
import me.lsong.mytv.epg.EpgChannel.Companion.currentProgrammes
import me.lsong.mytv.epg.EpgProgramme.Companion.isLive

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.lsong.mytv.iptv
package me.lsong.mytv.providers

import android.util.Log
import androidx.compose.runtime.Immutable
Expand Down
87 changes: 69 additions & 18 deletions app/src/main/java/me/lsong/mytv/ui/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand All @@ -38,6 +45,7 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.tv.foundation.lazy.list.TvLazyColumn
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
Expand All @@ -46,16 +54,16 @@ import me.lsong.mytv.R
import me.lsong.mytv.epg.EpgList
import me.lsong.mytv.epg.EpgList.Companion.currentProgrammes
import me.lsong.mytv.epg.EpgRepository
import me.lsong.mytv.iptv.IPTVProvider
import me.lsong.mytv.iptv.TVChannel
import me.lsong.mytv.iptv.TVGroupList
import me.lsong.mytv.iptv.TVGroupList.Companion.channels
import me.lsong.mytv.iptv.TVGroupList.Companion.findGroupIndex
import me.lsong.mytv.iptv.TVProvider
import me.lsong.mytv.providers.IPTVProvider
import me.lsong.mytv.providers.TVChannel
import me.lsong.mytv.providers.TVGroupList
import me.lsong.mytv.providers.TVGroupList.Companion.channels
import me.lsong.mytv.providers.TVGroupList.Companion.findGroupIndex
import me.lsong.mytv.providers.TVProvider
import me.lsong.mytv.ui.components.LeanbackVisible
import me.lsong.mytv.ui.components.MonitorScreen
import me.lsong.mytv.ui.components.MyTvMenu
import me.lsong.mytv.ui.components.MyTvMenuItem
import me.lsong.mytv.ui.components.MyTvMenuItemList
import me.lsong.mytv.ui.components.MyTvNowPlaying
import me.lsong.mytv.ui.player.MyTvVideoScreen
import me.lsong.mytv.ui.player.rememberLeanbackVideoPlayerState
Expand Down Expand Up @@ -143,7 +151,7 @@ fun MyTvMenuWidget(
channelProvider: () -> TVChannel = { TVChannel() },
groupListProvider: () -> TVGroupList = { TVGroupList() },
onSelected: (TVChannel) -> Unit = {},
onSettings: () -> Unit = {},
onSettings: (() -> Unit)? = null,
onUserAction: () -> Unit = {}
) {
val groupList = groupListProvider()
Expand Down Expand Up @@ -179,21 +187,64 @@ fun MyTvMenuWidget(
} ?: emptyList()
}

Row {
MyTvMenu(
groups = groups,
itemsProvider = itemsProvider,
currentGroup = currentGroup,
currentItem = currentMenuItem,
onItemSelected = { selectedItem ->
val selectedChannel = groupList.channels.first { it.title == selectedItem.title }
var focusedGroup by remember { mutableStateOf(currentGroup) }
var focusedItem by remember { mutableStateOf(currentMenuItem) }
var items by remember { mutableStateOf(itemsProvider(focusedGroup.title)) }
val rightListFocusRequester = remember { FocusRequester() }

Row(modifier = modifier) {
Column (
verticalArrangement = Arrangement.SpaceBetween,
modifier = Modifier
.width(250.dp)
.fillMaxHeight(),
) {
MyTvMenuItemList(
items = groups,
selectedItem = focusedGroup,
onFocused = { menuItem ->
focusedGroup = menuItem
items = itemsProvider(menuItem.title)
},
onSelected = { menuItem ->
focusedGroup = menuItem
items = itemsProvider(menuItem.title)
focusedItem = items.firstOrNull() ?: MyTvMenuItem()
rightListFocusRequester.requestFocus()
},
onUserAction = onUserAction,
modifier = Modifier.weight(1f)
)
LeanbackVisible ({ onSettings != null }) {
TvLazyColumn(
modifier = Modifier.width(250.dp),
contentPadding = PaddingValues(8.dp),
) {
item {
MyTvMenuItem(
item = MyTvMenuItem(icon = Icons.Default.Settings, title = "Settings"),
onSelected = onSettings!!
)
}
}
}
}
MyTvMenuItemList(
items = items,
selectedItem = focusedItem,
onSelected = { menuItem ->
focusedItem = menuItem
val selectedChannel = groupList.channels.first { it.title == menuItem.title }
onSelected(selectedChannel)
},
modifier = modifier,
onSettings = onSettings,
onUserAction = onUserAction,
focusRequester = rightListFocusRequester
)
}

LaunchedEffect(Unit) {
rightListFocusRequester.requestFocus()
}
}

@Composable
Expand Down
10 changes: 4 additions & 6 deletions app/src/main/java/me/lsong/mytv/ui/MainState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import me.lsong.mytv.iptv.TVChannel
import me.lsong.mytv.iptv.TVGroupList
import me.lsong.mytv.iptv.TVGroupList.Companion.channels
import me.lsong.mytv.iptv.TVGroupList.Companion.findChannelIndex
import me.lsong.mytv.utils.Constants
import me.lsong.mytv.providers.TVChannel
import me.lsong.mytv.providers.TVGroupList
import me.lsong.mytv.providers.TVGroupList.Companion.channels
import me.lsong.mytv.providers.TVGroupList.Companion.findChannelIndex
import me.lsong.mytv.ui.player.LeanbackVideoPlayerState
import me.lsong.mytv.ui.player.rememberLeanbackVideoPlayerState
import me.lsong.mytv.utils.Settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import me.lsong.mytv.iptv.TVChannel
import me.lsong.mytv.providers.TVChannel
import me.lsong.mytv.ui.theme.LeanbackTheme
import me.lsong.mytv.utils.isIPv6

Expand Down
Loading

0 comments on commit 27e07da

Please sign in to comment.