mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 08:01:20 +02:00
Scroll to new rows
This commit is contained in:
parent
75183802e7
commit
e11b9ecc72
5 changed files with 38 additions and 34 deletions
|
|
@ -20,7 +20,6 @@ import androidx.compose.ui.focus.focusRestorer
|
|||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.tv.material3.ListItem
|
||||
import androidx.tv.material3.MaterialTheme
|
||||
import androidx.tv.material3.Text
|
||||
import com.github.damontecres.wholphin.R
|
||||
|
|
@ -68,7 +67,7 @@ fun HomeSettingsAddRow(
|
|||
MetaRowType.COMBINED_CONTINUE_WATCHING,
|
||||
),
|
||||
) { index, type ->
|
||||
ListItem(
|
||||
HomeSettingsListItem(
|
||||
selected = false,
|
||||
headlineContent = {
|
||||
Text(stringResource(type.stringId))
|
||||
|
|
@ -91,7 +90,7 @@ fun HomeSettingsAddRow(
|
|||
)
|
||||
}
|
||||
itemsIndexed(libraries) { index, library ->
|
||||
ListItem(
|
||||
HomeSettingsListItem(
|
||||
selected = false,
|
||||
headlineContent = {
|
||||
Text(library.name)
|
||||
|
|
@ -114,7 +113,7 @@ fun HomeSettingsAddRow(
|
|||
)
|
||||
}
|
||||
item {
|
||||
ListItem(
|
||||
HomeSettingsListItem(
|
||||
selected = false,
|
||||
headlineContent = {
|
||||
Text(stringResource(MetaRowType.FAVORITES.stringId))
|
||||
|
|
@ -125,7 +124,7 @@ fun HomeSettingsAddRow(
|
|||
}
|
||||
if (showDiscover) {
|
||||
item {
|
||||
ListItem(
|
||||
HomeSettingsListItem(
|
||||
selected = false,
|
||||
headlineContent = {
|
||||
Text(stringResource(MetaRowType.DISCOVER.stringId))
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import androidx.compose.ui.focus.focusRequester
|
|||
import androidx.compose.ui.focus.focusRestorer
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.tv.material3.ListItem
|
||||
import androidx.tv.material3.Text
|
||||
import com.github.damontecres.wholphin.R
|
||||
import com.github.damontecres.wholphin.ui.ifElse
|
||||
|
|
@ -42,7 +41,7 @@ fun HomeSettingsFavoriteList(
|
|||
.focusRestorer(firstFocus),
|
||||
) {
|
||||
itemsIndexed(favoriteOptionsList) { index, type ->
|
||||
ListItem(
|
||||
HomeSettingsListItem(
|
||||
selected = false,
|
||||
headlineContent = {
|
||||
Text(
|
||||
|
|
|
|||
|
|
@ -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.RowSettings
|
||||
import com.github.damontecres.wholphin.util.ExceptionHandler
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
|
|
@ -44,6 +45,15 @@ fun HomeSettingsPage(
|
|||
val state by viewModel.state.collectAsState()
|
||||
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(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = modifier,
|
||||
|
|
@ -104,8 +114,7 @@ fun HomeSettingsPage(
|
|||
MetaRowType.NEXT_UP,
|
||||
MetaRowType.COMBINED_CONTINUE_WATCHING,
|
||||
-> {
|
||||
viewModel.addRow(it)
|
||||
backStack.add(HomeSettingsDestination.RowList)
|
||||
addRow { viewModel.addRow(it) }
|
||||
}
|
||||
|
||||
MetaRowType.FAVORITES -> {
|
||||
|
|
@ -124,9 +133,8 @@ fun HomeSettingsPage(
|
|||
is ChooseRowType -> {
|
||||
HomeLibraryRowTypeList(
|
||||
library = dest.library,
|
||||
onClick = {
|
||||
viewModel.addRow(dest.library, it)
|
||||
backStack.add(HomeSettingsDestination.RowList)
|
||||
onClick = { type ->
|
||||
addRow { viewModel.addRow(dest.library, type) }
|
||||
},
|
||||
modifier = destModifier,
|
||||
)
|
||||
|
|
@ -156,7 +164,7 @@ fun HomeSettingsPage(
|
|||
HomeSettingsDestination.ChooseFavorite -> {
|
||||
HomeSettingsFavoriteList(
|
||||
onClick = { type ->
|
||||
viewModel.addFavoriteRow(type)
|
||||
addRow { viewModel.addFavoriteRow(type) }
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.github.damontecres.wholphin.ui.main.settings
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
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.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
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.unit.dp
|
||||
import androidx.tv.material3.Icon
|
||||
import androidx.tv.material3.ListItem
|
||||
import androidx.tv.material3.MaterialTheme
|
||||
import androidx.tv.material3.Text
|
||||
import androidx.tv.material3.surfaceColorAtElevation
|
||||
import com.github.damontecres.wholphin.R
|
||||
import com.github.damontecres.wholphin.services.HomeRowConfigDisplay
|
||||
import com.github.damontecres.wholphin.ui.FontAwesome
|
||||
|
|
@ -70,7 +65,7 @@ fun HomeSettingsRowList(
|
|||
.focusRestorer(firstFocus),
|
||||
) {
|
||||
item {
|
||||
ListItem(
|
||||
HomeSettingsListItem(
|
||||
selected = false,
|
||||
headlineContent = {
|
||||
Text(
|
||||
|
|
@ -88,7 +83,7 @@ fun HomeSettingsRowList(
|
|||
)
|
||||
}
|
||||
item {
|
||||
ListItem(
|
||||
HomeSettingsListItem(
|
||||
selected = false,
|
||||
headlineContent = {
|
||||
Text(
|
||||
|
|
@ -106,7 +101,7 @@ fun HomeSettingsRowList(
|
|||
)
|
||||
}
|
||||
item {
|
||||
ListItem(
|
||||
HomeSettingsListItem(
|
||||
selected = false,
|
||||
headlineContent = {
|
||||
Text(
|
||||
|
|
@ -124,7 +119,7 @@ fun HomeSettingsRowList(
|
|||
)
|
||||
}
|
||||
item {
|
||||
ListItem(
|
||||
HomeSettingsListItem(
|
||||
selected = false,
|
||||
headlineContent = {
|
||||
Text(
|
||||
|
|
@ -189,13 +184,9 @@ fun HomeRowConfigContent(
|
|||
modifier =
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(min = 40.dp, max = 88.dp)
|
||||
.background(
|
||||
color = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp),
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
),
|
||||
.heightIn(min = 40.dp, max = 88.dp),
|
||||
) {
|
||||
ListItem(
|
||||
HomeSettingsListItem(
|
||||
selected = false,
|
||||
headlineContent = {
|
||||
Text(
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import com.github.damontecres.wholphin.util.LoadingState
|
|||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
|
|
@ -114,6 +115,15 @@ class HomeSettingsViewModel
|
|||
}
|
||||
}
|
||||
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 {
|
||||
it.copy(loading = LoadingState.Success, rowData = rows)
|
||||
}
|
||||
|
|
@ -165,7 +175,7 @@ class HomeSettingsViewModel
|
|||
}
|
||||
}
|
||||
|
||||
fun addRow(type: MetaRowType) {
|
||||
fun addRow(type: MetaRowType): Job =
|
||||
viewModelScope.launchIO {
|
||||
val id = state.value.rows.size
|
||||
val newRow =
|
||||
|
|
@ -210,12 +220,11 @@ class HomeSettingsViewModel
|
|||
}
|
||||
fetchRowData()
|
||||
}
|
||||
}
|
||||
|
||||
fun addRow(
|
||||
library: Library,
|
||||
rowType: LibraryRowType,
|
||||
) {
|
||||
): Job =
|
||||
viewModelScope.launchIO {
|
||||
val id = state.value.rows.size
|
||||
val newRow =
|
||||
|
|
@ -262,9 +271,8 @@ class HomeSettingsViewModel
|
|||
}
|
||||
fetchRowData()
|
||||
}
|
||||
}
|
||||
|
||||
fun addFavoriteRow(type: BaseItemKind) {
|
||||
fun addFavoriteRow(type: BaseItemKind): Job =
|
||||
viewModelScope.launchIO {
|
||||
Timber.v("Adding favorite row for $type")
|
||||
val id = state.value.rows.size
|
||||
|
|
@ -282,7 +290,6 @@ class HomeSettingsViewModel
|
|||
}
|
||||
fetchRowData()
|
||||
}
|
||||
}
|
||||
|
||||
fun updateViewOptions(
|
||||
rowId: Int,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue