Fix a few customize home bugs (#929)

## Description
Hopefully this is the last round of bug fixes for customizing the home
page!

Fixes a possible crash when scrolling after adding a row after resetting
to default or loading remote settings that have more rows than the
original settings

Fixes some incorrect titles

### Related issues
Related to #399 & #803

### Testing
Emulator & nvidia shield

## Screenshots
N/A

## AI or LLM usage
None
This commit is contained in:
Ray 2026-02-19 21:50:55 -05:00 committed by GitHub
parent 219e4b01db
commit 65f20e2daf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 41 additions and 19 deletions

View file

@ -13,6 +13,7 @@ import com.github.damontecres.wholphin.ui.DefaultItemFields
import com.github.damontecres.wholphin.ui.SlimItemFields import com.github.damontecres.wholphin.ui.SlimItemFields
import com.github.damontecres.wholphin.ui.components.getGenreImageMap import com.github.damontecres.wholphin.ui.components.getGenreImageMap
import com.github.damontecres.wholphin.ui.main.settings.Library import com.github.damontecres.wholphin.ui.main.settings.Library
import com.github.damontecres.wholphin.ui.main.settings.favoriteOptions
import com.github.damontecres.wholphin.ui.toBaseItems import com.github.damontecres.wholphin.ui.toBaseItems
import com.github.damontecres.wholphin.ui.toServerString import com.github.damontecres.wholphin.ui.toServerString
import com.github.damontecres.wholphin.util.GetGenresRequestHandler import com.github.damontecres.wholphin.util.GetGenresRequestHandler
@ -511,7 +512,11 @@ class HomeSettingsService
} }
is HomeRowConfig.Favorite -> { is HomeRowConfig.Favorite -> {
val name = context.getString(R.string.favorites) // TODO "Favorite <type>" val name =
context.getString(
R.string.favorite_items,
context.getString(favoriteOptions[config.kind]!!),
)
HomeRowConfigDisplay(id, name, config) HomeRowConfigDisplay(id, name, config)
} }
@ -785,6 +790,11 @@ class HomeSettingsService
} }
is HomeRowConfig.Favorite -> { is HomeRowConfig.Favorite -> {
val title =
context.getString(
R.string.favorite_items,
context.getString(favoriteOptions[row.kind]!!),
)
if (row.kind == BaseItemKind.PERSON) { if (row.kind == BaseItemKind.PERSON) {
val request = val request =
GetPersonsRequest( GetPersonsRequest(
@ -801,7 +811,7 @@ class HomeSettingsService
.map { BaseItem(it, true) } .map { BaseItem(it, true) }
.let { .let {
Success( Success(
context.getString(R.string.favorites), // TODO title,
it, it,
row.viewOptions, row.viewOptions,
) )
@ -822,7 +832,7 @@ class HomeSettingsService
.map { BaseItem(it, row.viewOptions.useSeries) } .map { BaseItem(it, row.viewOptions.useSeries) }
.let { .let {
Success( Success(
context.getString(R.string.favorites), // TODO title,
it, it,
row.viewOptions, row.viewOptions,
) )

View file

@ -127,6 +127,6 @@ enum class LibraryRowType(
TV_CHANNELS(R.string.channels), TV_CHANNELS(R.string.channels),
TV_PROGRAMS(R.string.live_tv), TV_PROGRAMS(R.string.live_tv),
RECENTLY_RECORDED(R.string.recently_recorded), RECENTLY_RECORDED(R.string.recently_recorded),
COLLECTION(R.string.collections), COLLECTION(R.string.collection),
PLAYLIST(R.string.playlist), PLAYLIST(R.string.playlist),
} }

View file

@ -66,15 +66,20 @@ fun HomeSettingsPage(
val discoverEnabled = false // by viewModel.discoverEnabled.collectAsState(false) val discoverEnabled = false // by viewModel.discoverEnabled.collectAsState(false)
// Adds a row, waits until its done loading, then scrolls to the new row // Adds a row, waits until its done loading, then scrolls to the new row
fun addRow(func: () -> Job) { fun addRow(
scrollToBottom: Boolean = true,
func: () -> Job,
) {
scope.launch(ExceptionHandler(autoToast = true)) { scope.launch(ExceptionHandler(autoToast = true)) {
while (backStack.size > 1) { while (backStack.size > 1) {
backStack.removeAt(backStack.lastIndex) backStack.removeAt(backStack.lastIndex)
} }
func.invoke().join() func.invoke().join()
if (scrollToBottom) {
listState.animateScrollToItem(state.rows.lastIndex) listState.animateScrollToItem(state.rows.lastIndex)
} }
} }
}
Row( Row(
horizontalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp),
@ -273,7 +278,7 @@ fun HomeSettingsPage(
onClickReset = { onClickReset = {
showConfirmDialog = showConfirmDialog =
ShowConfirm(R.string.overwrite_local_settings) { ShowConfirm(R.string.overwrite_local_settings) {
viewModel.resetToDefault() addRow(false) { viewModel.resetToDefault() }
} }
}, },
modifier = destModifier, modifier = destModifier,

View file

@ -141,7 +141,7 @@ fun HomeSettingsRowList(
) )
} }
item { item {
TitleText(stringResource(R.string.home_rows)) TitleText(stringResource(R.string.home_rows) + " (${state.rows.size})")
HorizontalDivider() HorizontalDivider()
} }
itemsIndexed(state.rows, key = { _, row -> row.id }) { index, row -> itemsIndexed(state.rows, key = { _, row -> row.id }) { index, row ->

View file

@ -114,7 +114,7 @@ class HomeSettingsViewModel
} }
private suspend fun fetchRowData() { private suspend fun fetchRowData() {
val limit = 6 val limit = 8
val semaphore = Semaphore(4) val semaphore = Semaphore(4)
val rows = val rows =
serverRepository.currentUserDto.value?.let { userDto -> serverRepository.currentUserDto.value?.let { userDto ->
@ -219,7 +219,7 @@ class HomeSettingsViewModel
MetaRowType.NEXT_UP -> { MetaRowType.NEXT_UP -> {
HomeRowConfigDisplay( HomeRowConfigDisplay(
id = id, id = id,
title = context.getString(R.string.continue_watching), title = context.getString(R.string.next_up),
config = NextUp(), config = NextUp(),
) )
} }
@ -356,7 +356,11 @@ class HomeSettingsViewModel
val newRow = val newRow =
HomeRowConfigDisplay( HomeRowConfigDisplay(
id = id, id = id,
title = context.getString(favoriteOptions[type]!!), title =
context.getString(
R.string.favorite_items,
context.getString(favoriteOptions[type]!!),
),
config = HomeRowConfig.Favorite(type), config = HomeRowConfig.Favorite(type),
) )
updateState { updateState {
@ -480,6 +484,7 @@ class HomeSettingsViewModel
result.rows.mapIndexed { index, config -> result.rows.mapIndexed { index, config ->
homeSettingsService.resolve(index, config) homeSettingsService.resolve(index, config)
} }
idCounter = newRows.maxOfOrNull { it.id }?.plus(1) ?: 0
_state.update { _state.update {
it.copy(rows = newRows) it.copy(rows = newRows)
} }
@ -509,6 +514,7 @@ class HomeSettingsViewModel
val result = homeSettingsService.parseFromWebConfig(user.id) val result = homeSettingsService.parseFromWebConfig(user.id)
if (result != null) { if (result != null) {
Timber.v("Got web settings") Timber.v("Got web settings")
idCounter = result.rows.maxOfOrNull { it.id }?.plus(1) ?: 0
_state.update { _state.update {
it.copy(rows = result.rows) it.copy(rows = result.rows)
} }
@ -593,17 +599,17 @@ class HomeSettingsViewModel
} }
} }
fun resetToDefault() { fun resetToDefault() =
viewModelScope.launchIO { viewModelScope.launchIO {
val userId = serverRepository.currentUser.value?.id ?: return@launchIO val userId = serverRepository.currentUser.value?.id ?: return@launchIO
_state.update { it.copy(loading = LoadingState.Loading) } _state.update { it.copy(loading = LoadingState.Loading) }
val result = homeSettingsService.createDefault(userId) val result = homeSettingsService.createDefault(userId)
idCounter = result.rows.maxOfOrNull { it.id }?.plus(1) ?: 0
_state.update { _state.update {
it.copy(rows = result.rows) it.copy(rows = result.rows, rowData = emptyList())
} }
fetchRowData() fetchRowData()
} }
}
private suspend fun showSaveToast() = private suspend fun showSaveToast() =
showToast( showToast(
@ -729,9 +735,9 @@ data class HomePageSettingsState(
val EMPTY = val EMPTY =
HomePageSettingsState( HomePageSettingsState(
LoadingState.Pending, LoadingState.Pending,
listOf(), emptyList(),
listOf(), emptyList(),
listOf(), emptyList(),
) )
} }
} }

View file

@ -188,6 +188,7 @@
<string name="samples">Samples</string> <string name="samples">Samples</string>
<string name="featurettes">Featurettes</string> <string name="featurettes">Featurettes</string>
<string name="shorts">Shorts</string> <string name="shorts">Shorts</string>
<string name="favorite_items">Favorite %s</string>
<plurals name="trailers"> <plurals name="trailers">
<item quantity="zero">Trailers</item> <item quantity="zero">Trailers</item>
@ -505,8 +506,8 @@
<string name="apply_all_rows">Apply to all rows</string> <string name="apply_all_rows">Apply to all rows</string>
<string name="customize_home">Customize home page</string> <string name="customize_home">Customize home page</string>
<string name="home_rows">Home rows</string> <string name="home_rows">Home rows</string>
<string name="load_from_server">Load from server</string> <string name="load_from_server">Load from server user profile</string>
<string name="save_to_server">Save to server</string> <string name="save_to_server">Save to server user profile</string>
<string name="load_from_web_client">Load from web client</string> <string name="load_from_web_client">Load from web client</string>
<string name="use_series">Use series image</string> <string name="use_series">Use series image</string>
<string name="add_row_for">Add row for %1$s</string> <string name="add_row_for">Add row for %1$s</string>