Scroll to new rows

This commit is contained in:
Damontecres 2026-01-29 15:19:33 -05:00
parent 75183802e7
commit e11b9ecc72
No known key found for this signature in database
5 changed files with 38 additions and 34 deletions

View file

@ -20,7 +20,6 @@ import androidx.compose.ui.focus.focusRestorer
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.tv.material3.ListItem
import androidx.tv.material3.MaterialTheme import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text import androidx.tv.material3.Text
import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.R
@ -68,7 +67,7 @@ fun HomeSettingsAddRow(
MetaRowType.COMBINED_CONTINUE_WATCHING, MetaRowType.COMBINED_CONTINUE_WATCHING,
), ),
) { index, type -> ) { index, type ->
ListItem( HomeSettingsListItem(
selected = false, selected = false,
headlineContent = { headlineContent = {
Text(stringResource(type.stringId)) Text(stringResource(type.stringId))
@ -91,7 +90,7 @@ fun HomeSettingsAddRow(
) )
} }
itemsIndexed(libraries) { index, library -> itemsIndexed(libraries) { index, library ->
ListItem( HomeSettingsListItem(
selected = false, selected = false,
headlineContent = { headlineContent = {
Text(library.name) Text(library.name)
@ -114,7 +113,7 @@ fun HomeSettingsAddRow(
) )
} }
item { item {
ListItem( HomeSettingsListItem(
selected = false, selected = false,
headlineContent = { headlineContent = {
Text(stringResource(MetaRowType.FAVORITES.stringId)) Text(stringResource(MetaRowType.FAVORITES.stringId))
@ -125,7 +124,7 @@ fun HomeSettingsAddRow(
} }
if (showDiscover) { if (showDiscover) {
item { item {
ListItem( HomeSettingsListItem(
selected = false, selected = false,
headlineContent = { headlineContent = {
Text(stringResource(MetaRowType.DISCOVER.stringId)) Text(stringResource(MetaRowType.DISCOVER.stringId))

View file

@ -15,7 +15,6 @@ import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.focusRestorer import androidx.compose.ui.focus.focusRestorer
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.tv.material3.ListItem
import androidx.tv.material3.Text import androidx.tv.material3.Text
import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.R
import com.github.damontecres.wholphin.ui.ifElse import com.github.damontecres.wholphin.ui.ifElse
@ -42,7 +41,7 @@ fun HomeSettingsFavoriteList(
.focusRestorer(firstFocus), .focusRestorer(firstFocus),
) { ) {
itemsIndexed(favoriteOptionsList) { index, type -> itemsIndexed(favoriteOptionsList) { index, type ->
ListItem( HomeSettingsListItem(
selected = false, selected = false,
headlineContent = { headlineContent = {
Text( Text(

View file

@ -27,6 +27,7 @@ import com.github.damontecres.wholphin.ui.main.HomePageContent
import com.github.damontecres.wholphin.ui.main.settings.HomeSettingsDestination.ChooseRowType import com.github.damontecres.wholphin.ui.main.settings.HomeSettingsDestination.ChooseRowType
import com.github.damontecres.wholphin.ui.main.settings.HomeSettingsDestination.RowSettings import com.github.damontecres.wholphin.ui.main.settings.HomeSettingsDestination.RowSettings
import com.github.damontecres.wholphin.util.ExceptionHandler import com.github.damontecres.wholphin.util.ExceptionHandler
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import timber.log.Timber import timber.log.Timber
@ -44,6 +45,15 @@ fun HomeSettingsPage(
val state by viewModel.state.collectAsState() val state by viewModel.state.collectAsState()
val discoverEnabled by viewModel.discoverEnabled.collectAsState(false) val discoverEnabled by viewModel.discoverEnabled.collectAsState(false)
// Adds a row, waits until its done loading, then scrolls to the new row
fun addRow(func: () -> Job) {
scope.launch(ExceptionHandler(autoToast = true)) {
backStack.add(HomeSettingsDestination.RowList)
func.invoke().join()
listState.animateScrollToItem(state.rows.lastIndex)
}
}
Row( Row(
horizontalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = modifier, modifier = modifier,
@ -104,8 +114,7 @@ fun HomeSettingsPage(
MetaRowType.NEXT_UP, MetaRowType.NEXT_UP,
MetaRowType.COMBINED_CONTINUE_WATCHING, MetaRowType.COMBINED_CONTINUE_WATCHING,
-> { -> {
viewModel.addRow(it) addRow { viewModel.addRow(it) }
backStack.add(HomeSettingsDestination.RowList)
} }
MetaRowType.FAVORITES -> { MetaRowType.FAVORITES -> {
@ -124,9 +133,8 @@ fun HomeSettingsPage(
is ChooseRowType -> { is ChooseRowType -> {
HomeLibraryRowTypeList( HomeLibraryRowTypeList(
library = dest.library, library = dest.library,
onClick = { onClick = { type ->
viewModel.addRow(dest.library, it) addRow { viewModel.addRow(dest.library, type) }
backStack.add(HomeSettingsDestination.RowList)
}, },
modifier = destModifier, modifier = destModifier,
) )
@ -156,7 +164,7 @@ fun HomeSettingsPage(
HomeSettingsDestination.ChooseFavorite -> { HomeSettingsDestination.ChooseFavorite -> {
HomeSettingsFavoriteList( HomeSettingsFavoriteList(
onClick = { type -> onClick = { type ->
viewModel.addFavoriteRow(type) addRow { viewModel.addFavoriteRow(type) }
}, },
) )
} }

View file

@ -1,6 +1,5 @@
package com.github.damontecres.wholphin.ui.main.settings package com.github.damontecres.wholphin.ui.main.settings
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
@ -11,7 +10,6 @@ import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Create import androidx.compose.material.icons.filled.Create
@ -32,10 +30,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.tv.material3.Icon import androidx.tv.material3.Icon
import androidx.tv.material3.ListItem
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text import androidx.tv.material3.Text
import androidx.tv.material3.surfaceColorAtElevation
import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.R
import com.github.damontecres.wholphin.services.HomeRowConfigDisplay import com.github.damontecres.wholphin.services.HomeRowConfigDisplay
import com.github.damontecres.wholphin.ui.FontAwesome import com.github.damontecres.wholphin.ui.FontAwesome
@ -70,7 +65,7 @@ fun HomeSettingsRowList(
.focusRestorer(firstFocus), .focusRestorer(firstFocus),
) { ) {
item { item {
ListItem( HomeSettingsListItem(
selected = false, selected = false,
headlineContent = { headlineContent = {
Text( Text(
@ -88,7 +83,7 @@ fun HomeSettingsRowList(
) )
} }
item { item {
ListItem( HomeSettingsListItem(
selected = false, selected = false,
headlineContent = { headlineContent = {
Text( Text(
@ -106,7 +101,7 @@ fun HomeSettingsRowList(
) )
} }
item { item {
ListItem( HomeSettingsListItem(
selected = false, selected = false,
headlineContent = { headlineContent = {
Text( Text(
@ -124,7 +119,7 @@ fun HomeSettingsRowList(
) )
} }
item { item {
ListItem( HomeSettingsListItem(
selected = false, selected = false,
headlineContent = { headlineContent = {
Text( Text(
@ -189,13 +184,9 @@ fun HomeRowConfigContent(
modifier = modifier =
Modifier Modifier
.fillMaxWidth() .fillMaxWidth()
.heightIn(min = 40.dp, max = 88.dp) .heightIn(min = 40.dp, max = 88.dp),
.background(
color = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp),
shape = RoundedCornerShape(8.dp),
),
) { ) {
ListItem( HomeSettingsListItem(
selected = false, selected = false,
headlineContent = { headlineContent = {
Text( Text(

View file

@ -30,6 +30,7 @@ import com.github.damontecres.wholphin.util.LoadingState
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
@ -114,6 +115,15 @@ class HomeSettingsViewModel
} }
} }
rows?.let { rows -> rows?.let { rows ->
rows
.firstOrNull { it is HomeRowLoadingState.Success && it.items.isNotEmpty() }
?.let {
it as HomeRowLoadingState.Success
it.items.firstOrNull()?.let {
Timber.v("Updating backdrop")
updateBackdrop(it)
}
}
updateState { updateState {
it.copy(loading = LoadingState.Success, rowData = rows) it.copy(loading = LoadingState.Success, rowData = rows)
} }
@ -165,7 +175,7 @@ class HomeSettingsViewModel
} }
} }
fun addRow(type: MetaRowType) { fun addRow(type: MetaRowType): Job =
viewModelScope.launchIO { viewModelScope.launchIO {
val id = state.value.rows.size val id = state.value.rows.size
val newRow = val newRow =
@ -210,12 +220,11 @@ class HomeSettingsViewModel
} }
fetchRowData() fetchRowData()
} }
}
fun addRow( fun addRow(
library: Library, library: Library,
rowType: LibraryRowType, rowType: LibraryRowType,
) { ): Job =
viewModelScope.launchIO { viewModelScope.launchIO {
val id = state.value.rows.size val id = state.value.rows.size
val newRow = val newRow =
@ -262,9 +271,8 @@ class HomeSettingsViewModel
} }
fetchRowData() fetchRowData()
} }
}
fun addFavoriteRow(type: BaseItemKind) { fun addFavoriteRow(type: BaseItemKind): Job =
viewModelScope.launchIO { viewModelScope.launchIO {
Timber.v("Adding favorite row for $type") Timber.v("Adding favorite row for $type")
val id = state.value.rows.size val id = state.value.rows.size
@ -282,7 +290,6 @@ class HomeSettingsViewModel
} }
fetchRowData() fetchRowData()
} }
}
fun updateViewOptions( fun updateViewOptions(
rowId: Int, rowId: Int,