Skip to content

Commit 335cd0e

Browse files
Morten Friesgaardnielsvanvelzen
authored andcommitted
adds watch next channel to top of home tab
1 parent 0993f78 commit 335cd0e

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

app/src/main/kotlin/nl/ndat/tvlauncher/data/repository/ChannelRepository.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,5 @@ class ChannelRepository(
123123
fun getChannels() = database.channels.getAll().executeAsListFlow()
124124
fun getFavoriteAppChannels() = database.channels.getFavoriteAppChannels(::Channel).executeAsListFlow()
125125
fun getProgramsByChannel(channel: Channel) = database.channelPrograms.getByChannel(channel.id).executeAsListFlow()
126+
fun getWatchNextPrograms() = database.channels.getById(ChannelResolver.CHANNEL_ID_WATCH_NEXT).executeAsListFlow()
126127
}

app/src/main/kotlin/nl/ndat/tvlauncher/ui/tab/home/HomeTab.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import androidx.compose.runtime.collectAsState
99
import androidx.compose.runtime.getValue
1010
import androidx.compose.runtime.remember
1111
import androidx.compose.ui.Modifier
12+
import androidx.compose.ui.res.stringResource
1213
import androidx.compose.ui.unit.dp
14+
import nl.ndat.tvlauncher.R
1315
import nl.ndat.tvlauncher.ui.tab.home.row.AppCardRow
1416
import nl.ndat.tvlauncher.ui.tab.home.row.ChannelProgramCardRow
1517
import org.koin.androidx.compose.koinViewModel
@@ -21,6 +23,7 @@ fun HomeTab(
2123
val viewModel = koinViewModel<HomeTabViewModel>()
2224
val apps by viewModel.apps.collectAsState()
2325
val channels by viewModel.channels.collectAsState()
26+
val watchNext by viewModel.watchNext.collectAsState()
2427

2528
LazyColumn(
2629
verticalArrangement = Arrangement.spacedBy(8.dp),
@@ -33,6 +36,18 @@ fun HomeTab(
3336
)
3437
}
3538

39+
items(
40+
items = watchNext,
41+
key = { channel -> channel.id }
42+
) { channel ->
43+
val programs by viewModel.channelPrograms(channel).collectAsState(initial = emptyList())
44+
45+
ChannelProgramCardRow(
46+
title = stringResource(R.string.channel_watch_next),
47+
programs = programs,
48+
)
49+
}
50+
3651
items(
3752
items = channels,
3853
key = { channel -> channel.id }
@@ -43,9 +58,10 @@ fun HomeTab(
4358
val programs by viewModel.channelPrograms(channel).collectAsState(initial = emptyList())
4459

4560
if (app != null) {
61+
val title = stringResource(R.string.channel_preview, app.displayName, channel.displayName)
62+
4663
ChannelProgramCardRow(
47-
channel = channel,
48-
app = app,
64+
title = title,
4965
programs = programs,
5066
)
5167
}

app/src/main/kotlin/nl/ndat/tvlauncher/ui/tab/home/HomeTabViewModel.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class HomeTabViewModel(
2020
val channels = channelRepository.getFavoriteAppChannels()
2121
.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())
2222

23+
val watchNext = channelRepository.getWatchNextPrograms()
24+
.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())
25+
2326
fun channelPrograms(channel: Channel) = channelRepository.getProgramsByChannel(channel)
2427

2528
fun favoriteApp(app: App, favorite: Boolean) = viewModelScope.launch {

app/src/main/kotlin/nl/ndat/tvlauncher/ui/tab/home/row/ChannelProgramCardRow.kt

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,19 @@ import androidx.compose.runtime.setValue
1515
import androidx.compose.ui.Modifier
1616
import androidx.compose.ui.focus.focusRequester
1717
import androidx.compose.ui.focus.onFocusChanged
18-
import androidx.compose.ui.res.stringResource
1918
import androidx.compose.ui.unit.dp
2019
import androidx.tv.material3.MaterialTheme
2120
import androidx.tv.material3.Text
22-
import nl.ndat.tvlauncher.R
23-
import nl.ndat.tvlauncher.data.model.ChannelType
24-
import nl.ndat.tvlauncher.data.sqldelight.App
25-
import nl.ndat.tvlauncher.data.sqldelight.Channel
2621
import nl.ndat.tvlauncher.data.sqldelight.ChannelProgram
2722
import nl.ndat.tvlauncher.ui.component.card.ChannelProgramCard
2823
import nl.ndat.tvlauncher.util.modifier.ifElse
2924

3025
@Composable
3126
fun ChannelProgramCardRow(
3227
modifier: Modifier = Modifier,
33-
channel: Channel,
34-
app: App,
28+
title: String,
3529
programs: List<ChannelProgram>,
3630
) {
37-
val title = when (channel.type) {
38-
ChannelType.WATCH_NEXT -> stringResource(R.string.channel_watch_next)
39-
ChannelType.PREVIEW -> stringResource(
40-
R.string.channel_preview,
41-
app.displayName,
42-
channel.displayName
43-
)
44-
}
45-
4631
var focusedProgram by remember { mutableStateOf<ChannelProgram?>(null) }
4732

4833
if (programs.isNotEmpty()) {

0 commit comments

Comments
 (0)