Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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(
Expand All @@ -801,7 +811,7 @@ class HomeSettingsService
.map { BaseItem(it, true) }
.let {
Success(
context.getString(R.string.favorites), // TODO
title,
it,
row.viewOptions,
)
Expand All @@ -822,7 +832,7 @@ class HomeSettingsService
.map { BaseItem(it, row.viewOptions.useSeries) }
.let {
Success(
context.getString(R.string.favorites), // TODO
title,
it,
row.viewOptions,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down Expand Up @@ -273,7 +278,7 @@ fun HomeSettingsPage(
onClickReset = {
showConfirmDialog =
ShowConfirm(R.string.overwrite_local_settings) {
viewModel.resetToDefault()
addRow(false) { viewModel.resetToDefault() }
}
},
modifier = destModifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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(),
)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -729,9 +735,9 @@ data class HomePageSettingsState(
val EMPTY =
HomePageSettingsState(
LoadingState.Pending,
listOf(),
listOf(),
listOf(),
emptyList(),
emptyList(),
emptyList(),
)
}
}
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
Loading