mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
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:
parent
219e4b01db
commit
65f20e2daf
6 changed files with 41 additions and 19 deletions
|
|
@ -13,6 +13,7 @@ import com.github.damontecres.wholphin.ui.DefaultItemFields
|
|||
import com.github.damontecres.wholphin.ui.SlimItemFields
|
||||
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.favoriteOptions
|
||||
import com.github.damontecres.wholphin.ui.toBaseItems
|
||||
import com.github.damontecres.wholphin.ui.toServerString
|
||||
import com.github.damontecres.wholphin.util.GetGenresRequestHandler
|
||||
|
|
@ -511,7 +512,11 @@ class HomeSettingsService
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
@ -785,6 +790,11 @@ class HomeSettingsService
|
|||
}
|
||||
|
||||
is HomeRowConfig.Favorite -> {
|
||||
val title =
|
||||
context.getString(
|
||||
R.string.favorite_items,
|
||||
context.getString(favoriteOptions[row.kind]!!),
|
||||
)
|
||||
if (row.kind == BaseItemKind.PERSON) {
|
||||
val request =
|
||||
GetPersonsRequest(
|
||||
|
|
@ -801,7 +811,7 @@ class HomeSettingsService
|
|||
.map { BaseItem(it, true) }
|
||||
.let {
|
||||
Success(
|
||||
context.getString(R.string.favorites), // TODO
|
||||
title,
|
||||
it,
|
||||
row.viewOptions,
|
||||
)
|
||||
|
|
@ -822,7 +832,7 @@ class HomeSettingsService
|
|||
.map { BaseItem(it, row.viewOptions.useSeries) }
|
||||
.let {
|
||||
Success(
|
||||
context.getString(R.string.favorites), // TODO
|
||||
title,
|
||||
it,
|
||||
row.viewOptions,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -127,6 +127,6 @@ enum class LibraryRowType(
|
|||
TV_CHANNELS(R.string.channels),
|
||||
TV_PROGRAMS(R.string.live_tv),
|
||||
RECENTLY_RECORDED(R.string.recently_recorded),
|
||||
COLLECTION(R.string.collections),
|
||||
COLLECTION(R.string.collection),
|
||||
PLAYLIST(R.string.playlist),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,13 +66,18 @@ fun HomeSettingsPage(
|
|||
val discoverEnabled = false // by viewModel.discoverEnabled.collectAsState(false)
|
||||
|
||||
// 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)) {
|
||||
while (backStack.size > 1) {
|
||||
backStack.removeAt(backStack.lastIndex)
|
||||
}
|
||||
func.invoke().join()
|
||||
listState.animateScrollToItem(state.rows.lastIndex)
|
||||
if (scrollToBottom) {
|
||||
listState.animateScrollToItem(state.rows.lastIndex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -273,7 +278,7 @@ fun HomeSettingsPage(
|
|||
onClickReset = {
|
||||
showConfirmDialog =
|
||||
ShowConfirm(R.string.overwrite_local_settings) {
|
||||
viewModel.resetToDefault()
|
||||
addRow(false) { viewModel.resetToDefault() }
|
||||
}
|
||||
},
|
||||
modifier = destModifier,
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ fun HomeSettingsRowList(
|
|||
)
|
||||
}
|
||||
item {
|
||||
TitleText(stringResource(R.string.home_rows))
|
||||
TitleText(stringResource(R.string.home_rows) + " (${state.rows.size})")
|
||||
HorizontalDivider()
|
||||
}
|
||||
itemsIndexed(state.rows, key = { _, row -> row.id }) { index, row ->
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ class HomeSettingsViewModel
|
|||
}
|
||||
|
||||
private suspend fun fetchRowData() {
|
||||
val limit = 6
|
||||
val limit = 8
|
||||
val semaphore = Semaphore(4)
|
||||
val rows =
|
||||
serverRepository.currentUserDto.value?.let { userDto ->
|
||||
|
|
@ -219,7 +219,7 @@ class HomeSettingsViewModel
|
|||
MetaRowType.NEXT_UP -> {
|
||||
HomeRowConfigDisplay(
|
||||
id = id,
|
||||
title = context.getString(R.string.continue_watching),
|
||||
title = context.getString(R.string.next_up),
|
||||
config = NextUp(),
|
||||
)
|
||||
}
|
||||
|
|
@ -356,7 +356,11 @@ class HomeSettingsViewModel
|
|||
val newRow =
|
||||
HomeRowConfigDisplay(
|
||||
id = id,
|
||||
title = context.getString(favoriteOptions[type]!!),
|
||||
title =
|
||||
context.getString(
|
||||
R.string.favorite_items,
|
||||
context.getString(favoriteOptions[type]!!),
|
||||
),
|
||||
config = HomeRowConfig.Favorite(type),
|
||||
)
|
||||
updateState {
|
||||
|
|
@ -480,6 +484,7 @@ class HomeSettingsViewModel
|
|||
result.rows.mapIndexed { index, config ->
|
||||
homeSettingsService.resolve(index, config)
|
||||
}
|
||||
idCounter = newRows.maxOfOrNull { it.id }?.plus(1) ?: 0
|
||||
_state.update {
|
||||
it.copy(rows = newRows)
|
||||
}
|
||||
|
|
@ -509,6 +514,7 @@ class HomeSettingsViewModel
|
|||
val result = homeSettingsService.parseFromWebConfig(user.id)
|
||||
if (result != null) {
|
||||
Timber.v("Got web settings")
|
||||
idCounter = result.rows.maxOfOrNull { it.id }?.plus(1) ?: 0
|
||||
_state.update {
|
||||
it.copy(rows = result.rows)
|
||||
}
|
||||
|
|
@ -593,17 +599,17 @@ class HomeSettingsViewModel
|
|||
}
|
||||
}
|
||||
|
||||
fun resetToDefault() {
|
||||
fun resetToDefault() =
|
||||
viewModelScope.launchIO {
|
||||
val userId = serverRepository.currentUser.value?.id ?: return@launchIO
|
||||
_state.update { it.copy(loading = LoadingState.Loading) }
|
||||
val result = homeSettingsService.createDefault(userId)
|
||||
idCounter = result.rows.maxOfOrNull { it.id }?.plus(1) ?: 0
|
||||
_state.update {
|
||||
it.copy(rows = result.rows)
|
||||
it.copy(rows = result.rows, rowData = emptyList())
|
||||
}
|
||||
fetchRowData()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun showSaveToast() =
|
||||
showToast(
|
||||
|
|
@ -729,9 +735,9 @@ data class HomePageSettingsState(
|
|||
val EMPTY =
|
||||
HomePageSettingsState(
|
||||
LoadingState.Pending,
|
||||
listOf(),
|
||||
listOf(),
|
||||
listOf(),
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,6 +188,7 @@
|
|||
<string name="samples">Samples</string>
|
||||
<string name="featurettes">Featurettes</string>
|
||||
<string name="shorts">Shorts</string>
|
||||
<string name="favorite_items">Favorite %s</string>
|
||||
|
||||
<plurals name="trailers">
|
||||
<item quantity="zero">Trailers</item>
|
||||
|
|
@ -505,8 +506,8 @@
|
|||
<string name="apply_all_rows">Apply to all rows</string>
|
||||
<string name="customize_home">Customize home page</string>
|
||||
<string name="home_rows">Home rows</string>
|
||||
<string name="load_from_server">Load from server</string>
|
||||
<string name="save_to_server">Save to server</string>
|
||||
<string name="load_from_server">Load from server user profile</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="use_series">Use series image</string>
|
||||
<string name="add_row_for">Add row for %1$s</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue