From 6d53869180c99133af935d029f990d25da4dd640 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Fri, 23 Jan 2026 11:32:55 -0500 Subject: [PATCH 01/53] WIP, basic MVP --- .../damontecres/wholphin/MainActivity.kt | 3 +- .../wholphin/data/ServerRepository.kt | 22 ++ .../wholphin/data/model/HomeRowConfig.kt | 58 +++ .../damontecres/wholphin/ui/UiConstants.kt | 3 +- .../damontecres/wholphin/ui/main/HomePage.kt | 3 +- .../ui/main/settings/HomePageRowList.kt | 155 ++++++++ .../ui/main/settings/HomePageSettings.kt | 359 ++++++++++++++++++ .../settings/HomePageSettingsDestination.kt | 17 + .../wholphin/ui/nav/Destination.kt | 3 + .../wholphin/ui/nav/DestinationContent.kt | 5 + app/src/main/res/values/strings.xml | 2 + 11 files changed, 627 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt create mode 100644 app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt create mode 100644 app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt create mode 100644 app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt diff --git a/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt b/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt index c7b12bfc34..f127944e20 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt @@ -265,7 +265,8 @@ class MainActivity : AppCompatActivity() { server = current.server, startDestination = requestedDestination - ?: Destination.Home(), + // TODO Undo + ?: Destination.HomeSettings, navigationManager = navigationManager, preferences = preferences, modifier = Modifier.fillMaxSize(), diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/ServerRepository.kt b/app/src/main/java/com/github/damontecres/wholphin/data/ServerRepository.kt index f66dcfca0c..c0cd962da8 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/ServerRepository.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/ServerRepository.kt @@ -18,6 +18,7 @@ import kotlinx.coroutines.withContext import kotlinx.serialization.Serializable import org.jellyfin.sdk.Jellyfin import org.jellyfin.sdk.api.client.ApiClient +import org.jellyfin.sdk.api.client.extensions.displayPreferencesApi import org.jellyfin.sdk.api.client.extensions.systemApi import org.jellyfin.sdk.api.client.extensions.userApi import org.jellyfin.sdk.model.api.AuthenticationResult @@ -102,6 +103,27 @@ class ServerRepository currentUserId = updatedUser.id.toServerString() }.build() } + val settings = + apiClient.displayPreferencesApi + .getDisplayPreferences( + displayPreferencesId = "settings", + userId = user.id, + client = "wholphin", + ).content + val newSettings = + settings.copy( + customPrefs = + settings.customPrefs.toMutableMap().apply { + put("test_key", "test_value") + }, + ) + apiClient.displayPreferencesApi.updateDisplayPreferences( + displayPreferencesId = "settings", + userId = user.id, + client = "wholphin", + data = newSettings, + ) + Timber.v("settings=$settings") withContext(Dispatchers.Main) { _current.value = CurrentUser(updatedServer, updatedUser) _currentUserDto.value = userDto diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt new file mode 100644 index 0000000000..c88612ccb8 --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -0,0 +1,58 @@ +@file:UseSerializers(UUIDSerializer::class) + +package com.github.damontecres.wholphin.data.model + +import com.github.damontecres.wholphin.preferences.PrefContentScale +import com.github.damontecres.wholphin.ui.AspectRatio +import com.github.damontecres.wholphin.ui.Cards +import com.github.damontecres.wholphin.ui.components.ViewOptionImageType +import kotlinx.serialization.Serializable +import kotlinx.serialization.UseSerializers +import org.jellyfin.sdk.model.serializer.UUIDSerializer +import java.util.UUID + +@Serializable +sealed class HomeRowConfig { + abstract val viewOptions: HomeRowViewOptions + + @Serializable + data class ContinueWatching( + val combined: Boolean, + override val viewOptions: HomeRowViewOptions, + ) : HomeRowConfig() + + @Serializable + data class RecentlyAdded( + val parentId: UUID, + override val viewOptions: HomeRowViewOptions, + ) : HomeRowConfig() + + @Serializable + data class RecentlyReleased( + val parentId: UUID, + override val viewOptions: HomeRowViewOptions, + ) : HomeRowConfig() + + @Serializable + data class Genres( + val genreId: UUID, + val parentId: UUID, + override val viewOptions: HomeRowViewOptions, + ) : HomeRowConfig() +} + +data class HomeRowConfigDisplay( + val title: String, + val config: HomeRowConfig, +) + +@Serializable +data class HomeRowViewOptions( + val heightDp: Int = Cards.HEIGHT_2X3_DP, + val spacing: Int = 16, + val contentScale: PrefContentScale = PrefContentScale.FIT, + val aspectRatio: AspectRatio = AspectRatio.TALL, + val imageType: ViewOptionImageType = ViewOptionImageType.PRIMARY, + val showTitles: Boolean = true, + val useSeries: Boolean = true, +) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/UiConstants.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/UiConstants.kt index 54f564f1b5..0ea92dcd5f 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/UiConstants.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/UiConstants.kt @@ -73,7 +73,8 @@ val SlimItemFields = ) object Cards { - val height2x3 = 172.dp + const val HEIGHT_2X3_DP = 172 + val height2x3 = HEIGHT_2X3_DP.dp val heightEpisode = height2x3 * .75f val playedPercentHeight = 6.dp val serverUserCircle = height2x3 * .75f diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt index 33d40a4a30..084c00d76c 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt @@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.runtime.Composable @@ -192,6 +193,7 @@ fun HomePageContent( modifier: Modifier = Modifier, onFocusPosition: ((RowColumn) -> Unit)? = null, loadingState: LoadingState? = null, + listState: LazyListState = rememberLazyListState(), ) { var position by rememberPosition() val focusedItem = @@ -199,7 +201,6 @@ fun HomePageContent( (homeRows.getOrNull(it.row) as? HomeRowLoadingState.Success)?.items?.getOrNull(it.column) } - val listState = rememberLazyListState() val rowFocusRequesters = remember(homeRows) { List(homeRows.size) { FocusRequester() } } var firstFocused by remember { mutableStateOf(false) } LaunchedEffect(homeRows) { diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt new file mode 100644 index 0000000000..b011b480a3 --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt @@ -0,0 +1,155 @@ +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 +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +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.Delete +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.focus.focusRestorer +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.MaterialTheme +import androidx.tv.material3.Text +import androidx.tv.material3.surfaceColorAtElevation +import com.github.damontecres.wholphin.R +import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay +import com.github.damontecres.wholphin.ui.FontAwesome +import com.github.damontecres.wholphin.ui.components.Button +import com.github.damontecres.wholphin.ui.ifElse + +enum class MoveDirection { + UP, + DOWN, +} + +@Composable +fun HomePageRowList( + state: HomePageSettingsState, + onClickAdd: () -> Unit, + onClickMove: (MoveDirection, Int) -> Unit, + onClickDelete: (Int) -> Unit, + modifier: Modifier, + firstFocus: FocusRequester = remember { FocusRequester() }, +) { + Column(modifier = modifier) { + LazyColumn( + contentPadding = PaddingValues(8.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + modifier = + modifier + .fillMaxHeight() + .focusRestorer(firstFocus), + ) { + itemsIndexed(state.rows) { index, row -> + HomeRowConfigContent( + config = row, + moveUpAllowed = index > 0, + moveDownAllowed = index != state.rows.lastIndex, + onClickMove = { onClickMove.invoke(it, index) }, + onClickDelete = { onClickDelete.invoke(index) }, + modifier = + Modifier + .fillMaxWidth() + .ifElse(index == 0, Modifier.focusRequester(firstFocus)), + ) + } + item { + Button( + onClick = onClickAdd, + modifier = Modifier.ifElse(state.rows.isEmpty(), Modifier.focusRequester(firstFocus)), + ) { + Text( + text = stringResource(R.string.add_row), + ) + } + } + } + } +} + +@Composable +fun HomeRowConfigContent( + config: HomeRowConfigDisplay, + moveUpAllowed: Boolean, + moveDownAllowed: Boolean, + onClickMove: (MoveDirection) -> Unit, + onClickDelete: () -> Unit, + modifier: Modifier, +) { + Box( + modifier = modifier, + ) { + Row( + horizontalArrangement = Arrangement.spacedBy(16.dp), + verticalAlignment = Alignment.CenterVertically, + modifier = + Modifier + .fillMaxWidth() + .heightIn(min = 40.dp, max = 88.dp) + .background( + color = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp), + shape = RoundedCornerShape(8.dp), + ).padding(8.dp), + ) { + Text( + text = config.title, + color = MaterialTheme.colorScheme.onSurface, + style = MaterialTheme.typography.titleMedium, + overflow = TextOverflow.Ellipsis, + modifier = Modifier.weight(1f), + ) + Row( + horizontalArrangement = Arrangement.spacedBy(4.dp), + modifier = Modifier.wrapContentWidth(), + ) { + Button( + onClick = { onClickMove.invoke(MoveDirection.UP) }, + enabled = moveUpAllowed, + ) { + Text( + text = stringResource(R.string.fa_caret_up), + fontFamily = FontAwesome, + ) + } + Button( + onClick = { onClickMove.invoke(MoveDirection.DOWN) }, + enabled = moveDownAllowed, + ) { + Text( + text = stringResource(R.string.fa_caret_down), + fontFamily = FontAwesome, + ) + } + Button( + onClick = onClickDelete, + enabled = true, + ) { + Icon( + imageVector = Icons.Default.Delete, + contentDescription = "delete", + modifier = Modifier, + ) + } + } + } + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt new file mode 100644 index 0000000000..79979638e2 --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt @@ -0,0 +1,359 @@ +package com.github.damontecres.wholphin.ui.main.settings + +import android.content.Context +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import androidx.tv.material3.MaterialTheme +import com.github.damontecres.wholphin.R +import com.github.damontecres.wholphin.data.NavDrawerItemRepository +import com.github.damontecres.wholphin.data.ServerRepository +import com.github.damontecres.wholphin.data.model.BaseItem +import com.github.damontecres.wholphin.data.model.HomeRowConfig +import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay +import com.github.damontecres.wholphin.data.model.HomeRowViewOptions +import com.github.damontecres.wholphin.services.BackdropService +import com.github.damontecres.wholphin.services.LatestNextUpService +import com.github.damontecres.wholphin.services.UserPreferencesService +import com.github.damontecres.wholphin.ui.SlimItemFields +import com.github.damontecres.wholphin.ui.launchIO +import com.github.damontecres.wholphin.ui.main.HomePageContent +import com.github.damontecres.wholphin.ui.main.LatestData +import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem +import com.github.damontecres.wholphin.util.GetGenresRequestHandler +import com.github.damontecres.wholphin.util.HomeRowLoadingState +import com.github.damontecres.wholphin.util.LoadingState +import dagger.hilt.android.lifecycle.HiltViewModel +import dagger.hilt.android.qualifiers.ApplicationContext +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.update +import org.jellyfin.sdk.api.client.ApiClient +import org.jellyfin.sdk.model.api.CollectionType +import org.jellyfin.sdk.model.api.request.GetGenresRequest +import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest +import java.util.UUID +import javax.inject.Inject + +@HiltViewModel +class HomePageSettingsViewModel + @Inject + constructor( + @param:ApplicationContext private val context: Context, + private val api: ApiClient, + private val serverRepository: ServerRepository, + private val userPreferencesService: UserPreferencesService, + private val navDrawerItemRepository: NavDrawerItemRepository, + private val backdropService: BackdropService, + private val latestNextUpService: LatestNextUpService, + ) : ViewModel() { + private val _state = MutableStateFlow(HomePageSettingsState.EMPTY) + val state: StateFlow = _state + + init { + viewModelScope.launchIO { + val navDrawerItems = + navDrawerItemRepository + .getNavDrawerItems() + val libraries = + navDrawerItems + .filter { it is ServerNavDrawerItem } + .map { + it as ServerNavDrawerItem + Library(it.itemId, it.name, it.type) + } + _state.update { it.copy(libraries = libraries) } + + // TODO get config + + // Or create default + val prefs = userPreferencesService.getCurrent().appPreferences.homePagePreferences + val includedIds = + navDrawerItemRepository + .getFilteredNavDrawerItems(navDrawerItems) + .filter { it is ServerNavDrawerItem } + .map { + val id = (it as ServerNavDrawerItem).itemId + val name = libraries.firstOrNull { it.itemId == id }?.name + val title = + name?.let { context.getString(R.string.recently_added_in, it) } + ?: context.getString(R.string.recently_added) + HomeRowConfigDisplay( + title, + HomeRowConfig.RecentlyAdded(id, HomeRowViewOptions()), + ) + } + val rowConfig = + listOf( + HomeRowConfigDisplay( + context.getString(R.string.continue_watching), + HomeRowConfig.ContinueWatching( + prefs.combineContinueNext, + HomeRowViewOptions(), + ), + ), + ) + includedIds + _state.update { + it.copy(rows = rowConfig) + } + + fetchRowData() + } + } + + fun updateBackdrop(item: BaseItem) { + viewModelScope.launchIO { + backdropService.submit(item) + } + } + + private suspend fun fetchRowData() { + val limit = 6 + val rows = + serverRepository.currentUserDto.value?.let { userDto -> + val prefs = userPreferencesService.getCurrent().appPreferences.homePagePreferences + state.value.rows + .map { it.config } + .map { row -> + // TODO parallelize + when (row) { + is HomeRowConfig.ContinueWatching -> { + val resume = latestNextUpService.getResume(userDto.id, limit, true) + val nextUp = + latestNextUpService.getNextUp( + userDto.id, + limit, + prefs.enableRewatchingNextUp, + false, + ) + val watching = + buildList { + if (row.combined) { + val items = + latestNextUpService.buildCombined(resume, nextUp) + add( + HomeRowLoadingState.Success( + title = context.getString(R.string.continue_watching), + items = items, + ), + ) + } else { + if (resume.isNotEmpty()) { + add( + HomeRowLoadingState.Success( + title = context.getString(R.string.continue_watching), + items = resume, + ), + ) + } + if (nextUp.isNotEmpty()) { + add( + HomeRowLoadingState.Success( + title = context.getString(R.string.next_up), + items = nextUp, + ), + ) + } + } + } + watching + } + + is HomeRowConfig.Genres -> { + val request = + GetGenresRequest( + parentId = row.parentId, + userId = userDto.id, + limit = limit, + ) + val items = + GetGenresRequestHandler + .execute(api, request) + .content.items + .map { BaseItem(it, false) } + val name = + _state.value.libraries + .firstOrNull { it.itemId == row.parentId } + ?.name + val title = + name?.let { context.getString(R.string.genres_in, it) } + ?: context.getString(R.string.genres) + listOf(HomeRowLoadingState.Success(title, items)) + } + + is HomeRowConfig.RecentlyAdded -> { + val name = + _state.value.libraries + .firstOrNull { it.itemId == row.parentId } + ?.name + val title = + name?.let { context.getString(R.string.recently_added_in, it) } + ?: context.getString(R.string.recently_added) + val request = + GetLatestMediaRequest( + fields = SlimItemFields, + imageTypeLimit = 1, + parentId = row.parentId, + groupItems = true, + limit = limit, + isPlayed = null, // Server will handle user's preference + ) + latestNextUpService.loadLatest(listOf(LatestData(title, request))) + } + + is HomeRowConfig.RecentlyReleased -> { + TODO() + } + } + }.flatten() + } + rows?.let { rows -> + _state.update { + it.copy(loading = LoadingState.Success, rowData = rows) + } + } + } + + private fun List.move( + direction: MoveDirection, + index: Int, + ): List = + toMutableList().apply { + if (direction == MoveDirection.DOWN) { + val down = this[index] + val up = this[index + 1] + set(index, up) + set(index + 1, down) + } else { + val up = this[index] + val down = this[index - 1] + set(index - 1, up) + set(index, down) + } + } + + fun moveRow( + direction: MoveDirection, + index: Int, + ) { + _state.update { + val rows = it.rows.move(direction, index) + // TODO would be more efficient to move rowData, but uncombined continue watching is two rows +// val rowData = it.rowData.move(direction, index) + it.copy( + loading = LoadingState.Loading, + rows = rows, + ) + } + viewModelScope.launchIO { fetchRowData() } + } + + fun deleteRow(index: Int) { + _state.update { + val rows = it.rows.toMutableList().apply { removeAt(index) } + val rowData = it.rowData.toMutableList().apply { removeAt(index) } + it.copy( + rows = rows, + rowData = rowData, + ) + } + } + } + +data class HomePageSettingsState( + val loading: LoadingState, + val rows: List, + val rowData: List, + val libraries: List, +) { + companion object { + val EMPTY = + HomePageSettingsState( + LoadingState.Pending, + listOf(), + listOf(), + listOf(), + ) + } +} + +data class Library( + val itemId: UUID, + val name: String, + val collectionType: CollectionType, +) + +val settingsWidth = 300.dp + +@Composable +fun HomePageSettings( + modifier: Modifier, + viewModel: HomePageSettingsViewModel = hiltViewModel(), +) { + val state by viewModel.state.collectAsState() + val listState = rememberLazyListState() + var destination by remember { mutableStateOf(HomePageSettingsDestination.RowList) } + Row( + horizontalArrangement = Arrangement.spacedBy(8.dp), + modifier = modifier, + ) { + HomePageContent( + loadingState = state.loading, + homeRows = state.rowData, + onClickItem = { _, _ -> }, + onLongClickItem = { _, _ -> }, + onClickPlay = { _, _ -> }, + showClock = false, + onUpdateBackdrop = viewModel::updateBackdrop, + listState = listState, + modifier = Modifier.fillMaxHeight().weight(1f), + ) + Box( + modifier = + Modifier + .width(settingsWidth) + .fillMaxHeight() + .background(color = MaterialTheme.colorScheme.surface), + ) { + when (destination) { + HomePageSettingsDestination.RowList -> { + HomePageRowList( + state = state, + onClickAdd = { destination = HomePageSettingsDestination.ChooseLibrary }, + onClickMove = viewModel::moveRow, + onClickDelete = viewModel::deleteRow, + modifier = Modifier.fillMaxSize(), + ) + } + + is HomePageSettingsDestination.ChooseLibrary -> { + TODO() + } + + is HomePageSettingsDestination.ChooseRow -> { + TODO() + } + + is HomePageSettingsDestination.RowSettings -> { + TODO() + } + } + } + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt new file mode 100644 index 0000000000..3ebdc1663f --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt @@ -0,0 +1,17 @@ +package com.github.damontecres.wholphin.ui.main.settings + +import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay + +sealed interface HomePageSettingsDestination { + data object RowList : HomePageSettingsDestination + + data object ChooseLibrary : HomePageSettingsDestination + + data class ChooseRow( + val library: Library, + ) : HomePageSettingsDestination + + data class RowSettings( + val row: HomeRowConfigDisplay, + ) : HomePageSettingsDestination +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/nav/Destination.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/nav/Destination.kt index 426d5328f0..d00416cf2b 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/nav/Destination.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/nav/Destination.kt @@ -33,6 +33,9 @@ sealed class Destination( val id: Long = 0L, ) : Destination() + @Serializable + data object HomeSettings : Destination(true) + @Serializable data class Settings( val screen: PreferenceScreenOption, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/nav/DestinationContent.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/nav/DestinationContent.kt index 43b8841d90..b4ef4575a1 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/nav/DestinationContent.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/nav/DestinationContent.kt @@ -32,6 +32,7 @@ import com.github.damontecres.wholphin.ui.detail.series.SeriesOverview import com.github.damontecres.wholphin.ui.discover.DiscoverPage import com.github.damontecres.wholphin.ui.main.HomePage import com.github.damontecres.wholphin.ui.main.SearchPage +import com.github.damontecres.wholphin.ui.main.settings.HomePageSettings import com.github.damontecres.wholphin.ui.playback.PlaybackPage import com.github.damontecres.wholphin.ui.preferences.PreferencesPage import com.github.damontecres.wholphin.ui.setup.InstallUpdatePage @@ -60,6 +61,10 @@ fun DestinationContent( ) } + is Destination.HomeSettings -> { + HomePageSettings(modifier) + } + is Destination.PlaybackList, is Destination.Playback, -> { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c83a3b636b..8fa26d53bc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -462,6 +462,8 @@ Request in 4K AV1 software decoding MPV is now the default player except for HDR.\nYou can change this in settings. + Add row + Genres in %1$s Disabled From 5dcdde36c30fcf4068ade5914cb6e252eff449d7 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Fri, 23 Jan 2026 12:06:07 -0500 Subject: [PATCH 02/53] Handle adding rows & back handling --- .../wholphin/data/model/HomeRowConfig.kt | 6 +- .../ui/main/settings/HomePageLibraryList.kt | 54 ++++++++ .../settings/HomePageLibraryRowTypeList.kt | 71 ++++++++++ .../ui/main/settings/HomePageRowList.kt | 16 ++- .../ui/main/settings/HomePageSettings.kt | 131 +++++++++++++++--- .../settings/HomePageSettingsDestination.kt | 2 +- app/src/main/res/values/strings.xml | 1 + 7 files changed, 256 insertions(+), 25 deletions(-) create mode 100644 app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryList.kt create mode 100644 app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryRowTypeList.kt diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index c88612ccb8..00dfd1aac7 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -13,29 +13,33 @@ import java.util.UUID @Serializable sealed class HomeRowConfig { + abstract val id: UUID abstract val viewOptions: HomeRowViewOptions @Serializable data class ContinueWatching( + override val id: UUID, val combined: Boolean, override val viewOptions: HomeRowViewOptions, ) : HomeRowConfig() @Serializable data class RecentlyAdded( + override val id: UUID, val parentId: UUID, override val viewOptions: HomeRowViewOptions, ) : HomeRowConfig() @Serializable data class RecentlyReleased( + override val id: UUID, val parentId: UUID, override val viewOptions: HomeRowViewOptions, ) : HomeRowConfig() @Serializable data class Genres( - val genreId: UUID, + override val id: UUID, val parentId: UUID, override val viewOptions: HomeRowViewOptions, ) : HomeRowConfig() diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryList.kt new file mode 100644 index 0000000000..73276da673 --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryList.kt @@ -0,0 +1,54 @@ +package com.github.damontecres.wholphin.ui.main.settings + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.itemsIndexed +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.focus.focusRestorer +import androidx.compose.ui.unit.dp +import androidx.tv.material3.ListItem +import androidx.tv.material3.Text +import com.github.damontecres.wholphin.ui.ifElse +import com.github.damontecres.wholphin.ui.tryRequestFocus + +@Composable +fun HomePageLibraryList( + libraries: List, + onClick: (Library) -> Unit, + modifier: Modifier, + firstFocus: FocusRequester = remember { FocusRequester() }, +) { + LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } + Column(modifier = modifier) { + Text( + text = "Add row for...", + ) + LazyColumn( + contentPadding = PaddingValues(8.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + modifier = + modifier + .fillMaxHeight() + .focusRestorer(firstFocus), + ) { + itemsIndexed(libraries) { index, library -> + ListItem( + selected = false, + headlineContent = { + Text(library.name) + }, + onClick = { onClick.invoke(library) }, + modifier = Modifier.ifElse(index == 0, Modifier.focusRequester(firstFocus)), + ) + } + } + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryRowTypeList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryRowTypeList.kt new file mode 100644 index 0000000000..0206d46a63 --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryRowTypeList.kt @@ -0,0 +1,71 @@ +package com.github.damontecres.wholphin.ui.main.settings + +import androidx.annotation.StringRes +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.itemsIndexed +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +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 +import com.github.damontecres.wholphin.ui.tryRequestFocus + +@Composable +fun HomePageLibraryRowTypeList( + library: Library, + onClick: (LibraryRowType) -> Unit, + modifier: Modifier, + firstFocus: FocusRequester = remember { FocusRequester() }, +) { + LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } + Column(modifier = modifier) { + Text( + text = "Add row for ${library.name}", + ) + LazyColumn( + contentPadding = PaddingValues(8.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + modifier = + modifier + .fillMaxHeight() + .focusRestorer(firstFocus), + ) { + itemsIndexed(LibraryRowType.entries) { index, rowType -> + ListItem( + selected = false, + headlineContent = { + Text( + text = stringResource(rowType.stringId), + ) + }, + onClick = { onClick.invoke(rowType) }, + modifier = + Modifier + .fillMaxWidth() + .ifElse(index == 0, Modifier.focusRequester(firstFocus)), + ) + } + } + } +} + +enum class LibraryRowType( + @param:StringRes val stringId: Int, +) { + RECENTLY_ADDED(R.string.recently_added), + RECENTLY_RELEASED(R.string.recently_released), + GENRES(R.string.genres), +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt index b011b480a3..81342db9e0 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt @@ -4,7 +4,6 @@ import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth @@ -31,6 +30,7 @@ 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.data.model.HomeRowConfig import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay import com.github.damontecres.wholphin.ui.FontAwesome import com.github.damontecres.wholphin.ui.components.Button @@ -52,18 +52,18 @@ fun HomePageRowList( ) { Column(modifier = modifier) { LazyColumn( - contentPadding = PaddingValues(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp), modifier = modifier .fillMaxHeight() .focusRestorer(firstFocus), ) { - itemsIndexed(state.rows) { index, row -> + itemsIndexed(state.rows, key = { _, row -> row.config.id }) { index, row -> HomeRowConfigContent( config = row, moveUpAllowed = index > 0, moveDownAllowed = index != state.rows.lastIndex, + deleteAllowed = row.config !is HomeRowConfig.ContinueWatching, onClickMove = { onClickMove.invoke(it, index) }, onClickDelete = { onClickDelete.invoke(index) }, modifier = @@ -91,6 +91,7 @@ fun HomeRowConfigContent( config: HomeRowConfigDisplay, moveUpAllowed: Boolean, moveDownAllowed: Boolean, + deleteAllowed: Boolean, onClickMove: (MoveDirection) -> Unit, onClickDelete: () -> Unit, modifier: Modifier, @@ -108,14 +109,17 @@ fun HomeRowConfigContent( .background( color = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp), shape = RoundedCornerShape(8.dp), - ).padding(8.dp), + ), ) { Text( text = config.title, color = MaterialTheme.colorScheme.onSurface, style = MaterialTheme.typography.titleMedium, overflow = TextOverflow.Ellipsis, - modifier = Modifier.weight(1f), + modifier = + Modifier + .weight(1f) + .padding(start = 4.dp), ) Row( horizontalArrangement = Arrangement.spacedBy(4.dp), @@ -141,7 +145,7 @@ fun HomeRowConfigContent( } Button( onClick = onClickDelete, - enabled = true, + enabled = deleteAllowed, ) { Icon( imageVector = Icons.Default.Delete, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt index 79979638e2..0070bd2dc1 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt @@ -1,15 +1,18 @@ package com.github.damontecres.wholphin.ui.main.settings import android.content.Context +import androidx.activity.compose.BackHandler import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.runtime.Composable +import androidx.compose.runtime.Immutable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -96,7 +99,11 @@ class HomePageSettingsViewModel ?: context.getString(R.string.recently_added) HomeRowConfigDisplay( title, - HomeRowConfig.RecentlyAdded(id, HomeRowViewOptions()), + HomeRowConfig.RecentlyAdded( + UUID.randomUUID(), + id, + HomeRowViewOptions(), + ), ) } val rowConfig = @@ -104,6 +111,7 @@ class HomePageSettingsViewModel HomeRowConfigDisplay( context.getString(R.string.continue_watching), HomeRowConfig.ContinueWatching( + UUID.randomUUID(), prefs.combineContinueNext, HomeRowViewOptions(), ), @@ -274,6 +282,66 @@ class HomePageSettingsViewModel ) } } + + fun addRow( + library: Library, + rowType: LibraryRowType, + ) { + viewModelScope.launchIO { + val newRow = + when (rowType) { + LibraryRowType.RECENTLY_ADDED -> { + val title = + library.name.let { context.getString(R.string.recently_added_in, it) } + HomeRowConfigDisplay( + title, + HomeRowConfig.RecentlyAdded( + UUID.randomUUID(), + library.itemId, + HomeRowViewOptions(), + ), + ) + } + + LibraryRowType.RECENTLY_RELEASED -> { + val title = + library.name.let { + context.getString( + R.string.recently_released_in, + it, + ) + } + HomeRowConfigDisplay( + title, + HomeRowConfig.RecentlyReleased( + UUID.randomUUID(), + library.itemId, + HomeRowViewOptions(), + ), + ) + } + + LibraryRowType.GENRES -> { + val title = library.name.let { context.getString(R.string.genres_in, it) } + HomeRowConfigDisplay( + title, + HomeRowConfig.Genres( + UUID.randomUUID(), + library.itemId, + HomeRowViewOptions(), + ), + ) + } + } + _state.update { + it.copy( + loading = LoadingState.Loading, + rows = it.rows.toMutableList().apply { add(newRow) }, + ) + } + fetchRowData() + } + } } data class HomePageSettingsState( @@ -293,6 +361,7 @@ data class HomePageSettingsState( } } +@Immutable data class Library( val itemId: UUID, val name: String, @@ -309,21 +378,20 @@ fun HomePageSettings( val state by viewModel.state.collectAsState() val listState = rememberLazyListState() var destination by remember { mutableStateOf(HomePageSettingsDestination.RowList) } + + BackHandler(destination is HomePageSettingsDestination.ChooseRowType) { + destination = HomePageSettingsDestination.ChooseLibrary + } + BackHandler(destination is HomePageSettingsDestination.ChooseLibrary) { + destination = HomePageSettingsDestination.RowList + } + BackHandler(destination is HomePageSettingsDestination.RowSettings) { + destination = HomePageSettingsDestination.RowList + } Row( horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = modifier, ) { - HomePageContent( - loadingState = state.loading, - homeRows = state.rowData, - onClickItem = { _, _ -> }, - onLongClickItem = { _, _ -> }, - onClickPlay = { _, _ -> }, - showClock = false, - onUpdateBackdrop = viewModel::updateBackdrop, - listState = listState, - modifier = Modifier.fillMaxHeight().weight(1f), - ) Box( modifier = Modifier @@ -331,23 +399,38 @@ fun HomePageSettings( .fillMaxHeight() .background(color = MaterialTheme.colorScheme.surface), ) { - when (destination) { + val destModifier = + Modifier + .fillMaxSize() + .padding(4.dp) + when (val dest = destination) { HomePageSettingsDestination.RowList -> { HomePageRowList( state = state, onClickAdd = { destination = HomePageSettingsDestination.ChooseLibrary }, onClickMove = viewModel::moveRow, onClickDelete = viewModel::deleteRow, - modifier = Modifier.fillMaxSize(), + modifier = destModifier, ) } is HomePageSettingsDestination.ChooseLibrary -> { - TODO() + HomePageLibraryList( + libraries = state.libraries, + onClick = { destination = HomePageSettingsDestination.ChooseRowType(it) }, + modifier = destModifier, + ) } - is HomePageSettingsDestination.ChooseRow -> { - TODO() + is HomePageSettingsDestination.ChooseRowType -> { + HomePageLibraryRowTypeList( + library = dest.library, + onClick = { + viewModel.addRow(dest.library, it) + destination = HomePageSettingsDestination.RowList + }, + modifier = destModifier, + ) } is HomePageSettingsDestination.RowSettings -> { @@ -355,5 +438,19 @@ fun HomePageSettings( } } } + HomePageContent( + loadingState = state.loading, + homeRows = state.rowData, + onClickItem = { _, _ -> }, + onLongClickItem = { _, _ -> }, + onClickPlay = { _, _ -> }, + showClock = false, + onUpdateBackdrop = viewModel::updateBackdrop, + listState = listState, + modifier = + Modifier + .fillMaxHeight() + .weight(1f), + ) } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt index 3ebdc1663f..51d7a8e8e9 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt @@ -7,7 +7,7 @@ sealed interface HomePageSettingsDestination { data object ChooseLibrary : HomePageSettingsDestination - data class ChooseRow( + data class ChooseRowType( val library: Library, ) : HomePageSettingsDestination diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8fa26d53bc..e9629e193a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -464,6 +464,7 @@ MPV is now the default player except for HDR.\nYou can change this in settings. Add row Genres in %1$s + Recently released in %1$s Disabled From 1ce380f3b59533b3d3c7864799fb0cb1bed53b46 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Fri, 23 Jan 2026 12:44:20 -0500 Subject: [PATCH 03/53] Apply view options to preview --- .../wholphin/data/model/HomeRowConfig.kt | 123 +++++++++++++++++- .../wholphin/ui/cards/BannerCard.kt | 8 +- .../damontecres/wholphin/ui/main/HomePage.kt | 10 +- .../ui/main/settings/HomePageRowList.kt | 26 ++-- .../ui/main/settings/HomePageRowSettings.kt | 56 ++++++++ .../ui/main/settings/HomePageSettings.kt | 71 +++++++++- .../settings/HomePageSettingsDestination.kt | 4 +- .../damontecres/wholphin/util/LoadingState.kt | 2 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 275 insertions(+), 26 deletions(-) create mode 100644 app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowSettings.kt diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index 00dfd1aac7..e15df65e1d 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -2,10 +2,16 @@ package com.github.damontecres.wholphin.data.model +import com.github.damontecres.wholphin.R +import com.github.damontecres.wholphin.preferences.AppChoicePreference +import com.github.damontecres.wholphin.preferences.AppClickablePreference +import com.github.damontecres.wholphin.preferences.AppSliderPreference +import com.github.damontecres.wholphin.preferences.AppSwitchPreference import com.github.damontecres.wholphin.preferences.PrefContentScale import com.github.damontecres.wholphin.ui.AspectRatio import com.github.damontecres.wholphin.ui.Cards import com.github.damontecres.wholphin.ui.components.ViewOptionImageType +import com.github.damontecres.wholphin.ui.components.ViewOptions import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers import org.jellyfin.sdk.model.serializer.UUIDSerializer @@ -16,33 +22,43 @@ sealed class HomeRowConfig { abstract val id: UUID abstract val viewOptions: HomeRowViewOptions + abstract fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig + @Serializable data class ContinueWatching( override val id: UUID, val combined: Boolean, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() + ) : HomeRowConfig() { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + } @Serializable data class RecentlyAdded( override val id: UUID, val parentId: UUID, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() + ) : HomeRowConfig() { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + } @Serializable data class RecentlyReleased( override val id: UUID, val parentId: UUID, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() + ) : HomeRowConfig() { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + } @Serializable data class Genres( override val id: UUID, val parentId: UUID, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() + ) : HomeRowConfig() { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + } } data class HomeRowConfigDisplay( @@ -59,4 +75,101 @@ data class HomeRowViewOptions( val imageType: ViewOptionImageType = ViewOptionImageType.PRIMARY, val showTitles: Boolean = true, val useSeries: Boolean = true, -) +) { + companion object { + val ViewOptionsColumns = + AppSliderPreference( + title = R.string.height, + defaultValue = Cards.HEIGHT_2X3_DP.toLong(), + min = Cards.HEIGHT_2X3_DP / 2L, + max = Cards.HEIGHT_2X3_DP + 64L, + interval = 4, + getter = { it.heightDp.toLong() }, + setter = { prefs, value -> prefs.copy(heightDp = value.toInt()) }, + ) + val ViewOptionsSpacing = + AppSliderPreference( + title = R.string.spacing, + defaultValue = 16, + min = 0, + max = 32, + interval = 2, + getter = { it.spacing.toLong() }, + setter = { prefs, value -> prefs.copy(spacing = value.toInt()) }, + ) + + val ViewOptionsContentScale = + AppChoicePreference( + title = R.string.global_content_scale, + defaultValue = PrefContentScale.FIT, + displayValues = R.array.content_scale, + getter = { it.contentScale }, + setter = { viewOptions, value -> viewOptions.copy(contentScale = value) }, + indexToValue = { PrefContentScale.forNumber(it) }, + valueToIndex = { it.number }, + ) + + val ViewOptionsAspectRatio = + AppChoicePreference( + title = R.string.aspect_ratio, + defaultValue = AspectRatio.TALL, + displayValues = R.array.aspect_ratios, + getter = { it.aspectRatio }, + setter = { viewOptions, value -> viewOptions.copy(aspectRatio = value) }, + indexToValue = { AspectRatio.entries[it] }, + valueToIndex = { it.ordinal }, + ) + + val ViewOptionsShowTitles = + AppSwitchPreference( + title = R.string.show_titles, + defaultValue = true, + getter = { it.showTitles }, + setter = { vo, value -> vo.copy(showTitles = value) }, + ) + + val ViewOptionsUseSeries = + AppSwitchPreference( + title = R.string.go_to_series, // TODO + defaultValue = true, + getter = { it.useSeries }, + setter = { vo, value -> vo.copy(useSeries = value) }, + ) + + val ViewOptionsImageType = + AppChoicePreference( + title = R.string.image_type, + defaultValue = ViewOptionImageType.PRIMARY, + displayValues = R.array.image_types, + getter = { it.imageType }, + setter = { viewOptions, value -> + val aspectRatio = + when (value) { + ViewOptionImageType.PRIMARY -> AspectRatio.TALL + ViewOptionImageType.THUMB -> AspectRatio.WIDE + } + viewOptions.copy(imageType = value, aspectRatio = aspectRatio) + }, + indexToValue = { ViewOptionImageType.entries[it] }, + valueToIndex = { it.ordinal }, + ) + + val ViewOptionsReset = + AppClickablePreference( + title = R.string.reset, + ) + + val OPTIONS = + listOf( + ViewOptionsImageType, + ViewOptionsAspectRatio, + // TODO +// ViewOptionsShowTitles, +// ViewOptionsUseSeries, + ViewOptionsColumns, + ViewOptionsSpacing, + ViewOptionsContentScale, + ViewOptionsReset, + ) + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/cards/BannerCard.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/cards/BannerCard.kt index 70de419b8b..1c75cc6fa4 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/cards/BannerCard.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/cards/BannerCard.kt @@ -60,6 +60,8 @@ fun BannerCard( cardHeight: Dp = 120.dp, aspectRatio: Float = AspectRatios.WIDE, interactionSource: MutableInteractionSource? = null, + imageType: ImageType = ImageType.PRIMARY, + imageContentScale: ContentScale = ContentScale.FillBounds, ) { val imageUrlService = LocalImageUrlService.current val density = LocalDensity.current @@ -74,11 +76,11 @@ fun BannerCard( } } val imageUrl = - remember(item, fillHeight) { + remember(item, fillHeight, imageType) { if (item != null) { imageUrlService.getItemImageUrl( item, - ImageType.PRIMARY, + imageType, fillWidth = null, fillHeight = fillHeight, ) @@ -107,7 +109,7 @@ fun BannerCard( AsyncImage( model = imageUrl, contentDescription = null, - contentScale = ContentScale.FillBounds, + contentScale = imageContentScale, onError = { imageError = true }, modifier = Modifier.fillMaxSize(), ) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt index 084c00d76c..88b2fd2744 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt @@ -46,7 +46,6 @@ import androidx.tv.material3.Text import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.model.BaseItem import com.github.damontecres.wholphin.preferences.UserPreferences -import com.github.damontecres.wholphin.ui.AspectRatios import com.github.damontecres.wholphin.ui.Cards import com.github.damontecres.wholphin.ui.cards.BannerCard import com.github.damontecres.wholphin.ui.cards.ItemRow @@ -67,6 +66,7 @@ import com.github.damontecres.wholphin.ui.isNotNullOrBlank import com.github.damontecres.wholphin.ui.nav.Destination import com.github.damontecres.wholphin.ui.playback.isPlayKeyUp import com.github.damontecres.wholphin.ui.playback.playable +import com.github.damontecres.wholphin.ui.playback.scale import com.github.damontecres.wholphin.ui.rememberPosition import com.github.damontecres.wholphin.ui.tryRequestFocus import com.github.damontecres.wholphin.util.HomeRowLoadingState @@ -308,6 +308,7 @@ fun HomePageContent( is HomeRowLoadingState.Success -> { if (row.items.isNotEmpty()) { + val viewOptions = row.viewOptions ItemRow( title = row.title, items = row.items, @@ -323,11 +324,14 @@ fun HomePageContent( .focusGroup() .focusRequester(rowFocusRequesters[rowIndex]) .animateItem(), + horizontalPadding = viewOptions.spacing.dp, cardContent = { index, item, cardModifier, onClick, onLongClick -> BannerCard( name = item?.data?.seriesName ?: item?.name, item = item, - aspectRatio = AspectRatios.TALL, + aspectRatio = viewOptions.aspectRatio.ratio, + imageType = viewOptions.imageType.imageType, + imageContentScale = viewOptions.contentScale.scale, cornerText = item?.ui?.episdodeUnplayedCornerText, played = item?.data?.userData?.played ?: false, favorite = item?.favorite ?: false, @@ -366,7 +370,7 @@ fun HomePageContent( return@onKeyEvent false }, interactionSource = null, - cardHeight = Cards.height2x3, + cardHeight = viewOptions.heightDp.dp, ) }, ) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt index 81342db9e0..c5c10d3ea6 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt @@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.heightIn -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed @@ -26,6 +25,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 @@ -44,6 +44,7 @@ enum class MoveDirection { @Composable fun HomePageRowList( state: HomePageSettingsState, + onClick: (Int, HomeRowConfigDisplay) -> Unit, onClickAdd: () -> Unit, onClickMove: (MoveDirection, Int) -> Unit, onClickDelete: (Int) -> Unit, @@ -66,6 +67,7 @@ fun HomePageRowList( deleteAllowed = row.config !is HomeRowConfig.ContinueWatching, onClickMove = { onClickMove.invoke(it, index) }, onClickDelete = { onClickDelete.invoke(index) }, + onClick = { onClick.invoke(index, row) }, modifier = Modifier .fillMaxWidth() @@ -92,6 +94,7 @@ fun HomeRowConfigContent( moveUpAllowed: Boolean, moveDownAllowed: Boolean, deleteAllowed: Boolean, + onClick: () -> Unit, onClickMove: (MoveDirection) -> Unit, onClickDelete: () -> Unit, modifier: Modifier, @@ -111,15 +114,18 @@ fun HomeRowConfigContent( shape = RoundedCornerShape(8.dp), ), ) { - Text( - text = config.title, - color = MaterialTheme.colorScheme.onSurface, - style = MaterialTheme.typography.titleMedium, - overflow = TextOverflow.Ellipsis, - modifier = - Modifier - .weight(1f) - .padding(start = 4.dp), + ListItem( + selected = false, + headlineContent = { + Text( + text = config.title, + overflow = TextOverflow.Ellipsis, + modifier = + Modifier, + ) + }, + onClick = onClick, + modifier = Modifier.weight(1f), ) Row( horizontalArrangement = Arrangement.spacedBy(4.dp), diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowSettings.kt new file mode 100644 index 0000000000..7b605ebda6 --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowSettings.kt @@ -0,0 +1,56 @@ +package com.github.damontecres.wholphin.ui.main.settings + +import androidx.compose.foundation.background +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.tv.material3.MaterialTheme +import androidx.tv.material3.Text +import androidx.tv.material3.surfaceColorAtElevation +import com.github.damontecres.wholphin.data.model.HomeRowViewOptions +import com.github.damontecres.wholphin.preferences.AppPreference +import com.github.damontecres.wholphin.ui.preferences.ComposablePreference + +@Composable +fun HomePageRowSettings( + title: String, + viewOptions: HomeRowViewOptions, + onViewOptionsChange: (HomeRowViewOptions) -> Unit, + modifier: Modifier = Modifier, + defaultViewOptions: HomeRowViewOptions = HomeRowViewOptions(), +) { + Column(modifier = modifier) { + Text( + text = title, + style = MaterialTheme.typography.titleLarge, + color = MaterialTheme.colorScheme.onSurface, + ) + LazyColumn { + items(HomeRowViewOptions.OPTIONS) { pref -> + pref as AppPreference + val interactionSource = remember { MutableInteractionSource() } + val value = pref.getter.invoke(viewOptions) + ComposablePreference( + preference = pref, + value = value, + onNavigate = {}, + onValueChange = { newValue -> + onViewOptionsChange.invoke(pref.setter(viewOptions, newValue)) + }, + interactionSource = interactionSource, + onClickPreference = { pref -> + if (pref == HomeRowViewOptions.ViewOptionsReset) { + onViewOptionsChange.invoke(defaultViewOptions) + } + }, + modifier = Modifier.background(MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)), + ) + } + } + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt index 0070bd2dc1..fba9c5db83 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt @@ -159,6 +159,7 @@ class HomePageSettingsViewModel HomeRowLoadingState.Success( title = context.getString(R.string.continue_watching), items = items, + viewOptions = row.viewOptions, ), ) } else { @@ -167,6 +168,7 @@ class HomePageSettingsViewModel HomeRowLoadingState.Success( title = context.getString(R.string.continue_watching), items = resume, + viewOptions = row.viewOptions, ), ) } @@ -175,6 +177,7 @@ class HomePageSettingsViewModel HomeRowLoadingState.Success( title = context.getString(R.string.next_up), items = nextUp, + viewOptions = row.viewOptions, ), ) } @@ -202,7 +205,13 @@ class HomePageSettingsViewModel val title = name?.let { context.getString(R.string.genres_in, it) } ?: context.getString(R.string.genres) - listOf(HomeRowLoadingState.Success(title, items)) + listOf( + HomeRowLoadingState.Success( + title, + items, + viewOptions = row.viewOptions, + ), + ) } is HomeRowConfig.RecentlyAdded -> { @@ -222,7 +231,17 @@ class HomePageSettingsViewModel limit = limit, isPlayed = null, // Server will handle user's preference ) - latestNextUpService.loadLatest(listOf(LatestData(title, request))) + latestNextUpService + .loadLatest(listOf(LatestData(title, request))) + .let { + it.map { + if (it is HomeRowLoadingState.Success) { + it.copy(viewOptions = row.viewOptions) + } else { + it + } + } + } } is HomeRowConfig.RecentlyReleased -> { @@ -342,6 +361,39 @@ class HomePageSettingsViewModel fetchRowData() } } + + fun updateViewOptions( + rowId: UUID, + viewOptions: HomeRowViewOptions, + ) { + viewModelScope.launchIO { + _state.update { + val index = state.value.rows.indexOfFirst { it.config.id == rowId } + val newRowConfig = + state.value.rows[index] + .config + .updateViewOptions(viewOptions) + val newRow = state.value.rows[index].copy(config = newRowConfig) + it.copy( + rows = + it.rows.toMutableList().apply { + set(index, newRow) + }, + rowData = + it.rowData.toMutableList().apply { + val row = it.rowData[index] + val newRow = + if (row is HomeRowLoadingState.Success) { + row.copy(viewOptions = viewOptions) + } else { + row + } + set(index, newRow) + }, + ) + } + } + } } data class HomePageSettingsState( @@ -410,6 +462,9 @@ fun HomePageSettings( onClickAdd = { destination = HomePageSettingsDestination.ChooseLibrary }, onClickMove = viewModel::moveRow, onClickDelete = viewModel::deleteRow, + onClick = { index, row -> + destination = HomePageSettingsDestination.RowSettings(row.config.id) + }, modifier = destModifier, ) } @@ -434,7 +489,17 @@ fun HomePageSettings( } is HomePageSettingsDestination.RowSettings -> { - TODO() + val row = + state.rows + .first { it.config.id == dest.rowId } + HomePageRowSettings( + title = row.title, + viewOptions = row.config.viewOptions, + onViewOptionsChange = { + viewModel.updateViewOptions(dest.rowId, it) + }, + modifier = destModifier, + ) } } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt index 51d7a8e8e9..f6c21219d2 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt @@ -1,6 +1,6 @@ package com.github.damontecres.wholphin.ui.main.settings -import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay +import java.util.UUID sealed interface HomePageSettingsDestination { data object RowList : HomePageSettingsDestination @@ -12,6 +12,6 @@ sealed interface HomePageSettingsDestination { ) : HomePageSettingsDestination data class RowSettings( - val row: HomeRowConfigDisplay, + val rowId: UUID, ) : HomePageSettingsDestination } diff --git a/app/src/main/java/com/github/damontecres/wholphin/util/LoadingState.kt b/app/src/main/java/com/github/damontecres/wholphin/util/LoadingState.kt index c35e951287..50e42889b5 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/util/LoadingState.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/util/LoadingState.kt @@ -1,6 +1,7 @@ package com.github.damontecres.wholphin.util import com.github.damontecres.wholphin.data.model.BaseItem +import com.github.damontecres.wholphin.data.model.HomeRowViewOptions /** * Generic state for loading something from the API @@ -59,6 +60,7 @@ sealed interface HomeRowLoadingState { data class Success( override val title: String, val items: List, + val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) : HomeRowLoadingState data class Error( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e9629e193a..e3663513bf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -465,6 +465,7 @@ Add row Genres in %1$s Recently released in %1$s + Height Disabled From 71ddb59ac3e948d654a938bd36411796bde3ef49 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Fri, 23 Jan 2026 17:05:39 -0500 Subject: [PATCH 04/53] Add apply all button --- .../wholphin/data/model/HomeRowConfig.kt | 8 +++++++- .../ui/main/settings/HomePageRowSettings.kt | 3 +++ .../ui/main/settings/HomePageSettings.kt | 18 ++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index e15df65e1d..6b0fee4f0b 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -81,7 +81,7 @@ data class HomeRowViewOptions( AppSliderPreference( title = R.string.height, defaultValue = Cards.HEIGHT_2X3_DP.toLong(), - min = Cards.HEIGHT_2X3_DP / 2L, + min = 64L, max = Cards.HEIGHT_2X3_DP + 64L, interval = 4, getter = { it.heightDp.toLong() }, @@ -154,6 +154,11 @@ data class HomeRowViewOptions( valueToIndex = { it.ordinal }, ) + val ViewOptionsApplyAll = + AppClickablePreference( + title = R.string.apply_all_rows, + ) + val ViewOptionsReset = AppClickablePreference( title = R.string.reset, @@ -169,6 +174,7 @@ data class HomeRowViewOptions( ViewOptionsColumns, ViewOptionsSpacing, ViewOptionsContentScale, + ViewOptionsApplyAll, ViewOptionsReset, ) } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowSettings.kt index 7b605ebda6..f8b2a1e68b 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowSettings.kt @@ -21,6 +21,7 @@ fun HomePageRowSettings( title: String, viewOptions: HomeRowViewOptions, onViewOptionsChange: (HomeRowViewOptions) -> Unit, + onApplyApplyAll: () -> Unit, modifier: Modifier = Modifier, defaultViewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) { @@ -46,6 +47,8 @@ fun HomePageRowSettings( onClickPreference = { pref -> if (pref == HomeRowViewOptions.ViewOptionsReset) { onViewOptionsChange.invoke(defaultViewOptions) + } else if (pref == HomeRowViewOptions.ViewOptionsApplyAll) { + onApplyApplyAll.invoke() } }, modifier = Modifier.background(MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)), diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt index fba9c5db83..9372d5479a 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt @@ -394,6 +394,21 @@ class HomePageSettingsViewModel } } } + + fun updateViewOptionsForAll(viewOptions: HomeRowViewOptions) { + _state.update { + it.copy( + rowData = + it.rowData.toMutableList().map { row -> + if (row is HomeRowLoadingState.Success) { + row.copy(viewOptions = viewOptions) + } else { + row + } + }, + ) + } + } } data class HomePageSettingsState( @@ -498,6 +513,9 @@ fun HomePageSettings( onViewOptionsChange = { viewModel.updateViewOptions(dest.rowId, it) }, + onApplyApplyAll = { + viewModel.updateViewOptionsForAll(row.config.viewOptions) + }, modifier = destModifier, ) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e3663513bf..f0f23aaac4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -466,6 +466,7 @@ Genres in %1$s Recently released in %1$s Height + Apply to all rows Disabled From 2c6e7a57f0204d2ce85ae86c84702a959b1e80bf Mon Sep 17 00:00:00 2001 From: Damontecres Date: Fri, 23 Jan 2026 18:18:54 -0500 Subject: [PATCH 05/53] Use typed HomeRow in HomeRowLoadingState.Success --- .../ui/components/RecommendedContent.kt | 12 +- .../damontecres/wholphin/ui/main/HomePage.kt | 214 +++++++++++------- .../damontecres/wholphin/util/LoadingState.kt | 29 ++- 3 files changed, 176 insertions(+), 79 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedContent.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedContent.kt index 869a454d9c..44dffeec97 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedContent.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedContent.kt @@ -34,6 +34,7 @@ import com.github.damontecres.wholphin.ui.launchIO import com.github.damontecres.wholphin.ui.main.HomePageContent import com.github.damontecres.wholphin.ui.nav.Destination import com.github.damontecres.wholphin.util.ApiRequestPager +import com.github.damontecres.wholphin.util.HomeRow import com.github.damontecres.wholphin.util.HomeRowLoadingState import com.github.damontecres.wholphin.util.LoadingState import kotlinx.coroutines.Dispatchers @@ -61,7 +62,16 @@ abstract class RecommendedViewModel( viewModelScope.launchIO { val row = rows.value.getOrNull(position.row) if (row is HomeRowLoadingState.Success) { - (row.items as? ApiRequestPager<*>)?.refreshItem(position.column, itemId) + when (row.data) { + is HomeRow.BaseItemHomeRow -> { + (row.data.items as? ApiRequestPager<*>)?.refreshItem( + position.column, + itemId, + ) + } + + is HomeRow.GenreHowRow -> {} + } } } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt index 88b2fd2744..092b2f8078 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt @@ -54,6 +54,7 @@ import com.github.damontecres.wholphin.ui.components.DialogParams import com.github.damontecres.wholphin.ui.components.DialogPopup import com.github.damontecres.wholphin.ui.components.EpisodeName import com.github.damontecres.wholphin.ui.components.ErrorMessage +import com.github.damontecres.wholphin.ui.components.Genre import com.github.damontecres.wholphin.ui.components.LoadingPage import com.github.damontecres.wholphin.ui.components.QuickDetails import com.github.damontecres.wholphin.ui.data.AddPlaylistViewModel @@ -69,6 +70,7 @@ import com.github.damontecres.wholphin.ui.playback.playable import com.github.damontecres.wholphin.ui.playback.scale import com.github.damontecres.wholphin.ui.rememberPosition import com.github.damontecres.wholphin.ui.tryRequestFocus +import com.github.damontecres.wholphin.util.HomeRow import com.github.damontecres.wholphin.util.HomeRowLoadingState import com.github.damontecres.wholphin.util.LoadingState import kotlinx.coroutines.delay @@ -182,6 +184,13 @@ fun HomePage( } } +fun HomeRowLoadingState.getItem(index: Int) = + when (val data = (this as? HomeRowLoadingState.Success)?.data) { + is HomeRow.BaseItemHomeRow -> data.items.getOrNull(index) + is HomeRow.GenreHowRow -> data.items.getOrNull(index) + null -> null + } + @Composable fun HomePageContent( homeRows: List, @@ -198,7 +207,7 @@ fun HomePageContent( var position by rememberPosition() val focusedItem = position.let { - (homeRows.getOrNull(it.row) as? HomeRowLoadingState.Success)?.items?.getOrNull(it.column) + homeRows.getOrNull(it.row)?.getItem(it.column) } val rowFocusRequesters = remember(homeRows) { List(homeRows.size) { FocusRequester() } } @@ -211,7 +220,7 @@ fun HomePageContent( } else { // Waiting for the first home row to load, then focus on it homeRows - .indexOfFirst { it is HomeRowLoadingState.Success && it.items.isNotEmpty() } + .indexOfFirst { it is HomeRowLoadingState.Success && it.data.isNotEmpty() } .takeIf { it >= 0 } ?.let { rowFocusRequesters[it].tryRequestFocus() @@ -228,17 +237,29 @@ fun HomePageContent( } } LaunchedEffect(onUpdateBackdrop, focusedItem) { - focusedItem?.let { onUpdateBackdrop.invoke(it) } + (focusedItem as? BaseItem)?.let { onUpdateBackdrop.invoke(it) } } Box(modifier = modifier) { Column(modifier = Modifier.fillMaxSize()) { - HomePageHeader( - item = focusedItem, - modifier = - Modifier - .padding(top = 48.dp, bottom = 32.dp, start = 32.dp) - .fillMaxHeight(.33f), - ) + val headerModifier = + Modifier + .padding(top = 48.dp, bottom = 32.dp, start = 32.dp) + .fillMaxHeight(.33f) + when (focusedItem) { + is BaseItem -> { + HomePageHeader( + item = focusedItem, + modifier = headerModifier, + ) + } + + is Genre -> { + Text( + text = focusedItem.name, + modifier = headerModifier, + ) + } + } LazyColumn( state = listState, verticalArrangement = Arrangement.spacedBy(8.dp), @@ -307,73 +328,55 @@ fun HomePageContent( } is HomeRowLoadingState.Success -> { - if (row.items.isNotEmpty()) { - val viewOptions = row.viewOptions - ItemRow( - title = row.title, - items = row.items, - onClickItem = { index, item -> - onClickItem.invoke(RowColumn(rowIndex, index), item) - }, - onLongClickItem = { index, item -> - onLongClickItem.invoke(RowColumn(rowIndex, index), item) - }, - modifier = - Modifier - .fillMaxWidth() - .focusGroup() - .focusRequester(rowFocusRequesters[rowIndex]) - .animateItem(), - horizontalPadding = viewOptions.spacing.dp, - cardContent = { index, item, cardModifier, onClick, onLongClick -> - BannerCard( - name = item?.data?.seriesName ?: item?.name, - item = item, - aspectRatio = viewOptions.aspectRatio.ratio, - imageType = viewOptions.imageType.imageType, - imageContentScale = viewOptions.contentScale.scale, - cornerText = item?.ui?.episdodeUnplayedCornerText, - played = item?.data?.userData?.played ?: false, - favorite = item?.favorite ?: false, - playPercent = - item?.data?.userData?.playedPercentage - ?: 0.0, - onClick = onClick, - onLongClick = onLongClick, - modifier = - cardModifier - .onFocusChanged { - if (it.isFocused) { - position = RowColumn(rowIndex, index) -// item?.let(onUpdateBackdrop) - } - if (it.isFocused && onFocusPosition != null) { - val nonEmptyRowBefore = - homeRows - .subList(0, rowIndex) - .count { - it is HomeRowLoadingState.Success && it.items.isEmpty() - } - onFocusPosition.invoke( - RowColumn( - rowIndex - nonEmptyRowBefore, - index, - ), - ) - } - }.onKeyEvent { - if (isPlayKeyUp(it) && item?.type?.playable == true) { - Timber.v("Clicked play on ${item.id}") - onClickPlay.invoke(position, item) - return@onKeyEvent true - } - return@onKeyEvent false - }, - interactionSource = null, - cardHeight = viewOptions.heightDp.dp, + if (row.data.isNotEmpty()) { + when (row.data) { + is HomeRow.BaseItemHomeRow -> { + BaseItemRow( + row = row, + rowData = row.data, + onClickItem = { index, item -> + onClickItem.invoke(RowColumn(rowIndex, index), item) + }, + onLongClickItem = { index, item -> + onLongClickItem.invoke( + RowColumn(rowIndex, index), + item, + ) + }, + onCardFocus = { index -> + position = RowColumn(rowIndex, index) + if (onFocusPosition != null) { + val nonEmptyRowBefore = + homeRows + .subList(0, rowIndex) + .count { + it is HomeRowLoadingState.Success && it.data.isEmpty() + } + onFocusPosition.invoke( + RowColumn( + rowIndex - nonEmptyRowBefore, + index, + ), + ) + } + }, + onClickPlay = { index -> + row.data.items.get(index)?.let { + onClickPlay.invoke( + RowColumn(rowIndex, index), + it, + ) + } + }, + modifier = Modifier, + focusRequester = rowFocusRequesters[rowIndex], ) - }, - ) + } + + is HomeRow.GenreHowRow -> { + TODO() + } + } } } } @@ -475,3 +478,62 @@ fun HomePageHeader( } } } + +@Composable +fun BaseItemRow( + row: HomeRowLoadingState.Success, + rowData: HomeRow.BaseItemHomeRow, + onClickItem: (Int, BaseItem) -> Unit, + onLongClickItem: (Int, BaseItem) -> Unit, + onClickPlay: (Int) -> Unit, + onCardFocus: (Int) -> Unit, + modifier: Modifier = Modifier, + focusRequester: FocusRequester = remember { FocusRequester() }, +) { + val viewOptions = row.viewOptions + ItemRow( + title = row.title, + items = rowData.items, + onClickItem = onClickItem, + onLongClickItem = onLongClickItem, + modifier = + modifier + .fillMaxWidth() + .focusGroup() + .focusRequester(focusRequester), + horizontalPadding = viewOptions.spacing.dp, + cardContent = { index, item, cardModifier, onClick, onLongClick -> + BannerCard( + name = item?.data?.seriesName ?: item?.name, + item = item, + aspectRatio = viewOptions.aspectRatio.ratio, + imageType = viewOptions.imageType.imageType, + imageContentScale = viewOptions.contentScale.scale, + cornerText = item?.ui?.episdodeUnplayedCornerText, + played = item?.data?.userData?.played ?: false, + favorite = item?.favorite ?: false, + playPercent = + item?.data?.userData?.playedPercentage + ?: 0.0, + onClick = onClick, + onLongClick = onLongClick, + modifier = + cardModifier + .onFocusChanged { + if (it.isFocused) { + onCardFocus.invoke(index) + } + }.onKeyEvent { + if (isPlayKeyUp(it) && item?.type?.playable == true) { + Timber.v("Clicked play on ${item.id}") + onClickPlay.invoke(index) + return@onKeyEvent true + } + return@onKeyEvent false + }, + interactionSource = null, + cardHeight = viewOptions.heightDp.dp, + ) + }, + ) +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/util/LoadingState.kt b/app/src/main/java/com/github/damontecres/wholphin/util/LoadingState.kt index 50e42889b5..49f9be615e 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/util/LoadingState.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/util/LoadingState.kt @@ -2,6 +2,7 @@ package com.github.damontecres.wholphin.util import com.github.damontecres.wholphin.data.model.BaseItem import com.github.damontecres.wholphin.data.model.HomeRowViewOptions +import com.github.damontecres.wholphin.ui.components.Genre /** * Generic state for loading something from the API @@ -59,9 +60,15 @@ sealed interface HomeRowLoadingState { data class Success( override val title: String, - val items: List, val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), - ) : HomeRowLoadingState + val data: HomeRow, + ) : HomeRowLoadingState { + constructor( + title: String, + items: List, + viewOptions: HomeRowViewOptions = HomeRowViewOptions(), + ) : this(title, viewOptions, HomeRow.BaseItemHomeRow(items)) + } data class Error( override val title: String, @@ -73,6 +80,24 @@ sealed interface HomeRowLoadingState { } } +sealed interface HomeRow { + fun isEmpty(): Boolean + + fun isNotEmpty(): Boolean = !isEmpty() + + data class BaseItemHomeRow( + val items: List, + ) : HomeRow { + override fun isEmpty(): Boolean = items.isEmpty() + } + + data class GenreHowRow( + val items: List, + ) : HomeRow { + override fun isEmpty(): Boolean = items.isEmpty() + } +} + /** * Generic state for loading something from the API * From 45e023d1b2a08de36dec78c48ad7b0aa2ba5f404 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Fri, 23 Jan 2026 18:18:59 -0500 Subject: [PATCH 06/53] Revert "Use typed HomeRow in HomeRowLoadingState.Success" This reverts commit 2c6e7a57f0204d2ce85ae86c84702a959b1e80bf. --- .../ui/components/RecommendedContent.kt | 12 +- .../damontecres/wholphin/ui/main/HomePage.kt | 214 +++++++----------- .../damontecres/wholphin/util/LoadingState.kt | 29 +-- 3 files changed, 79 insertions(+), 176 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedContent.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedContent.kt index 44dffeec97..869a454d9c 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedContent.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedContent.kt @@ -34,7 +34,6 @@ import com.github.damontecres.wholphin.ui.launchIO import com.github.damontecres.wholphin.ui.main.HomePageContent import com.github.damontecres.wholphin.ui.nav.Destination import com.github.damontecres.wholphin.util.ApiRequestPager -import com.github.damontecres.wholphin.util.HomeRow import com.github.damontecres.wholphin.util.HomeRowLoadingState import com.github.damontecres.wholphin.util.LoadingState import kotlinx.coroutines.Dispatchers @@ -62,16 +61,7 @@ abstract class RecommendedViewModel( viewModelScope.launchIO { val row = rows.value.getOrNull(position.row) if (row is HomeRowLoadingState.Success) { - when (row.data) { - is HomeRow.BaseItemHomeRow -> { - (row.data.items as? ApiRequestPager<*>)?.refreshItem( - position.column, - itemId, - ) - } - - is HomeRow.GenreHowRow -> {} - } + (row.items as? ApiRequestPager<*>)?.refreshItem(position.column, itemId) } } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt index 092b2f8078..88b2fd2744 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt @@ -54,7 +54,6 @@ import com.github.damontecres.wholphin.ui.components.DialogParams import com.github.damontecres.wholphin.ui.components.DialogPopup import com.github.damontecres.wholphin.ui.components.EpisodeName import com.github.damontecres.wholphin.ui.components.ErrorMessage -import com.github.damontecres.wholphin.ui.components.Genre import com.github.damontecres.wholphin.ui.components.LoadingPage import com.github.damontecres.wholphin.ui.components.QuickDetails import com.github.damontecres.wholphin.ui.data.AddPlaylistViewModel @@ -70,7 +69,6 @@ import com.github.damontecres.wholphin.ui.playback.playable import com.github.damontecres.wholphin.ui.playback.scale import com.github.damontecres.wholphin.ui.rememberPosition import com.github.damontecres.wholphin.ui.tryRequestFocus -import com.github.damontecres.wholphin.util.HomeRow import com.github.damontecres.wholphin.util.HomeRowLoadingState import com.github.damontecres.wholphin.util.LoadingState import kotlinx.coroutines.delay @@ -184,13 +182,6 @@ fun HomePage( } } -fun HomeRowLoadingState.getItem(index: Int) = - when (val data = (this as? HomeRowLoadingState.Success)?.data) { - is HomeRow.BaseItemHomeRow -> data.items.getOrNull(index) - is HomeRow.GenreHowRow -> data.items.getOrNull(index) - null -> null - } - @Composable fun HomePageContent( homeRows: List, @@ -207,7 +198,7 @@ fun HomePageContent( var position by rememberPosition() val focusedItem = position.let { - homeRows.getOrNull(it.row)?.getItem(it.column) + (homeRows.getOrNull(it.row) as? HomeRowLoadingState.Success)?.items?.getOrNull(it.column) } val rowFocusRequesters = remember(homeRows) { List(homeRows.size) { FocusRequester() } } @@ -220,7 +211,7 @@ fun HomePageContent( } else { // Waiting for the first home row to load, then focus on it homeRows - .indexOfFirst { it is HomeRowLoadingState.Success && it.data.isNotEmpty() } + .indexOfFirst { it is HomeRowLoadingState.Success && it.items.isNotEmpty() } .takeIf { it >= 0 } ?.let { rowFocusRequesters[it].tryRequestFocus() @@ -237,29 +228,17 @@ fun HomePageContent( } } LaunchedEffect(onUpdateBackdrop, focusedItem) { - (focusedItem as? BaseItem)?.let { onUpdateBackdrop.invoke(it) } + focusedItem?.let { onUpdateBackdrop.invoke(it) } } Box(modifier = modifier) { Column(modifier = Modifier.fillMaxSize()) { - val headerModifier = - Modifier - .padding(top = 48.dp, bottom = 32.dp, start = 32.dp) - .fillMaxHeight(.33f) - when (focusedItem) { - is BaseItem -> { - HomePageHeader( - item = focusedItem, - modifier = headerModifier, - ) - } - - is Genre -> { - Text( - text = focusedItem.name, - modifier = headerModifier, - ) - } - } + HomePageHeader( + item = focusedItem, + modifier = + Modifier + .padding(top = 48.dp, bottom = 32.dp, start = 32.dp) + .fillMaxHeight(.33f), + ) LazyColumn( state = listState, verticalArrangement = Arrangement.spacedBy(8.dp), @@ -328,55 +307,73 @@ fun HomePageContent( } is HomeRowLoadingState.Success -> { - if (row.data.isNotEmpty()) { - when (row.data) { - is HomeRow.BaseItemHomeRow -> { - BaseItemRow( - row = row, - rowData = row.data, - onClickItem = { index, item -> - onClickItem.invoke(RowColumn(rowIndex, index), item) - }, - onLongClickItem = { index, item -> - onLongClickItem.invoke( - RowColumn(rowIndex, index), - item, - ) - }, - onCardFocus = { index -> - position = RowColumn(rowIndex, index) - if (onFocusPosition != null) { - val nonEmptyRowBefore = - homeRows - .subList(0, rowIndex) - .count { - it is HomeRowLoadingState.Success && it.data.isEmpty() - } - onFocusPosition.invoke( - RowColumn( - rowIndex - nonEmptyRowBefore, - index, - ), - ) - } - }, - onClickPlay = { index -> - row.data.items.get(index)?.let { - onClickPlay.invoke( - RowColumn(rowIndex, index), - it, - ) - } - }, - modifier = Modifier, - focusRequester = rowFocusRequesters[rowIndex], + if (row.items.isNotEmpty()) { + val viewOptions = row.viewOptions + ItemRow( + title = row.title, + items = row.items, + onClickItem = { index, item -> + onClickItem.invoke(RowColumn(rowIndex, index), item) + }, + onLongClickItem = { index, item -> + onLongClickItem.invoke(RowColumn(rowIndex, index), item) + }, + modifier = + Modifier + .fillMaxWidth() + .focusGroup() + .focusRequester(rowFocusRequesters[rowIndex]) + .animateItem(), + horizontalPadding = viewOptions.spacing.dp, + cardContent = { index, item, cardModifier, onClick, onLongClick -> + BannerCard( + name = item?.data?.seriesName ?: item?.name, + item = item, + aspectRatio = viewOptions.aspectRatio.ratio, + imageType = viewOptions.imageType.imageType, + imageContentScale = viewOptions.contentScale.scale, + cornerText = item?.ui?.episdodeUnplayedCornerText, + played = item?.data?.userData?.played ?: false, + favorite = item?.favorite ?: false, + playPercent = + item?.data?.userData?.playedPercentage + ?: 0.0, + onClick = onClick, + onLongClick = onLongClick, + modifier = + cardModifier + .onFocusChanged { + if (it.isFocused) { + position = RowColumn(rowIndex, index) +// item?.let(onUpdateBackdrop) + } + if (it.isFocused && onFocusPosition != null) { + val nonEmptyRowBefore = + homeRows + .subList(0, rowIndex) + .count { + it is HomeRowLoadingState.Success && it.items.isEmpty() + } + onFocusPosition.invoke( + RowColumn( + rowIndex - nonEmptyRowBefore, + index, + ), + ) + } + }.onKeyEvent { + if (isPlayKeyUp(it) && item?.type?.playable == true) { + Timber.v("Clicked play on ${item.id}") + onClickPlay.invoke(position, item) + return@onKeyEvent true + } + return@onKeyEvent false + }, + interactionSource = null, + cardHeight = viewOptions.heightDp.dp, ) - } - - is HomeRow.GenreHowRow -> { - TODO() - } - } + }, + ) } } } @@ -478,62 +475,3 @@ fun HomePageHeader( } } } - -@Composable -fun BaseItemRow( - row: HomeRowLoadingState.Success, - rowData: HomeRow.BaseItemHomeRow, - onClickItem: (Int, BaseItem) -> Unit, - onLongClickItem: (Int, BaseItem) -> Unit, - onClickPlay: (Int) -> Unit, - onCardFocus: (Int) -> Unit, - modifier: Modifier = Modifier, - focusRequester: FocusRequester = remember { FocusRequester() }, -) { - val viewOptions = row.viewOptions - ItemRow( - title = row.title, - items = rowData.items, - onClickItem = onClickItem, - onLongClickItem = onLongClickItem, - modifier = - modifier - .fillMaxWidth() - .focusGroup() - .focusRequester(focusRequester), - horizontalPadding = viewOptions.spacing.dp, - cardContent = { index, item, cardModifier, onClick, onLongClick -> - BannerCard( - name = item?.data?.seriesName ?: item?.name, - item = item, - aspectRatio = viewOptions.aspectRatio.ratio, - imageType = viewOptions.imageType.imageType, - imageContentScale = viewOptions.contentScale.scale, - cornerText = item?.ui?.episdodeUnplayedCornerText, - played = item?.data?.userData?.played ?: false, - favorite = item?.favorite ?: false, - playPercent = - item?.data?.userData?.playedPercentage - ?: 0.0, - onClick = onClick, - onLongClick = onLongClick, - modifier = - cardModifier - .onFocusChanged { - if (it.isFocused) { - onCardFocus.invoke(index) - } - }.onKeyEvent { - if (isPlayKeyUp(it) && item?.type?.playable == true) { - Timber.v("Clicked play on ${item.id}") - onClickPlay.invoke(index) - return@onKeyEvent true - } - return@onKeyEvent false - }, - interactionSource = null, - cardHeight = viewOptions.heightDp.dp, - ) - }, - ) -} diff --git a/app/src/main/java/com/github/damontecres/wholphin/util/LoadingState.kt b/app/src/main/java/com/github/damontecres/wholphin/util/LoadingState.kt index 49f9be615e..50e42889b5 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/util/LoadingState.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/util/LoadingState.kt @@ -2,7 +2,6 @@ package com.github.damontecres.wholphin.util import com.github.damontecres.wholphin.data.model.BaseItem import com.github.damontecres.wholphin.data.model.HomeRowViewOptions -import com.github.damontecres.wholphin.ui.components.Genre /** * Generic state for loading something from the API @@ -60,15 +59,9 @@ sealed interface HomeRowLoadingState { data class Success( override val title: String, + val items: List, val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), - val data: HomeRow, - ) : HomeRowLoadingState { - constructor( - title: String, - items: List, - viewOptions: HomeRowViewOptions = HomeRowViewOptions(), - ) : this(title, viewOptions, HomeRow.BaseItemHomeRow(items)) - } + ) : HomeRowLoadingState data class Error( override val title: String, @@ -80,24 +73,6 @@ sealed interface HomeRowLoadingState { } } -sealed interface HomeRow { - fun isEmpty(): Boolean - - fun isNotEmpty(): Boolean = !isEmpty() - - data class BaseItemHomeRow( - val items: List, - ) : HomeRow { - override fun isEmpty(): Boolean = items.isEmpty() - } - - data class GenreHowRow( - val items: List, - ) : HomeRow { - override fun isEmpty(): Boolean = items.isEmpty() - } -} - /** * Generic state for loading something from the API * From 00f6de8ec4f45f5b4cc44cc6e81bb008800e7f7b Mon Sep 17 00:00:00 2001 From: Damontecres Date: Fri, 23 Jan 2026 19:01:21 -0500 Subject: [PATCH 07/53] Handle genre cards --- .../wholphin/data/model/BaseItem.kt | 1 + .../wholphin/ui/cards/BannerCard.kt | 13 ++- .../wholphin/ui/cards/GenreCard.kt | 31 +++-- .../wholphin/ui/components/GenreCardGrid.kt | 104 ++++++++++------- .../damontecres/wholphin/ui/main/HomePage.kt | 108 ++++++++++-------- .../ui/main/settings/HomePageSettings.kt | 28 ++++- 6 files changed, 181 insertions(+), 104 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/BaseItem.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/BaseItem.kt index 312b744634..c32f4a4506 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/BaseItem.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/BaseItem.kt @@ -32,6 +32,7 @@ import kotlin.time.Duration data class BaseItem( val data: BaseItemDto, val useSeriesForPrimary: Boolean, + val imageUrlOverride: String? = null, ) : CardGridItem { val id get() = data.id diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/cards/BannerCard.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/cards/BannerCard.kt index 1c75cc6fa4..5999a2696d 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/cards/BannerCard.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/cards/BannerCard.kt @@ -78,12 +78,13 @@ fun BannerCard( val imageUrl = remember(item, fillHeight, imageType) { if (item != null) { - imageUrlService.getItemImageUrl( - item, - imageType, - fillWidth = null, - fillHeight = fillHeight, - ) + item.imageUrlOverride + ?: imageUrlService.getItemImageUrl( + item, + imageType, + fillWidth = null, + fillHeight = fillHeight, + ) } else { null } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/cards/GenreCard.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/cards/GenreCard.kt index 73cf5ba3aa..a32fece9ae 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/cards/GenreCard.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/cards/GenreCard.kt @@ -42,11 +42,29 @@ fun GenreCard( onLongClick: () -> Unit, modifier: Modifier = Modifier, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, +) = GenreCard( + genreId = genre?.id, + name = genre?.name, + imageUrl = genre?.imageUrl, + onClick = onClick, + onLongClick = onLongClick, + modifier = modifier, + interactionSource = interactionSource, +) + +@Composable +fun GenreCard( + genreId: UUID?, + name: String?, + imageUrl: String?, + onClick: () -> Unit, + onLongClick: () -> Unit, + modifier: Modifier = Modifier, + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, ) { - val background = rememberIdColor(genre?.id).copy(alpha = .6f) + val background = rememberIdColor(genreId).copy(alpha = .6f) Card( - modifier = - modifier, + modifier = modifier, onClick = onClick, onLongClick = onLongClick, interactionSource = interactionSource, @@ -63,12 +81,12 @@ fun GenreCard( .fillMaxSize() .clip(RoundedCornerShape(8.dp)), ) { - if (genre?.imageUrl.isNotNullOrBlank()) { + if (imageUrl != null) { AsyncImage( model = ImageRequest .Builder(LocalContext.current) - .data(genre.imageUrl) + .data(imageUrl) .crossfade(true) .build(), contentScale = ContentScale.FillBounds, @@ -88,7 +106,7 @@ fun GenreCard( .background(background), ) { Text( - text = genre?.name ?: "", + text = name ?: "", color = MaterialTheme.colorScheme.onSurfaceVariant, style = MaterialTheme.typography.titleLarge, fontWeight = FontWeight.Bold, @@ -112,7 +130,6 @@ private fun GenreCardPreview() { UUID.randomUUID(), "Adventure", null, - Color.Black, ) GenreCard( genre = genre, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/components/GenreCardGrid.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/components/GenreCardGrid.kt index cdf1896960..9d6f662b14 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/components/GenreCardGrid.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/components/GenreCardGrid.kt @@ -5,12 +5,12 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.Stable import androidx.compose.runtime.getValue import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester -import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.dp @@ -102,51 +102,21 @@ class GenreViewModel .execute(api, request) .content.items .map { - Genre(it.id, it.name ?: "", null, Color.Black) + Genre(it.id, it.name ?: "", null) } withContext(Dispatchers.Main) { this@GenreViewModel.genres.value = genres loading.value = LoadingState.Success } - val genreToUrl = ConcurrentHashMap() - val semaphore = Semaphore(4) - genres - .map { genre -> - viewModelScope.async(Dispatchers.IO) { - semaphore.withPermit { - val item = - GetItemsRequestHandler - .execute( - api, - GetItemsRequest( - parentId = itemId, - recursive = true, - limit = 1, - sortBy = listOf(ItemSortBy.RANDOM), - fields = listOf(ItemFields.GENRES), - imageTypes = listOf(ImageType.BACKDROP), - imageTypeLimit = 1, - includeItemTypes = includeItemTypes, - genreIds = listOf(genre.id), - enableTotalRecordCount = false, - ), - ).content.items - .firstOrNull() - if (item != null) { - genreToUrl[genre.id] = - imageUrlService.getItemImageUrl( - itemId = item.id, - itemType = item.type, - seriesId = null, - useSeriesForPrimary = true, - imageType = ImageType.BACKDROP, - imageTags = item.imageTags.orEmpty(), - fillWidth = cardWidthPx, - ) - } - } - } - }.awaitAll() + val genreToUrl = + getGenreImageMap( + api = api, + imageUrlService = imageUrlService, + genres = genres.map { it.id }, + parentId = itemId, + includeItemTypes = includeItemTypes, + cardWidthPx = cardWidthPx, + ) val genresWithImages = genres.map { it.copy( @@ -171,11 +141,61 @@ class GenreViewModel } } +suspend fun ViewModel.getGenreImageMap( + api: ApiClient, + imageUrlService: ImageUrlService, + genres: List, + parentId: UUID, + includeItemTypes: List?, + cardWidthPx: Int?, +): Map { + val genreToUrl = ConcurrentHashMap() + val semaphore = Semaphore(4) + genres + .map { genreId -> + viewModelScope.async(Dispatchers.IO) { + semaphore.withPermit { + val item = + GetItemsRequestHandler + .execute( + api, + GetItemsRequest( + parentId = parentId, + recursive = true, + limit = 1, + sortBy = listOf(ItemSortBy.RANDOM), + fields = listOf(ItemFields.GENRES), + imageTypes = listOf(ImageType.BACKDROP), + imageTypeLimit = 1, + includeItemTypes = includeItemTypes, + genreIds = listOf(genreId), + enableTotalRecordCount = false, + ), + ).content.items + .firstOrNull() + if (item != null) { + genreToUrl[genreId] = + imageUrlService.getItemImageUrl( + itemId = item.id, + itemType = item.type, + seriesId = null, + useSeriesForPrimary = true, + imageType = ImageType.BACKDROP, + imageTags = item.imageTags.orEmpty(), + fillWidth = cardWidthPx, + ) + } + } + } + }.awaitAll() + return genreToUrl +} + +@Stable data class Genre( val id: UUID, val name: String, val imageUrl: String?, - val color: Color, ) : CardGridItem { override val gridId: String get() = id.toString() override val playable: Boolean = false diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt index 88b2fd2744..dbcf8fb02d 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt @@ -48,6 +48,7 @@ import com.github.damontecres.wholphin.data.model.BaseItem import com.github.damontecres.wholphin.preferences.UserPreferences import com.github.damontecres.wholphin.ui.Cards import com.github.damontecres.wholphin.ui.cards.BannerCard +import com.github.damontecres.wholphin.ui.cards.GenreCard import com.github.damontecres.wholphin.ui.cards.ItemRow import com.github.damontecres.wholphin.ui.components.CircularProgress import com.github.damontecres.wholphin.ui.components.DialogParams @@ -326,52 +327,67 @@ fun HomePageContent( .animateItem(), horizontalPadding = viewOptions.spacing.dp, cardContent = { index, item, cardModifier, onClick, onLongClick -> - BannerCard( - name = item?.data?.seriesName ?: item?.name, - item = item, - aspectRatio = viewOptions.aspectRatio.ratio, - imageType = viewOptions.imageType.imageType, - imageContentScale = viewOptions.contentScale.scale, - cornerText = item?.ui?.episdodeUnplayedCornerText, - played = item?.data?.userData?.played ?: false, - favorite = item?.favorite ?: false, - playPercent = - item?.data?.userData?.playedPercentage - ?: 0.0, - onClick = onClick, - onLongClick = onLongClick, - modifier = - cardModifier - .onFocusChanged { - if (it.isFocused) { - position = RowColumn(rowIndex, index) -// item?.let(onUpdateBackdrop) - } - if (it.isFocused && onFocusPosition != null) { - val nonEmptyRowBefore = - homeRows - .subList(0, rowIndex) - .count { - it is HomeRowLoadingState.Success && it.items.isEmpty() - } - onFocusPosition.invoke( - RowColumn( - rowIndex - nonEmptyRowBefore, - index, - ), - ) - } - }.onKeyEvent { - if (isPlayKeyUp(it) && item?.type?.playable == true) { - Timber.v("Clicked play on ${item.id}") - onClickPlay.invoke(position, item) - return@onKeyEvent true - } - return@onKeyEvent false - }, - interactionSource = null, - cardHeight = viewOptions.heightDp.dp, - ) + val mod = + cardModifier + .onFocusChanged { + if (it.isFocused) { + position = RowColumn(rowIndex, index) + } + if (it.isFocused && onFocusPosition != null) { + val nonEmptyRowBefore = + homeRows + .subList(0, rowIndex) + .count { + it is HomeRowLoadingState.Success && it.items.isEmpty() + } + onFocusPosition.invoke( + RowColumn( + rowIndex - nonEmptyRowBefore, + index, + ), + ) + } + }.onKeyEvent { + if (isPlayKeyUp(it) && item?.type?.playable == true) { + Timber.v("Clicked play on ${item.id}") + onClickPlay.invoke(position, item) + return@onKeyEvent true + } + return@onKeyEvent false + } + when (item?.type) { + BaseItemKind.GENRE -> { + GenreCard( + genreId = item.id, + name = item.name, + imageUrl = item.imageUrlOverride, + onClick = onClick, + onLongClick = onLongClick, + modifier = mod.height(viewOptions.heightDp.dp), + ) + } + + else -> { + BannerCard( + name = item?.data?.seriesName ?: item?.name, + item = item, + aspectRatio = viewOptions.aspectRatio.ratio, + imageType = viewOptions.imageType.imageType, + imageContentScale = viewOptions.contentScale.scale, + cornerText = item?.ui?.episdodeUnplayedCornerText, + played = item?.data?.userData?.played ?: false, + favorite = item?.favorite ?: false, + playPercent = + item?.data?.userData?.playedPercentage + ?: 0.0, + onClick = onClick, + onLongClick = onLongClick, + modifier = mod, + interactionSource = null, + cardHeight = viewOptions.heightDp.dp, + ) + } + } }, ) } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt index 9372d5479a..c57d17b031 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt @@ -32,9 +32,13 @@ import com.github.damontecres.wholphin.data.model.HomeRowConfig import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay import com.github.damontecres.wholphin.data.model.HomeRowViewOptions import com.github.damontecres.wholphin.services.BackdropService +import com.github.damontecres.wholphin.services.ImageUrlService import com.github.damontecres.wholphin.services.LatestNextUpService import com.github.damontecres.wholphin.services.UserPreferencesService +import com.github.damontecres.wholphin.ui.AspectRatio +import com.github.damontecres.wholphin.ui.Cards import com.github.damontecres.wholphin.ui.SlimItemFields +import com.github.damontecres.wholphin.ui.components.getGenreImageMap import com.github.damontecres.wholphin.ui.launchIO import com.github.damontecres.wholphin.ui.main.HomePageContent import com.github.damontecres.wholphin.ui.main.LatestData @@ -65,6 +69,7 @@ class HomePageSettingsViewModel private val navDrawerItemRepository: NavDrawerItemRepository, private val backdropService: BackdropService, private val latestNextUpService: LatestNextUpService, + private val imageUrlService: ImageUrlService, ) : ViewModel() { private val _state = MutableStateFlow(HomePageSettingsState.EMPTY) val state: StateFlow = _state @@ -197,7 +202,21 @@ class HomePageSettingsViewModel GetGenresRequestHandler .execute(api, request) .content.items - .map { BaseItem(it, false) } + val genreIds = items.map { it.id } + val genreImages = + getGenreImageMap( + api = api, + imageUrlService = imageUrlService, + genres = genreIds, + parentId = row.parentId, + includeItemTypes = null, + cardWidthPx = null, + ) + val genres = + items.map { + BaseItem(it, false, genreImages[it.id]) + } + val name = _state.value.libraries .firstOrNull { it.itemId == row.parentId } @@ -208,7 +227,7 @@ class HomePageSettingsViewModel listOf( HomeRowLoadingState.Success( title, - items, + genres, viewOptions = row.viewOptions, ), ) @@ -347,7 +366,10 @@ class HomePageSettingsViewModel HomeRowConfig.Genres( UUID.randomUUID(), library.itemId, - HomeRowViewOptions(), + HomeRowViewOptions( + heightDp = (Cards.HEIGHT_2X3_DP * .75f).toInt(), + aspectRatio = AspectRatio.WIDE, + ), ), ) } From a90e6bc7b005c5d07ac75824413e1c122f497870 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Fri, 23 Jan 2026 19:39:57 -0500 Subject: [PATCH 08/53] Separate type for continue & next up --- .../wholphin/data/model/HomeRowConfig.kt | 17 +- .../ui/main/settings/HomePageLibraryList.kt | 28 ++- .../ui/main/settings/HomePageRowList.kt | 3 +- .../ui/main/settings/HomePageSettings.kt | 159 +++++++++++++----- 4 files changed, 159 insertions(+), 48 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index 6b0fee4f0b..83a7b1a247 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -27,7 +27,22 @@ sealed class HomeRowConfig { @Serializable data class ContinueWatching( override val id: UUID, - val combined: Boolean, + override val viewOptions: HomeRowViewOptions, + ) : HomeRowConfig() { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + } + + @Serializable + data class NextUp( + override val id: UUID, + override val viewOptions: HomeRowViewOptions, + ) : HomeRowConfig() { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + } + + @Serializable + data class ContinueWatchingCombined( + override val id: UUID, override val viewOptions: HomeRowViewOptions, ) : HomeRowConfig() { override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryList.kt index 73276da673..66d8fd2842 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryList.kt @@ -1,11 +1,13 @@ package com.github.damontecres.wholphin.ui.main.settings +import androidx.annotation.StringRes import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed +import androidx.compose.material3.HorizontalDivider import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember @@ -13,9 +15,11 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester 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 import com.github.damontecres.wholphin.ui.tryRequestFocus @@ -23,6 +27,7 @@ import com.github.damontecres.wholphin.ui.tryRequestFocus fun HomePageLibraryList( libraries: List, onClick: (Library) -> Unit, + onClickMeta: (MetaRowType) -> Unit, modifier: Modifier, firstFocus: FocusRequester = remember { FocusRequester() }, ) { @@ -39,6 +44,19 @@ fun HomePageLibraryList( .fillMaxHeight() .focusRestorer(firstFocus), ) { + itemsIndexed(MetaRowType.entries) { index, type -> + ListItem( + selected = false, + headlineContent = { + Text(stringResource(type.stringId)) + }, + onClick = { onClickMeta.invoke(type) }, + modifier = Modifier.ifElse(index == 0, Modifier.focusRequester(firstFocus)), + ) + } + item { + HorizontalDivider() + } itemsIndexed(libraries) { index, library -> ListItem( selected = false, @@ -46,9 +64,17 @@ fun HomePageLibraryList( Text(library.name) }, onClick = { onClick.invoke(library) }, - modifier = Modifier.ifElse(index == 0, Modifier.focusRequester(firstFocus)), + modifier = Modifier, // .ifElse(index == 0, Modifier.focusRequester(firstFocus)), ) } } } } + +enum class MetaRowType( + @param:StringRes val stringId: Int, +) { + CONTINUE_WATCHING(R.string.continue_watching), + NEXT_UP(R.string.next_up), + COMBINED_CONTINUE_WATCHING(R.string.combine_continue_next), +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt index c5c10d3ea6..6b42fbbe84 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt @@ -30,7 +30,6 @@ 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.data.model.HomeRowConfig import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay import com.github.damontecres.wholphin.ui.FontAwesome import com.github.damontecres.wholphin.ui.components.Button @@ -64,7 +63,7 @@ fun HomePageRowList( config = row, moveUpAllowed = index > 0, moveDownAllowed = index != state.rows.lastIndex, - deleteAllowed = row.config !is HomeRowConfig.ContinueWatching, + deleteAllowed = true, onClickMove = { onClickMove.invoke(it, index) }, onClickDelete = { onClickDelete.invoke(index) }, onClick = { onClick.invoke(index, row) }, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt index c57d17b031..69eec4f504 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt @@ -111,17 +111,36 @@ class HomePageSettingsViewModel ), ) } - val rowConfig = - listOf( - HomeRowConfigDisplay( - context.getString(R.string.continue_watching), - HomeRowConfig.ContinueWatching( - UUID.randomUUID(), - prefs.combineContinueNext, - HomeRowViewOptions(), + val continueWatchingRows = + if (prefs.combineContinueNext) { + listOf( + HomeRowConfigDisplay( + context.getString(R.string.combine_continue_next), + HomeRowConfig.ContinueWatchingCombined( + UUID.randomUUID(), + HomeRowViewOptions(), + ), + ), + ) + } else { + listOf( + HomeRowConfigDisplay( + context.getString(R.string.continue_watching), + HomeRowConfig.ContinueWatching( + UUID.randomUUID(), + HomeRowViewOptions(), + ), + ), + HomeRowConfigDisplay( + context.getString(R.string.next_up), + HomeRowConfig.NextUp( + UUID.randomUUID(), + HomeRowViewOptions(), + ), ), - ), - ) + includedIds + ) + } + val rowConfig = continueWatchingRows + includedIds _state.update { it.copy(rows = rowConfig) } @@ -148,6 +167,16 @@ class HomePageSettingsViewModel when (row) { is HomeRowConfig.ContinueWatching -> { val resume = latestNextUpService.getResume(userDto.id, limit, true) + listOf( + HomeRowLoadingState.Success( + title = context.getString(R.string.continue_watching), + items = resume, + viewOptions = row.viewOptions, + ), + ) + } + + is HomeRowConfig.NextUp -> { val nextUp = latestNextUpService.getNextUp( userDto.id, @@ -155,40 +184,37 @@ class HomePageSettingsViewModel prefs.enableRewatchingNextUp, false, ) - val watching = - buildList { - if (row.combined) { - val items = - latestNextUpService.buildCombined(resume, nextUp) - add( - HomeRowLoadingState.Success( - title = context.getString(R.string.continue_watching), - items = items, - viewOptions = row.viewOptions, - ), - ) - } else { - if (resume.isNotEmpty()) { - add( - HomeRowLoadingState.Success( - title = context.getString(R.string.continue_watching), - items = resume, - viewOptions = row.viewOptions, - ), - ) - } - if (nextUp.isNotEmpty()) { - add( - HomeRowLoadingState.Success( - title = context.getString(R.string.next_up), - items = nextUp, - viewOptions = row.viewOptions, - ), - ) - } - } - } - watching + listOf( + HomeRowLoadingState.Success( + title = context.getString(R.string.next_up), + items = nextUp, + viewOptions = row.viewOptions, + ), + ) + } + + is HomeRowConfig.ContinueWatchingCombined -> { + val resume = + latestNextUpService.getResume(userDto.id, limit, true) + val nextUp = + latestNextUpService.getNextUp( + userDto.id, + limit, + prefs.enableRewatchingNextUp, + false, + ) + + listOf( + HomeRowLoadingState.Success( + title = context.getString(R.string.continue_watching), + items = + latestNextUpService.buildCombined( + resume, + nextUp, + ), + viewOptions = row.viewOptions, + ), + ) } is HomeRowConfig.Genres -> { @@ -321,6 +347,50 @@ class HomePageSettingsViewModel } } + fun addRow(type: MetaRowType) { + viewModelScope.launchIO { + val newRow = + when (type) { + MetaRowType.CONTINUE_WATCHING -> { + HomeRowConfigDisplay( + context.getString(R.string.continue_watching), + HomeRowConfig.ContinueWatching( + UUID.randomUUID(), + HomeRowViewOptions(), + ), + ) + } + + MetaRowType.NEXT_UP -> { + HomeRowConfigDisplay( + context.getString(R.string.continue_watching), + HomeRowConfig.NextUp( + UUID.randomUUID(), + HomeRowViewOptions(), + ), + ) + } + + MetaRowType.COMBINED_CONTINUE_WATCHING -> { + HomeRowConfigDisplay( + context.getString(R.string.combine_continue_next), + HomeRowConfig.ContinueWatchingCombined( + UUID.randomUUID(), + HomeRowViewOptions(), + ), + ) + } + } + _state.update { + it.copy( + loading = LoadingState.Loading, + rows = it.rows.toMutableList().apply { add(newRow) }, + ) + } + fetchRowData() + } + } + fun addRow( library: Library, rowType: LibraryRowType, @@ -510,6 +580,7 @@ fun HomePageSettings( HomePageLibraryList( libraries = state.libraries, onClick = { destination = HomePageSettingsDestination.ChooseRowType(it) }, + onClickMeta = { viewModel.addRow(it) }, modifier = destModifier, ) } From d809cc2be43514bfb05023d06ab810c4aa48f71c Mon Sep 17 00:00:00 2001 From: Damontecres Date: Fri, 23 Jan 2026 20:24:53 -0500 Subject: [PATCH 09/53] Switch ids to ints --- .../wholphin/data/model/HomeRowConfig.kt | 21 ++-- .../ui/main/settings/HomePageSettings.kt | 101 +++++++++++++----- .../settings/HomePageSettingsDestination.kt | 4 +- 3 files changed, 88 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index 83a7b1a247..8468b01272 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -12,6 +12,7 @@ import com.github.damontecres.wholphin.ui.AspectRatio import com.github.damontecres.wholphin.ui.Cards import com.github.damontecres.wholphin.ui.components.ViewOptionImageType import com.github.damontecres.wholphin.ui.components.ViewOptions +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers import org.jellyfin.sdk.model.serializer.UUIDSerializer @@ -19,38 +20,42 @@ import java.util.UUID @Serializable sealed class HomeRowConfig { - abstract val id: UUID + abstract val id: Int abstract val viewOptions: HomeRowViewOptions abstract fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig @Serializable + @SerialName("ContinueWatching") data class ContinueWatching( - override val id: UUID, + override val id: Int, override val viewOptions: HomeRowViewOptions, ) : HomeRowConfig() { override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) } @Serializable + @SerialName("NextUp") data class NextUp( - override val id: UUID, + override val id: Int, override val viewOptions: HomeRowViewOptions, ) : HomeRowConfig() { override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) } @Serializable + @SerialName("ContinueWatchingCombined") data class ContinueWatchingCombined( - override val id: UUID, + override val id: Int, override val viewOptions: HomeRowViewOptions, ) : HomeRowConfig() { override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) } @Serializable + @SerialName("RecentlyAdded") data class RecentlyAdded( - override val id: UUID, + override val id: Int, val parentId: UUID, override val viewOptions: HomeRowViewOptions, ) : HomeRowConfig() { @@ -58,8 +63,9 @@ sealed class HomeRowConfig { } @Serializable + @SerialName("RecentlyReleased") data class RecentlyReleased( - override val id: UUID, + override val id: Int, val parentId: UUID, override val viewOptions: HomeRowViewOptions, ) : HomeRowConfig() { @@ -67,8 +73,9 @@ sealed class HomeRowConfig { } @Serializable + @SerialName("Genres") data class Genres( - override val id: UUID, + override val id: Int, val parentId: UUID, override val viewOptions: HomeRowViewOptions, ) : HomeRowConfig() { diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt index 69eec4f504..b12d8dedaa 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt @@ -37,13 +37,14 @@ import com.github.damontecres.wholphin.services.LatestNextUpService import com.github.damontecres.wholphin.services.UserPreferencesService import com.github.damontecres.wholphin.ui.AspectRatio import com.github.damontecres.wholphin.ui.Cards +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.launchIO import com.github.damontecres.wholphin.ui.main.HomePageContent -import com.github.damontecres.wholphin.ui.main.LatestData import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem import com.github.damontecres.wholphin.util.GetGenresRequestHandler +import com.github.damontecres.wholphin.util.GetItemsRequestHandler import com.github.damontecres.wholphin.util.HomeRowLoadingState import com.github.damontecres.wholphin.util.LoadingState import dagger.hilt.android.lifecycle.HiltViewModel @@ -51,10 +52,16 @@ import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.update +import kotlinx.serialization.json.Json import org.jellyfin.sdk.api.client.ApiClient +import org.jellyfin.sdk.api.client.extensions.userLibraryApi import org.jellyfin.sdk.model.api.CollectionType +import org.jellyfin.sdk.model.api.ItemSortBy +import org.jellyfin.sdk.model.api.SortOrder import org.jellyfin.sdk.model.api.request.GetGenresRequest +import org.jellyfin.sdk.model.api.request.GetItemsRequest import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest +import timber.log.Timber import java.util.UUID import javax.inject.Inject @@ -96,7 +103,7 @@ class HomePageSettingsViewModel navDrawerItemRepository .getFilteredNavDrawerItems(navDrawerItems) .filter { it is ServerNavDrawerItem } - .map { + .mapIndexed { index, it -> val id = (it as ServerNavDrawerItem).itemId val name = libraries.firstOrNull { it.itemId == id }?.name val title = @@ -105,7 +112,7 @@ class HomePageSettingsViewModel HomeRowConfigDisplay( title, HomeRowConfig.RecentlyAdded( - UUID.randomUUID(), + index, id, HomeRowViewOptions(), ), @@ -117,7 +124,7 @@ class HomePageSettingsViewModel HomeRowConfigDisplay( context.getString(R.string.combine_continue_next), HomeRowConfig.ContinueWatchingCombined( - UUID.randomUUID(), + includedIds.size + 1, HomeRowViewOptions(), ), ), @@ -127,14 +134,14 @@ class HomePageSettingsViewModel HomeRowConfigDisplay( context.getString(R.string.continue_watching), HomeRowConfig.ContinueWatching( - UUID.randomUUID(), + includedIds.size + 1, HomeRowViewOptions(), ), ), HomeRowConfigDisplay( context.getString(R.string.next_up), HomeRowConfig.NextUp( - UUID.randomUUID(), + includedIds.size + 2, HomeRowViewOptions(), ), ), @@ -144,6 +151,8 @@ class HomePageSettingsViewModel _state.update { it.copy(rows = rowConfig) } + val json = Json.encodeToString(rowConfig.map { it.config }) + Timber.v("json=$json") fetchRowData() } @@ -276,21 +285,52 @@ class HomePageSettingsViewModel limit = limit, isPlayed = null, // Server will handle user's preference ) - latestNextUpService - .loadLatest(listOf(LatestData(title, request))) - .let { - it.map { - if (it is HomeRowLoadingState.Success) { - it.copy(viewOptions = row.viewOptions) - } else { - it - } + val latest = + api.userLibraryApi + .getLatestMedia(request) + .content + .map { BaseItem.from(it, api, true) } + .let { + HomeRowLoadingState.Success( + title, + it, + row.viewOptions, + ) } - } + listOf(latest) } is HomeRowConfig.RecentlyReleased -> { - TODO() + val name = + _state.value.libraries + .firstOrNull { it.itemId == row.parentId } + ?.name + val title = + name?.let { + context.getString(R.string.recently_released_in, it) + } ?: context.getString(R.string.recently_released) + val request = + GetItemsRequest( + parentId = row.parentId, + limit = limit, + sortBy = listOf(ItemSortBy.PREMIERE_DATE), + sortOrder = listOf(SortOrder.DESCENDING), + fields = DefaultItemFields, + recursive = true, + ) + GetItemsRequestHandler + .execute(api, request) + .content.items + .map { BaseItem.from(it, api, true) } + .let { + listOf( + HomeRowLoadingState.Success( + title, + it, + row.viewOptions, + ), + ) + } } } }.flatten() @@ -349,13 +389,14 @@ class HomePageSettingsViewModel fun addRow(type: MetaRowType) { viewModelScope.launchIO { + val id = state.value.rows.size val newRow = when (type) { MetaRowType.CONTINUE_WATCHING -> { HomeRowConfigDisplay( context.getString(R.string.continue_watching), HomeRowConfig.ContinueWatching( - UUID.randomUUID(), + id, HomeRowViewOptions(), ), ) @@ -365,7 +406,7 @@ class HomePageSettingsViewModel HomeRowConfigDisplay( context.getString(R.string.continue_watching), HomeRowConfig.NextUp( - UUID.randomUUID(), + id, HomeRowViewOptions(), ), ) @@ -375,7 +416,7 @@ class HomePageSettingsViewModel HomeRowConfigDisplay( context.getString(R.string.combine_continue_next), HomeRowConfig.ContinueWatchingCombined( - UUID.randomUUID(), + id, HomeRowViewOptions(), ), ) @@ -396,6 +437,7 @@ class HomePageSettingsViewModel rowType: LibraryRowType, ) { viewModelScope.launchIO { + val id = state.value.rows.size val newRow = when (rowType) { LibraryRowType.RECENTLY_ADDED -> { @@ -404,7 +446,7 @@ class HomePageSettingsViewModel HomeRowConfigDisplay( title, HomeRowConfig.RecentlyAdded( - UUID.randomUUID(), + id, library.itemId, HomeRowViewOptions(), ), @@ -422,7 +464,7 @@ class HomePageSettingsViewModel HomeRowConfigDisplay( title, HomeRowConfig.RecentlyReleased( - UUID.randomUUID(), + id, library.itemId, HomeRowViewOptions(), ), @@ -434,7 +476,7 @@ class HomePageSettingsViewModel HomeRowConfigDisplay( title, HomeRowConfig.Genres( - UUID.randomUUID(), + id, library.itemId, HomeRowViewOptions( heightDp = (Cards.HEIGHT_2X3_DP * .75f).toInt(), @@ -455,17 +497,17 @@ class HomePageSettingsViewModel } fun updateViewOptions( - rowId: UUID, + rowId: Int, viewOptions: HomeRowViewOptions, ) { viewModelScope.launchIO { _state.update { - val index = state.value.rows.indexOfFirst { it.config.id == rowId } + val index = it.rows.indexOfFirst { it.config.id == rowId } val newRowConfig = - state.value.rows[index] + it.rows[index] .config .updateViewOptions(viewOptions) - val newRow = state.value.rows[index].copy(config = newRowConfig) + val newRow = it.rows[index].copy(config = newRowConfig) it.copy( rows = it.rows.toMutableList().apply { @@ -580,7 +622,10 @@ fun HomePageSettings( HomePageLibraryList( libraries = state.libraries, onClick = { destination = HomePageSettingsDestination.ChooseRowType(it) }, - onClickMeta = { viewModel.addRow(it) }, + onClickMeta = { + viewModel.addRow(it) + destination = HomePageSettingsDestination.RowList + }, modifier = destModifier, ) } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt index f6c21219d2..ddf1a2fcdd 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt @@ -1,7 +1,5 @@ package com.github.damontecres.wholphin.ui.main.settings -import java.util.UUID - sealed interface HomePageSettingsDestination { data object RowList : HomePageSettingsDestination @@ -12,6 +10,6 @@ sealed interface HomePageSettingsDestination { ) : HomePageSettingsDestination data class RowSettings( - val rowId: UUID, + val rowId: Int, ) : HomePageSettingsDestination } From 2da34a8f563eb4a96043a54b7337bf3bfb854291 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Fri, 23 Jan 2026 21:30:45 -0500 Subject: [PATCH 10/53] Add some tests to ensure samples --- .../wholphin/data/model/HomeRowConfig.kt | 1 + .../ui/main/settings/HomePageSettings.kt | 6 +- .../wholphin/test/TestHomeRowSamples.kt | 112 ++++++++++++++++++ 3 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index 8468b01272..d760d44512 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -83,6 +83,7 @@ sealed class HomeRowConfig { } } +@Serializable data class HomeRowConfigDisplay( val title: String, val config: HomeRowConfig, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt index b12d8dedaa..61a2ec2add 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt @@ -52,7 +52,6 @@ import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.update -import kotlinx.serialization.json.Json import org.jellyfin.sdk.api.client.ApiClient import org.jellyfin.sdk.api.client.extensions.userLibraryApi import org.jellyfin.sdk.model.api.CollectionType @@ -61,7 +60,6 @@ import org.jellyfin.sdk.model.api.SortOrder import org.jellyfin.sdk.model.api.request.GetGenresRequest import org.jellyfin.sdk.model.api.request.GetItemsRequest import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest -import timber.log.Timber import java.util.UUID import javax.inject.Inject @@ -151,8 +149,8 @@ class HomePageSettingsViewModel _state.update { it.copy(rows = rowConfig) } - val json = Json.encodeToString(rowConfig.map { it.config }) - Timber.v("json=$json") +// val json = Json.encodeToString(rowConfig) +// Timber.v("json=$json") fetchRowData() } diff --git a/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt b/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt new file mode 100644 index 0000000000..ec3bf4ebe1 --- /dev/null +++ b/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt @@ -0,0 +1,112 @@ +package com.github.damontecres.wholphin.test + +import com.github.damontecres.wholphin.data.model.HomeRowConfig +import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay +import com.github.damontecres.wholphin.data.model.HomeRowViewOptions +import com.github.damontecres.wholphin.preferences.PrefContentScale +import com.github.damontecres.wholphin.ui.AspectRatio +import com.github.damontecres.wholphin.ui.components.ViewOptionImageType +import kotlinx.serialization.json.Json +import org.jellyfin.sdk.model.UUID +import org.junit.Assert +import org.junit.Test +import kotlin.reflect.KClass + +class TestHomeRowSamples { + companion object { + val SAMPLES = + listOf( + HomeRowConfigDisplay( + title = "Recently added", + config = + HomeRowConfig.RecentlyAdded( + id = 0, + parentId = UUID.randomUUID(), + viewOptions = + HomeRowViewOptions( + heightDp = 100, + spacing = 8, + contentScale = PrefContentScale.CROP, + aspectRatio = AspectRatio.FOUR_THREE, + imageType = ViewOptionImageType.THUMB, + showTitles = false, + useSeries = false, + ), + ), + ), + HomeRowConfigDisplay( + title = "Recently released", + config = + HomeRowConfig.RecentlyReleased( + id = 0, + parentId = UUID.randomUUID(), + viewOptions = HomeRowViewOptions(), + ), + ), + HomeRowConfigDisplay( + title = "Genres", + config = + HomeRowConfig.Genres( + id = 0, + parentId = UUID.randomUUID(), + viewOptions = HomeRowViewOptions(), + ), + ), + HomeRowConfigDisplay( + title = "Continue watching", + config = + HomeRowConfig.ContinueWatching( + id = 0, + viewOptions = HomeRowViewOptions(), + ), + ), + HomeRowConfigDisplay( + title = "Next up", + config = + HomeRowConfig.NextUp( + id = 0, + viewOptions = HomeRowViewOptions(), + ), + ), + HomeRowConfigDisplay( + title = "Combined", + config = + HomeRowConfig.ContinueWatchingCombined( + id = 0, + viewOptions = HomeRowViewOptions(), + ), + ), + ) + } + + @Test + fun `Check all types have a sample`() { + // This ensures there is a sample for each possible HomeRowConfig type + val foundTypes = mutableSetOf>() + SAMPLES.forEach { + when (it.config) { + is HomeRowConfig.ContinueWatching -> foundTypes.add(HomeRowConfig.ContinueWatching::class) + is HomeRowConfig.ContinueWatchingCombined -> foundTypes.add(HomeRowConfig.ContinueWatchingCombined::class) + is HomeRowConfig.Genres -> foundTypes.add(HomeRowConfig.Genres::class) + is HomeRowConfig.NextUp -> foundTypes.add(HomeRowConfig.NextUp::class) + is HomeRowConfig.RecentlyAdded -> foundTypes.add(HomeRowConfig.RecentlyAdded::class) + is HomeRowConfig.RecentlyReleased -> foundTypes.add(HomeRowConfig.RecentlyReleased::class) + } + } + Assert.assertEquals(HomeRowConfig::class.sealedSubclasses.size, foundTypes.size) + } + + @Test + fun `Print sample JSON`() { + // This just prints out the JSON of the samples so developers can review + val json = + Json { + ignoreUnknownKeys = true + isLenient = true + prettyPrint = true + } + val string = json.encodeToString(SAMPLES) + println(string) + json.decodeFromString>(string) + } +} From cd71d5b00f5706b001d2aa1fc967499b958f860d Mon Sep 17 00:00:00 2001 From: Damontecres Date: Fri, 23 Jan 2026 21:41:46 -0500 Subject: [PATCH 11/53] Support collections --- .../wholphin/data/model/HomeRowConfig.kt | 10 + .../ui/main/settings/HomePageSettings.kt | 368 ++++++++++-------- 2 files changed, 218 insertions(+), 160 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index d760d44512..27be82ca48 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -81,6 +81,16 @@ sealed class HomeRowConfig { ) : HomeRowConfig() { override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) } + + @Serializable + @SerialName("Collection") + data class Collection( + override val id: Int, + val collectionId: UUID, + override val viewOptions: HomeRowViewOptions, + ) : HomeRowConfig() { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + } } @Serializable diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt index 61a2ec2add..a94d56eaed 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt @@ -31,6 +31,7 @@ import com.github.damontecres.wholphin.data.model.BaseItem import com.github.damontecres.wholphin.data.model.HomeRowConfig import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay import com.github.damontecres.wholphin.data.model.HomeRowViewOptions +import com.github.damontecres.wholphin.preferences.HomePagePreferences import com.github.damontecres.wholphin.services.BackdropService import com.github.damontecres.wholphin.services.ImageUrlService import com.github.damontecres.wholphin.services.LatestNextUpService @@ -46,6 +47,7 @@ import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem import com.github.damontecres.wholphin.util.GetGenresRequestHandler import com.github.damontecres.wholphin.util.GetItemsRequestHandler import com.github.damontecres.wholphin.util.HomeRowLoadingState +import com.github.damontecres.wholphin.util.HomeRowLoadingState.Success import com.github.damontecres.wholphin.util.LoadingState import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext @@ -57,9 +59,11 @@ import org.jellyfin.sdk.api.client.extensions.userLibraryApi import org.jellyfin.sdk.model.api.CollectionType import org.jellyfin.sdk.model.api.ItemSortBy import org.jellyfin.sdk.model.api.SortOrder +import org.jellyfin.sdk.model.api.UserDto import org.jellyfin.sdk.model.api.request.GetGenresRequest import org.jellyfin.sdk.model.api.request.GetItemsRequest import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest +import org.jellyfin.sdk.model.serializer.toUUID import java.util.UUID import javax.inject.Inject @@ -145,7 +149,19 @@ class HomePageSettingsViewModel ), ) } - val rowConfig = continueWatchingRows + includedIds + val rowConfig = + continueWatchingRows + includedIds + + // TODO remove after testing + listOf( + HomeRowConfigDisplay( + "Collection", + HomeRowConfig.Collection( + 100, + "34ab6fd1f51c41bb014981f2e334f465".toUUID(), + HomeRowViewOptions(), + ), + ), + ) _state.update { it.copy(rows = rowConfig) } @@ -171,174 +187,206 @@ class HomePageSettingsViewModel .map { it.config } .map { row -> // TODO parallelize - when (row) { - is HomeRowConfig.ContinueWatching -> { - val resume = latestNextUpService.getResume(userDto.id, limit, true) - listOf( - HomeRowLoadingState.Success( - title = context.getString(R.string.continue_watching), - items = resume, - viewOptions = row.viewOptions, - ), - ) - } + parseRow(prefs, userDto, row, limit) + }.flatten() + } + rows?.let { rows -> + _state.update { + it.copy(loading = LoadingState.Success, rowData = rows) + } + } + } - is HomeRowConfig.NextUp -> { - val nextUp = - latestNextUpService.getNextUp( - userDto.id, - limit, - prefs.enableRewatchingNextUp, - false, - ) - listOf( - HomeRowLoadingState.Success( - title = context.getString(R.string.next_up), - items = nextUp, - viewOptions = row.viewOptions, - ), - ) - } + private suspend fun parseRow( + prefs: HomePagePreferences, + userDto: UserDto, + row: HomeRowConfig, + limit: Int, + ): List = + when (row) { + is HomeRowConfig.ContinueWatching -> { + val resume = latestNextUpService.getResume(userDto.id, limit, true) + listOf( + Success( + title = context.getString(R.string.continue_watching), + items = resume, + viewOptions = row.viewOptions, + ), + ) + } - is HomeRowConfig.ContinueWatchingCombined -> { - val resume = - latestNextUpService.getResume(userDto.id, limit, true) - val nextUp = - latestNextUpService.getNextUp( - userDto.id, - limit, - prefs.enableRewatchingNextUp, - false, - ) - - listOf( - HomeRowLoadingState.Success( - title = context.getString(R.string.continue_watching), - items = - latestNextUpService.buildCombined( - resume, - nextUp, - ), - viewOptions = row.viewOptions, - ), - ) - } + is HomeRowConfig.NextUp -> { + val nextUp = + latestNextUpService.getNextUp( + userDto.id, + limit, + prefs.enableRewatchingNextUp, + false, + ) + listOf( + Success( + title = context.getString(R.string.next_up), + items = nextUp, + viewOptions = row.viewOptions, + ), + ) + } - is HomeRowConfig.Genres -> { - val request = - GetGenresRequest( - parentId = row.parentId, - userId = userDto.id, - limit = limit, - ) - val items = - GetGenresRequestHandler - .execute(api, request) - .content.items - val genreIds = items.map { it.id } - val genreImages = - getGenreImageMap( - api = api, - imageUrlService = imageUrlService, - genres = genreIds, - parentId = row.parentId, - includeItemTypes = null, - cardWidthPx = null, - ) - val genres = - items.map { - BaseItem(it, false, genreImages[it.id]) - } - - val name = - _state.value.libraries - .firstOrNull { it.itemId == row.parentId } - ?.name - val title = - name?.let { context.getString(R.string.genres_in, it) } - ?: context.getString(R.string.genres) - listOf( - HomeRowLoadingState.Success( - title, - genres, - viewOptions = row.viewOptions, - ), - ) - } + is HomeRowConfig.ContinueWatchingCombined -> { + val resume = + latestNextUpService.getResume(userDto.id, limit, true) + val nextUp = + latestNextUpService.getNextUp( + userDto.id, + limit, + prefs.enableRewatchingNextUp, + false, + ) - is HomeRowConfig.RecentlyAdded -> { - val name = - _state.value.libraries - .firstOrNull { it.itemId == row.parentId } - ?.name - val title = - name?.let { context.getString(R.string.recently_added_in, it) } - ?: context.getString(R.string.recently_added) - val request = - GetLatestMediaRequest( - fields = SlimItemFields, - imageTypeLimit = 1, - parentId = row.parentId, - groupItems = true, - limit = limit, - isPlayed = null, // Server will handle user's preference - ) - val latest = - api.userLibraryApi - .getLatestMedia(request) - .content - .map { BaseItem.from(it, api, true) } - .let { - HomeRowLoadingState.Success( - title, - it, - row.viewOptions, - ) - } - listOf(latest) - } + listOf( + Success( + title = context.getString(R.string.continue_watching), + items = + latestNextUpService.buildCombined( + resume, + nextUp, + ), + viewOptions = row.viewOptions, + ), + ) + } - is HomeRowConfig.RecentlyReleased -> { - val name = - _state.value.libraries - .firstOrNull { it.itemId == row.parentId } - ?.name - val title = - name?.let { - context.getString(R.string.recently_released_in, it) - } ?: context.getString(R.string.recently_released) - val request = - GetItemsRequest( - parentId = row.parentId, - limit = limit, - sortBy = listOf(ItemSortBy.PREMIERE_DATE), - sortOrder = listOf(SortOrder.DESCENDING), - fields = DefaultItemFields, - recursive = true, - ) - GetItemsRequestHandler - .execute(api, request) - .content.items - .map { BaseItem.from(it, api, true) } - .let { - listOf( - HomeRowLoadingState.Success( - title, - it, - row.viewOptions, - ), - ) - } - } + is HomeRowConfig.Genres -> { + val request = + GetGenresRequest( + parentId = row.parentId, + userId = userDto.id, + limit = limit, + ) + val items = + GetGenresRequestHandler + .execute(api, request) + .content.items + val genreIds = items.map { it.id } + val genreImages = + getGenreImageMap( + api = api, + imageUrlService = imageUrlService, + genres = genreIds, + parentId = row.parentId, + includeItemTypes = null, + cardWidthPx = null, + ) + val genres = + items.map { + BaseItem(it, false, genreImages[it.id]) + } + + val name = + _state.value.libraries + .firstOrNull { it.itemId == row.parentId } + ?.name + val title = + name?.let { context.getString(R.string.genres_in, it) } + ?: context.getString(R.string.genres) + listOf( + Success( + title, + genres, + viewOptions = row.viewOptions, + ), + ) + } + + is HomeRowConfig.RecentlyAdded -> { + val name = + _state.value.libraries + .firstOrNull { it.itemId == row.parentId } + ?.name + val title = + name?.let { context.getString(R.string.recently_added_in, it) } + ?: context.getString(R.string.recently_added) + val request = + GetLatestMediaRequest( + fields = SlimItemFields, + imageTypeLimit = 1, + parentId = row.parentId, + groupItems = true, + limit = limit, + isPlayed = null, // Server will handle user's preference + ) + val latest = + api.userLibraryApi + .getLatestMedia(request) + .content + .map { BaseItem.from(it, api, true) } + .let { + Success( + title, + it, + row.viewOptions, + ) } - }.flatten() + listOf(latest) } - rows?.let { rows -> - _state.update { - it.copy(loading = LoadingState.Success, rowData = rows) + + is HomeRowConfig.RecentlyReleased -> { + val name = + _state.value.libraries + .firstOrNull { it.itemId == row.parentId } + ?.name + val title = + name?.let { + context.getString(R.string.recently_released_in, it) + } ?: context.getString(R.string.recently_released) + val request = + GetItemsRequest( + parentId = row.parentId, + limit = limit, + sortBy = listOf(ItemSortBy.PREMIERE_DATE), + sortOrder = listOf(SortOrder.DESCENDING), + fields = DefaultItemFields, + recursive = true, + ) + GetItemsRequestHandler + .execute(api, request) + .content.items + .map { BaseItem.from(it, api, true) } + .let { + listOf( + Success( + title, + it, + row.viewOptions, + ), + ) + } + } + + is HomeRowConfig.Collection -> { + val collection by api.userLibraryApi.getItem(itemId = row.collectionId) + val request = + GetItemsRequest( + parentId = row.collectionId, + limit = limit, + fields = DefaultItemFields, + recursive = true, + ) + GetItemsRequestHandler + .execute(api, request) + .content.items + .map { BaseItem.from(it, api, true) } + .let { + listOf( + Success( + collection.name ?: "", + it, + row.viewOptions, + ), + ) + } } } - } private fun List.move( direction: MoveDirection, From b2016bf9760678f70438b90e9e8c2745b6e2a22e Mon Sep 17 00:00:00 2001 From: Damontecres Date: Sat, 24 Jan 2026 14:46:00 -0500 Subject: [PATCH 12/53] Support different rows --- .../wholphin/data/model/HomeRowConfig.kt | 57 +++++++- .../ui/main/settings/HomePageSettings.kt | 78 ++++++++--- .../wholphin/test/TestHomeRowSamples.kt | 125 +++++++++--------- 3 files changed, 180 insertions(+), 80 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index 27be82ca48..cc60e43644 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -12,9 +12,11 @@ import com.github.damontecres.wholphin.ui.AspectRatio import com.github.damontecres.wholphin.ui.Cards import com.github.damontecres.wholphin.ui.components.ViewOptionImageType import com.github.damontecres.wholphin.ui.components.ViewOptions +import com.github.damontecres.wholphin.ui.data.SortAndDirection import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers +import org.jellyfin.sdk.model.api.request.GetItemsRequest import org.jellyfin.sdk.model.serializer.UUIDSerializer import java.util.UUID @@ -25,6 +27,9 @@ sealed class HomeRowConfig { abstract fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig + /** + * Continue watching media that the user has started but not finished + */ @Serializable @SerialName("ContinueWatching") data class ContinueWatching( @@ -34,6 +39,9 @@ sealed class HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) } + /** + * Next up row for next episodes in a series the user has started + */ @Serializable @SerialName("NextUp") data class NextUp( @@ -43,6 +51,9 @@ sealed class HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) } + /** + * Combined [ContinueWatching] and [NextUp] + */ @Serializable @SerialName("ContinueWatchingCombined") data class ContinueWatchingCombined( @@ -52,6 +63,9 @@ sealed class HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) } + /** + * Media recently added to a library + */ @Serializable @SerialName("RecentlyAdded") data class RecentlyAdded( @@ -62,6 +76,9 @@ sealed class HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) } + /** + * Media recently released (premiere date) in a library + */ @Serializable @SerialName("RecentlyReleased") data class RecentlyReleased( @@ -72,33 +89,65 @@ sealed class HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) } + /** + * Row of a genres in a library + */ @Serializable @SerialName("Genres") data class Genres( override val id: Int, val parentId: UUID, + override val viewOptions: HomeRowViewOptions = + HomeRowViewOptions( + heightDp = (Cards.HEIGHT_2X3_DP * .75f).toInt(), + aspectRatio = AspectRatio.WIDE, + ), + ) : HomeRowConfig() { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + } + + /** + * Fetch by parent ID such as a library, collection, or playlist with optional simple sorting + */ + @Serializable + @SerialName("ByParent") + data class ByParent( + override val id: Int, + val parentId: UUID, + val recursive: Boolean, + val sort: SortAndDirection? = null, override val viewOptions: HomeRowViewOptions, ) : HomeRowConfig() { override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) } + /** + * An arbitrary [GetItemsRequest] allowing to query for anything + */ @Serializable - @SerialName("Collection") - data class Collection( + @SerialName("GetItems") + data class GetItems( override val id: Int, - val collectionId: UUID, + val name: String?, + val getItems: GetItemsRequest, override val viewOptions: HomeRowViewOptions, ) : HomeRowConfig() { override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) } } -@Serializable data class HomeRowConfigDisplay( val title: String, val config: HomeRowConfig, ) +@Serializable +@SerialName("HomePageConfiguration") +data class HomePageConfiguration( + val version: Int = 1, + val rows: List, +) + @Serializable data class HomeRowViewOptions( val heightDp: Int = Cards.HEIGHT_2X3_DP, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt index a94d56eaed..4fae6901c2 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt @@ -36,8 +36,6 @@ import com.github.damontecres.wholphin.services.BackdropService import com.github.damontecres.wholphin.services.ImageUrlService import com.github.damontecres.wholphin.services.LatestNextUpService import com.github.damontecres.wholphin.services.UserPreferencesService -import com.github.damontecres.wholphin.ui.AspectRatio -import com.github.damontecres.wholphin.ui.Cards import com.github.damontecres.wholphin.ui.DefaultItemFields import com.github.damontecres.wholphin.ui.SlimItemFields import com.github.damontecres.wholphin.ui.components.getGenreImageMap @@ -155,10 +153,20 @@ class HomePageSettingsViewModel listOf( HomeRowConfigDisplay( "Collection", - HomeRowConfig.Collection( - 100, - "34ab6fd1f51c41bb014981f2e334f465".toUUID(), - HomeRowViewOptions(), + HomeRowConfig.ByParent( + id = 100, + parentId = "34ab6fd1f51c41bb014981f2e334f465".toUUID(), + recursive = true, + viewOptions = HomeRowViewOptions(), + ), + ), + HomeRowConfigDisplay( + "Playlist", + HomeRowConfig.ByParent( + id = 101, + parentId = "f94be36e9836127a0bccfc7843b19e5b".toUUID(), + recursive = true, + viewOptions = HomeRowViewOptions(), ), ), ) @@ -363,15 +371,59 @@ class HomePageSettingsViewModel } } - is HomeRowConfig.Collection -> { - val collection by api.userLibraryApi.getItem(itemId = row.collectionId) + is HomeRowConfig.ByParent -> { val request = GetItemsRequest( - parentId = row.collectionId, + userId = userDto.id, + parentId = row.parentId, + recursive = row.recursive, + sortBy = row.sort?.let { listOf(it.sort) }, + sortOrder = row.sort?.let { listOf(it.direction) }, limit = limit, fields = DefaultItemFields, - recursive = true, ) + val name = + api.userLibraryApi + .getItem(itemId = row.parentId) + .content.name + GetItemsRequestHandler + .execute(api, request) + .content.items + .map { BaseItem(it, true) } + .let { + listOf( + Success( + name ?: context.getString(R.string.collection), + it, + row.viewOptions, + ), + ) + } + } + + is HomeRowConfig.GetItems -> { + val request = + row.getItems.let { + if (it.limit == null) { + it.copy( + userId = userDto.id, + limit = limit, + ) + } else { + it.copy( + userId = userDto.id, + ) + } + } + val name = + if (row.name == null && request.parentId != null) { + // If a name was not provided, use the parent's name if available + api.userLibraryApi + .getItem(itemId = request.parentId!!) + .content.name + } else { + row.name + } GetItemsRequestHandler .execute(api, request) .content.items @@ -379,7 +431,7 @@ class HomePageSettingsViewModel .let { listOf( Success( - collection.name ?: "", + name ?: context.getString(R.string.collection), it, row.viewOptions, ), @@ -524,10 +576,6 @@ class HomePageSettingsViewModel HomeRowConfig.Genres( id, library.itemId, - HomeRowViewOptions( - heightDp = (Cards.HEIGHT_2X3_DP * .75f).toInt(), - aspectRatio = AspectRatio.WIDE, - ), ), ) } diff --git a/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt b/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt index ec3bf4ebe1..5ab69cadcf 100644 --- a/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt +++ b/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt @@ -1,13 +1,17 @@ package com.github.damontecres.wholphin.test import com.github.damontecres.wholphin.data.model.HomeRowConfig -import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay import com.github.damontecres.wholphin.data.model.HomeRowViewOptions import com.github.damontecres.wholphin.preferences.PrefContentScale import com.github.damontecres.wholphin.ui.AspectRatio import com.github.damontecres.wholphin.ui.components.ViewOptionImageType +import com.github.damontecres.wholphin.ui.data.SortAndDirection import kotlinx.serialization.json.Json import org.jellyfin.sdk.model.UUID +import org.jellyfin.sdk.model.api.BaseItemKind +import org.jellyfin.sdk.model.api.ItemSortBy +import org.jellyfin.sdk.model.api.SortOrder +import org.jellyfin.sdk.model.api.request.GetItemsRequest import org.junit.Assert import org.junit.Test import kotlin.reflect.KClass @@ -16,65 +20,62 @@ class TestHomeRowSamples { companion object { val SAMPLES = listOf( - HomeRowConfigDisplay( - title = "Recently added", - config = - HomeRowConfig.RecentlyAdded( - id = 0, - parentId = UUID.randomUUID(), - viewOptions = - HomeRowViewOptions( - heightDp = 100, - spacing = 8, - contentScale = PrefContentScale.CROP, - aspectRatio = AspectRatio.FOUR_THREE, - imageType = ViewOptionImageType.THUMB, - showTitles = false, - useSeries = false, - ), + HomeRowConfig.RecentlyAdded( + id = 0, + parentId = UUID.randomUUID(), + viewOptions = + HomeRowViewOptions( + heightDp = 100, + spacing = 8, + contentScale = PrefContentScale.CROP, + aspectRatio = AspectRatio.FOUR_THREE, + imageType = ViewOptionImageType.THUMB, + showTitles = false, + useSeries = false, ), ), - HomeRowConfigDisplay( - title = "Recently released", - config = - HomeRowConfig.RecentlyReleased( - id = 0, - parentId = UUID.randomUUID(), - viewOptions = HomeRowViewOptions(), - ), + HomeRowConfig.RecentlyReleased( + id = 0, + parentId = UUID.randomUUID(), + viewOptions = HomeRowViewOptions(), ), - HomeRowConfigDisplay( - title = "Genres", - config = - HomeRowConfig.Genres( - id = 0, - parentId = UUID.randomUUID(), - viewOptions = HomeRowViewOptions(), - ), + HomeRowConfig.Genres( + id = 0, + parentId = UUID.randomUUID(), + viewOptions = HomeRowViewOptions(), ), - HomeRowConfigDisplay( - title = "Continue watching", - config = - HomeRowConfig.ContinueWatching( - id = 0, - viewOptions = HomeRowViewOptions(), - ), + HomeRowConfig.ContinueWatching( + id = 0, + viewOptions = HomeRowViewOptions(), ), - HomeRowConfigDisplay( - title = "Next up", - config = - HomeRowConfig.NextUp( - id = 0, - viewOptions = HomeRowViewOptions(), - ), + HomeRowConfig.NextUp( + id = 0, + viewOptions = HomeRowViewOptions(), + ), + HomeRowConfig.ContinueWatchingCombined( + id = 0, + viewOptions = HomeRowViewOptions(), ), - HomeRowConfigDisplay( - title = "Combined", - config = - HomeRowConfig.ContinueWatchingCombined( - id = 0, - viewOptions = HomeRowViewOptions(), + HomeRowConfig.ByParent( + id = 0, + parentId = UUID.randomUUID(), + recursive = true, + sort = SortAndDirection(ItemSortBy.CRITIC_RATING, SortOrder.ASCENDING), + viewOptions = HomeRowViewOptions(), + ), + HomeRowConfig.GetItems( + id = 0, + name = "Episodes by date created", + getItems = + GetItemsRequest( + parentId = UUID.randomUUID(), + recursive = true, + isFavorite = true, + includeItemTypes = listOf(BaseItemKind.EPISODE), + sortBy = listOf(ItemSortBy.DATE_CREATED), + sortOrder = listOf(SortOrder.DESCENDING), ), + viewOptions = HomeRowViewOptions(), ), ) } @@ -84,13 +85,15 @@ class TestHomeRowSamples { // This ensures there is a sample for each possible HomeRowConfig type val foundTypes = mutableSetOf>() SAMPLES.forEach { - when (it.config) { - is HomeRowConfig.ContinueWatching -> foundTypes.add(HomeRowConfig.ContinueWatching::class) - is HomeRowConfig.ContinueWatchingCombined -> foundTypes.add(HomeRowConfig.ContinueWatchingCombined::class) - is HomeRowConfig.Genres -> foundTypes.add(HomeRowConfig.Genres::class) - is HomeRowConfig.NextUp -> foundTypes.add(HomeRowConfig.NextUp::class) - is HomeRowConfig.RecentlyAdded -> foundTypes.add(HomeRowConfig.RecentlyAdded::class) - is HomeRowConfig.RecentlyReleased -> foundTypes.add(HomeRowConfig.RecentlyReleased::class) + when (it) { + is HomeRowConfig.ContinueWatching -> foundTypes.add(it::class) + is HomeRowConfig.ContinueWatchingCombined -> foundTypes.add(it::class) + is HomeRowConfig.Genres -> foundTypes.add(it::class) + is HomeRowConfig.NextUp -> foundTypes.add(it::class) + is HomeRowConfig.RecentlyAdded -> foundTypes.add(it::class) + is HomeRowConfig.RecentlyReleased -> foundTypes.add(it::class) + is HomeRowConfig.ByParent -> foundTypes.add(it::class) + is HomeRowConfig.GetItems -> foundTypes.add(it::class) } } Assert.assertEquals(HomeRowConfig::class.sealedSubclasses.size, foundTypes.size) @@ -107,6 +110,6 @@ class TestHomeRowSamples { } val string = json.encodeToString(SAMPLES) println(string) - json.decodeFromString>(string) + json.decodeFromString>(string) } } From 84dc56289c3c25c0730d20be4cc469aa02e7b1a6 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Sat, 24 Jan 2026 14:51:09 -0500 Subject: [PATCH 13/53] Renaming --- ...wTypeList.kt => HomeLibraryRowTypeList.kt} | 2 +- .../settings/HomePageSettingsDestination.kt | 15 -- ...ePageRowSettings.kt => HomeRowSettings.kt} | 2 +- .../main/settings/HomeSettingsDestination.kt | 18 +++ ...raryList.kt => HomeSettingsLibraryList.kt} | 2 +- .../ui/main/settings/HomeSettingsPage.kt | 130 +++++++++++++++ ...ePageRowList.kt => HomeSettingsRowList.kt} | 2 +- ...geSettings.kt => HomeSettingsViewModel.kt} | 153 ++---------------- .../wholphin/ui/nav/DestinationContent.kt | 4 +- 9 files changed, 166 insertions(+), 162 deletions(-) rename app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/{HomePageLibraryRowTypeList.kt => HomeLibraryRowTypeList.kt} (98%) delete mode 100644 app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt rename app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/{HomePageRowSettings.kt => HomeRowSettings.kt} (98%) create mode 100644 app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt rename app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/{HomePageLibraryList.kt => HomeSettingsLibraryList.kt} (99%) create mode 100644 app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt rename app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/{HomePageRowList.kt => HomeSettingsRowList.kt} (99%) rename app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/{HomePageSettings.kt => HomeSettingsViewModel.kt} (81%) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryRowTypeList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeLibraryRowTypeList.kt similarity index 98% rename from app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryRowTypeList.kt rename to app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeLibraryRowTypeList.kt index 0206d46a63..421bc9bfe6 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryRowTypeList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeLibraryRowTypeList.kt @@ -24,7 +24,7 @@ import com.github.damontecres.wholphin.ui.ifElse import com.github.damontecres.wholphin.ui.tryRequestFocus @Composable -fun HomePageLibraryRowTypeList( +fun HomeLibraryRowTypeList( library: Library, onClick: (LibraryRowType) -> Unit, modifier: Modifier, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt deleted file mode 100644 index ddf1a2fcdd..0000000000 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettingsDestination.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.damontecres.wholphin.ui.main.settings - -sealed interface HomePageSettingsDestination { - data object RowList : HomePageSettingsDestination - - data object ChooseLibrary : HomePageSettingsDestination - - data class ChooseRowType( - val library: Library, - ) : HomePageSettingsDestination - - data class RowSettings( - val rowId: Int, - ) : HomePageSettingsDestination -} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt similarity index 98% rename from app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowSettings.kt rename to app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt index f8b2a1e68b..bf8e667688 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt @@ -17,7 +17,7 @@ import com.github.damontecres.wholphin.preferences.AppPreference import com.github.damontecres.wholphin.ui.preferences.ComposablePreference @Composable -fun HomePageRowSettings( +fun HomeRowSettings( title: String, viewOptions: HomeRowViewOptions, onViewOptionsChange: (HomeRowViewOptions) -> Unit, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt new file mode 100644 index 0000000000..10398755dd --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt @@ -0,0 +1,18 @@ +package com.github.damontecres.wholphin.ui.main.settings + +/** + * Tracking the pages for selecting and configuring rows + */ +sealed interface HomeSettingsDestination { + data object RowList : HomeSettingsDestination + + data object ChooseLibrary : HomeSettingsDestination + + data class ChooseRowType( + val library: Library, + ) : HomeSettingsDestination + + data class RowSettings( + val rowId: Int, + ) : HomeSettingsDestination +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsLibraryList.kt similarity index 99% rename from app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryList.kt rename to app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsLibraryList.kt index 66d8fd2842..998b634dca 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageLibraryList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsLibraryList.kt @@ -24,7 +24,7 @@ import com.github.damontecres.wholphin.ui.ifElse import com.github.damontecres.wholphin.ui.tryRequestFocus @Composable -fun HomePageLibraryList( +fun HomeSettingsLibraryList( libraries: List, onClick: (Library) -> Unit, onClickMeta: (MetaRowType) -> Unit, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt new file mode 100644 index 0000000000..7c226ba1a0 --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -0,0 +1,130 @@ +package com.github.damontecres.wholphin.ui.main.settings + +import androidx.activity.compose.BackHandler +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel +import androidx.tv.material3.MaterialTheme +import com.github.damontecres.wholphin.ui.main.HomePageContent + +val settingsWidth = 300.dp + +@Composable +fun HomeSettingsPage( + modifier: Modifier, + viewModel: HomeSettingsViewModel = hiltViewModel(), +) { + val state by viewModel.state.collectAsState() + val listState = rememberLazyListState() + var destination by remember { mutableStateOf(HomeSettingsDestination.RowList) } + + BackHandler(destination is HomeSettingsDestination.ChooseRowType) { + destination = HomeSettingsDestination.ChooseLibrary + } + BackHandler(destination is HomeSettingsDestination.ChooseLibrary) { + destination = HomeSettingsDestination.RowList + } + BackHandler(destination is HomeSettingsDestination.RowSettings) { + destination = HomeSettingsDestination.RowList + } + Row( + horizontalArrangement = Arrangement.spacedBy(8.dp), + modifier = modifier, + ) { + Box( + modifier = + Modifier + .width(settingsWidth) + .fillMaxHeight() + .background(color = MaterialTheme.colorScheme.surface), + ) { + val destModifier = + Modifier + .fillMaxSize() + .padding(4.dp) + when (val dest = destination) { + HomeSettingsDestination.RowList -> { + HomeSettingsRowList( + state = state, + onClickAdd = { destination = HomeSettingsDestination.ChooseLibrary }, + onClickMove = viewModel::moveRow, + onClickDelete = viewModel::deleteRow, + onClick = { index, row -> + destination = HomeSettingsDestination.RowSettings(row.config.id) + }, + modifier = destModifier, + ) + } + + is HomeSettingsDestination.ChooseLibrary -> { + HomeSettingsLibraryList( + libraries = state.libraries, + onClick = { destination = HomeSettingsDestination.ChooseRowType(it) }, + onClickMeta = { + viewModel.addRow(it) + destination = HomeSettingsDestination.RowList + }, + modifier = destModifier, + ) + } + + is HomeSettingsDestination.ChooseRowType -> { + HomeLibraryRowTypeList( + library = dest.library, + onClick = { + viewModel.addRow(dest.library, it) + destination = HomeSettingsDestination.RowList + }, + modifier = destModifier, + ) + } + + is HomeSettingsDestination.RowSettings -> { + val row = + state.rows + .first { it.config.id == dest.rowId } + HomeRowSettings( + title = row.title, + viewOptions = row.config.viewOptions, + onViewOptionsChange = { + viewModel.updateViewOptions(dest.rowId, it) + }, + onApplyApplyAll = { + viewModel.updateViewOptionsForAll(row.config.viewOptions) + }, + modifier = destModifier, + ) + } + } + } + HomePageContent( + loadingState = state.loading, + homeRows = state.rowData, + onClickItem = { _, _ -> }, + onLongClickItem = { _, _ -> }, + onClickPlay = { _, _ -> }, + showClock = false, + onUpdateBackdrop = viewModel::updateBackdrop, + listState = listState, + modifier = + Modifier + .fillMaxHeight() + .weight(1f), + ) + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt similarity index 99% rename from app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt rename to app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt index 6b42fbbe84..49842fca5a 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt @@ -41,7 +41,7 @@ enum class MoveDirection { } @Composable -fun HomePageRowList( +fun HomeSettingsRowList( state: HomePageSettingsState, onClick: (Int, HomeRowConfigDisplay) -> Unit, onClickAdd: () -> Unit, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt similarity index 81% rename from app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt rename to app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 4fae6901c2..275fe2025a 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomePageSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -1,29 +1,9 @@ package com.github.damontecres.wholphin.ui.main.settings import android.content.Context -import androidx.activity.compose.BackHandler -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.width -import androidx.compose.foundation.lazy.rememberLazyListState -import androidx.compose.runtime.Composable import androidx.compose.runtime.Immutable -import androidx.compose.runtime.collectAsState -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier -import androidx.compose.ui.unit.dp -import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import androidx.tv.material3.MaterialTheme import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.NavDrawerItemRepository import com.github.damontecres.wholphin.data.ServerRepository @@ -40,12 +20,10 @@ 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.launchIO -import com.github.damontecres.wholphin.ui.main.HomePageContent import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem import com.github.damontecres.wholphin.util.GetGenresRequestHandler import com.github.damontecres.wholphin.util.GetItemsRequestHandler import com.github.damontecres.wholphin.util.HomeRowLoadingState -import com.github.damontecres.wholphin.util.HomeRowLoadingState.Success import com.github.damontecres.wholphin.util.LoadingState import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext @@ -66,7 +44,7 @@ import java.util.UUID import javax.inject.Inject @HiltViewModel -class HomePageSettingsViewModel +class HomeSettingsViewModel @Inject constructor( @param:ApplicationContext private val context: Context, @@ -215,7 +193,7 @@ class HomePageSettingsViewModel is HomeRowConfig.ContinueWatching -> { val resume = latestNextUpService.getResume(userDto.id, limit, true) listOf( - Success( + HomeRowLoadingState.Success( title = context.getString(R.string.continue_watching), items = resume, viewOptions = row.viewOptions, @@ -232,7 +210,7 @@ class HomePageSettingsViewModel false, ) listOf( - Success( + HomeRowLoadingState.Success( title = context.getString(R.string.next_up), items = nextUp, viewOptions = row.viewOptions, @@ -252,7 +230,7 @@ class HomePageSettingsViewModel ) listOf( - Success( + HomeRowLoadingState.Success( title = context.getString(R.string.continue_watching), items = latestNextUpService.buildCombined( @@ -298,7 +276,7 @@ class HomePageSettingsViewModel name?.let { context.getString(R.string.genres_in, it) } ?: context.getString(R.string.genres) listOf( - Success( + HomeRowLoadingState.Success( title, genres, viewOptions = row.viewOptions, @@ -327,9 +305,9 @@ class HomePageSettingsViewModel api.userLibraryApi .getLatestMedia(request) .content - .map { BaseItem.from(it, api, true) } + .map { BaseItem.Companion.from(it, api, true) } .let { - Success( + HomeRowLoadingState.Success( title, it, row.viewOptions, @@ -359,10 +337,10 @@ class HomePageSettingsViewModel GetItemsRequestHandler .execute(api, request) .content.items - .map { BaseItem.from(it, api, true) } + .map { BaseItem.Companion.from(it, api, true) } .let { listOf( - Success( + HomeRowLoadingState.Success( title, it, row.viewOptions, @@ -392,7 +370,7 @@ class HomePageSettingsViewModel .map { BaseItem(it, true) } .let { listOf( - Success( + HomeRowLoadingState.Success( name ?: context.getString(R.string.collection), it, row.viewOptions, @@ -427,10 +405,10 @@ class HomePageSettingsViewModel GetItemsRequestHandler .execute(api, request) .content.items - .map { BaseItem.from(it, api, true) } + .map { BaseItem.Companion.from(it, api, true) } .let { listOf( - Success( + HomeRowLoadingState.Success( name ?: context.getString(R.string.collection), it, row.viewOptions, @@ -662,110 +640,3 @@ data class Library( val name: String, val collectionType: CollectionType, ) - -val settingsWidth = 300.dp - -@Composable -fun HomePageSettings( - modifier: Modifier, - viewModel: HomePageSettingsViewModel = hiltViewModel(), -) { - val state by viewModel.state.collectAsState() - val listState = rememberLazyListState() - var destination by remember { mutableStateOf(HomePageSettingsDestination.RowList) } - - BackHandler(destination is HomePageSettingsDestination.ChooseRowType) { - destination = HomePageSettingsDestination.ChooseLibrary - } - BackHandler(destination is HomePageSettingsDestination.ChooseLibrary) { - destination = HomePageSettingsDestination.RowList - } - BackHandler(destination is HomePageSettingsDestination.RowSettings) { - destination = HomePageSettingsDestination.RowList - } - Row( - horizontalArrangement = Arrangement.spacedBy(8.dp), - modifier = modifier, - ) { - Box( - modifier = - Modifier - .width(settingsWidth) - .fillMaxHeight() - .background(color = MaterialTheme.colorScheme.surface), - ) { - val destModifier = - Modifier - .fillMaxSize() - .padding(4.dp) - when (val dest = destination) { - HomePageSettingsDestination.RowList -> { - HomePageRowList( - state = state, - onClickAdd = { destination = HomePageSettingsDestination.ChooseLibrary }, - onClickMove = viewModel::moveRow, - onClickDelete = viewModel::deleteRow, - onClick = { index, row -> - destination = HomePageSettingsDestination.RowSettings(row.config.id) - }, - modifier = destModifier, - ) - } - - is HomePageSettingsDestination.ChooseLibrary -> { - HomePageLibraryList( - libraries = state.libraries, - onClick = { destination = HomePageSettingsDestination.ChooseRowType(it) }, - onClickMeta = { - viewModel.addRow(it) - destination = HomePageSettingsDestination.RowList - }, - modifier = destModifier, - ) - } - - is HomePageSettingsDestination.ChooseRowType -> { - HomePageLibraryRowTypeList( - library = dest.library, - onClick = { - viewModel.addRow(dest.library, it) - destination = HomePageSettingsDestination.RowList - }, - modifier = destModifier, - ) - } - - is HomePageSettingsDestination.RowSettings -> { - val row = - state.rows - .first { it.config.id == dest.rowId } - HomePageRowSettings( - title = row.title, - viewOptions = row.config.viewOptions, - onViewOptionsChange = { - viewModel.updateViewOptions(dest.rowId, it) - }, - onApplyApplyAll = { - viewModel.updateViewOptionsForAll(row.config.viewOptions) - }, - modifier = destModifier, - ) - } - } - } - HomePageContent( - loadingState = state.loading, - homeRows = state.rowData, - onClickItem = { _, _ -> }, - onLongClickItem = { _, _ -> }, - onClickPlay = { _, _ -> }, - showClock = false, - onUpdateBackdrop = viewModel::updateBackdrop, - listState = listState, - modifier = - Modifier - .fillMaxHeight() - .weight(1f), - ) - } -} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/nav/DestinationContent.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/nav/DestinationContent.kt index b4ef4575a1..63010fde23 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/nav/DestinationContent.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/nav/DestinationContent.kt @@ -32,7 +32,7 @@ import com.github.damontecres.wholphin.ui.detail.series.SeriesOverview import com.github.damontecres.wholphin.ui.discover.DiscoverPage import com.github.damontecres.wholphin.ui.main.HomePage import com.github.damontecres.wholphin.ui.main.SearchPage -import com.github.damontecres.wholphin.ui.main.settings.HomePageSettings +import com.github.damontecres.wholphin.ui.main.settings.HomeSettingsPage import com.github.damontecres.wholphin.ui.playback.PlaybackPage import com.github.damontecres.wholphin.ui.preferences.PreferencesPage import com.github.damontecres.wholphin.ui.setup.InstallUpdatePage @@ -62,7 +62,7 @@ fun DestinationContent( } is Destination.HomeSettings -> { - HomePageSettings(modifier) + HomeSettingsPage(modifier) } is Destination.PlaybackList, From ee8a4ac0ac56e8aeeb059b66db0614e1731a7559 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Sat, 24 Jan 2026 16:05:33 -0500 Subject: [PATCH 14/53] Basic save/load locally --- .../wholphin/data/model/HomeRowConfig.kt | 8 +- .../wholphin/services/HomeSettingsService.kt | 102 +++++++ .../damontecres/wholphin/ui/main/HomePage.kt | 59 +++-- .../ui/main/settings/HomeRowSettings.kt | 19 +- .../main/settings/HomeSettingsDestination.kt | 4 +- .../ui/main/settings/HomeSettingsPage.kt | 14 +- .../ui/main/settings/HomeSettingsRowList.kt | 60 ++++- .../ui/main/settings/HomeSettingsViewModel.kt | 249 +++++++++++++----- 8 files changed, 392 insertions(+), 123 deletions(-) create mode 100644 app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index cc60e43644..7c1faf745f 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -99,7 +99,7 @@ sealed class HomeRowConfig { val parentId: UUID, override val viewOptions: HomeRowViewOptions = HomeRowViewOptions( - heightDp = (Cards.HEIGHT_2X3_DP * .75f).toInt(), + heightDp = (Cards.HEIGHT_2X3_DP * .75f).toInt().let { it - it % 4 }, aspectRatio = AspectRatio.WIDE, ), ) : HomeRowConfig() { @@ -128,7 +128,7 @@ sealed class HomeRowConfig { @SerialName("GetItems") data class GetItems( override val id: Int, - val name: String?, + val name: String, val getItems: GetItemsRequest, override val viewOptions: HomeRowViewOptions, ) : HomeRowConfig() { @@ -142,8 +142,8 @@ data class HomeRowConfigDisplay( ) @Serializable -@SerialName("HomePageConfiguration") -data class HomePageConfiguration( +@SerialName("HomePageSettings") +data class HomePageSettings( val version: Int = 1, val rows: List, ) diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt new file mode 100644 index 0000000000..31744ddab9 --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -0,0 +1,102 @@ +package com.github.damontecres.wholphin.services + +import android.content.Context +import com.github.damontecres.wholphin.R +import com.github.damontecres.wholphin.data.ServerRepository +import com.github.damontecres.wholphin.data.model.HomePageSettings +import com.github.damontecres.wholphin.ui.toServerString +import dagger.hilt.android.qualifiers.ApplicationContext +import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.decodeFromStream +import kotlinx.serialization.json.encodeToStream +import org.jellyfin.sdk.api.client.ApiClient +import org.jellyfin.sdk.api.client.extensions.displayPreferencesApi +import org.jellyfin.sdk.model.UUID +import java.io.File +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class HomeSettingsService + @Inject + constructor( + @param:ApplicationContext private val context: Context, + private val api: ApiClient, + private val serverRepository: ServerRepository, + ) { + val jsonParser = + Json { + isLenient = true + ignoreUnknownKeys = true + } + + suspend fun saveToServer( + settings: HomePageSettings, + displayPreferencesId: String = DISPLAY_PREF_ID, + ) { + serverRepository.currentUser.value?.let { user -> + val current = getDisplayPreferences(user.id, DISPLAY_PREF_ID) + val customPrefs = + current.customPrefs.toMutableMap().apply { + put(CUSTOM_PREF_ID, jsonParser.encodeToString(settings)) + } + api.displayPreferencesApi.updateDisplayPreferences( + displayPreferencesId = displayPreferencesId, + userId = user.id, + client = context.getString(R.string.app_name), + data = current.copy(customPrefs = customPrefs), + ) + } + } + + suspend fun loadFromServer(displayPreferencesId: String = DISPLAY_PREF_ID): HomePageSettings? = + serverRepository.currentUser.value?.let { user -> + val current = getDisplayPreferences(user.id, displayPreferencesId) + current.customPrefs[DISPLAY_PREF_ID]?.let { + Json.decodeFromString(it) + } + } + + private suspend fun getDisplayPreferences( + userId: UUID, + displayPreferencesId: String, + ) = api.displayPreferencesApi + .getDisplayPreferences( + userId = userId, + displayPreferencesId = displayPreferencesId, + client = context.getString(R.string.app_name), + ).content + + private fun filename(userId: UUID) = "${CUSTOM_PREF_ID}_${userId.toServerString()}.json" + + @OptIn(ExperimentalSerializationApi::class) + suspend fun saveToLocal(settings: HomePageSettings) { + serverRepository.currentUser.value?.let { user -> + val dir = File(context.filesDir, CUSTOM_PREF_ID) + dir.mkdirs() + File(dir, filename(user.id)).outputStream().use { + jsonParser.encodeToStream(settings, it) + } + } + } + + @OptIn(ExperimentalSerializationApi::class) + suspend fun loadFromLocal(): HomePageSettings? = + serverRepository.currentUser.value?.let { user -> + val dir = File(context.filesDir, CUSTOM_PREF_ID) + val file = File(dir, filename(user.id)) + if (file.exists()) { + file.inputStream().use { + jsonParser.decodeFromStream(it) + } + } else { + null + } + } + + companion object { + const val DISPLAY_PREF_ID = "default" + const val CUSTOM_PREF_ID = "home_settings" + } + } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt index dbcf8fb02d..3bcea534cb 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt @@ -195,6 +195,7 @@ fun HomePageContent( onFocusPosition: ((RowColumn) -> Unit)? = null, loadingState: LoadingState? = null, listState: LazyListState = rememberLazyListState(), + takeFocus: Boolean = true, ) { var position by rememberPosition() val focusedItem = @@ -204,22 +205,24 @@ fun HomePageContent( val rowFocusRequesters = remember(homeRows) { List(homeRows.size) { FocusRequester() } } var firstFocused by remember { mutableStateOf(false) } - LaunchedEffect(homeRows) { - if (!firstFocused) { - if (position.row >= 0) { - rowFocusRequesters[position.row].tryRequestFocus() - firstFocused = true - } else { - // Waiting for the first home row to load, then focus on it - homeRows - .indexOfFirst { it is HomeRowLoadingState.Success && it.items.isNotEmpty() } - .takeIf { it >= 0 } - ?.let { - rowFocusRequesters[it].tryRequestFocus() - firstFocused = true - delay(50) - listState.scrollToItem(it) - } + if (takeFocus) { + LaunchedEffect(homeRows) { + if (!firstFocused) { + if (position.row >= 0) { + rowFocusRequesters[position.row].tryRequestFocus() + firstFocused = true + } else { + // Waiting for the first home row to load, then focus on it + homeRows + .indexOfFirst { it is HomeRowLoadingState.Success && it.items.isNotEmpty() } + .takeIf { it >= 0 } + ?.let { + rowFocusRequesters[it].tryRequestFocus() + firstFocused = true + delay(50) + listState.scrollToItem(it) + } + } } } } @@ -421,19 +424,17 @@ fun HomePageHeader( item: BaseItem?, modifier: Modifier = Modifier, ) { - item?.let { - val isEpisode = item.type == BaseItemKind.EPISODE - val dto = item.data - HomePageHeader( - title = item.title, - subtitle = if (isEpisode) dto.name else null, - overview = dto.overview, - overviewTwoLines = isEpisode, - quickDetails = item.ui.quickDetails, - timeRemaining = item.timeRemainingOrRuntime, - modifier = modifier, - ) - } + val isEpisode = item?.type == BaseItemKind.EPISODE + val dto = item?.data + HomePageHeader( + title = item?.title, + subtitle = if (isEpisode) dto?.name else null, + overview = dto?.overview, + overviewTwoLines = isEpisode, + quickDetails = item?.ui?.quickDetails ?: AnnotatedString(""), + timeRemaining = item?.timeRemainingOrRuntime, + modifier = modifier, + ) } @Composable diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt index bf8e667688..5946fe4b01 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt @@ -4,17 +4,22 @@ import androidx.compose.foundation.background import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Column import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.unit.dp import androidx.tv.material3.MaterialTheme import androidx.tv.material3.Text import androidx.tv.material3.surfaceColorAtElevation import com.github.damontecres.wholphin.data.model.HomeRowViewOptions import com.github.damontecres.wholphin.preferences.AppPreference +import com.github.damontecres.wholphin.ui.ifElse import com.github.damontecres.wholphin.ui.preferences.ComposablePreference +import com.github.damontecres.wholphin.ui.tryRequestFocus @Composable fun HomeRowSettings( @@ -25,6 +30,8 @@ fun HomeRowSettings( modifier: Modifier = Modifier, defaultViewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) { + val firstFocus = remember { FocusRequester() } + LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } Column(modifier = modifier) { Text( text = title, @@ -32,7 +39,7 @@ fun HomeRowSettings( color = MaterialTheme.colorScheme.onSurface, ) LazyColumn { - items(HomeRowViewOptions.OPTIONS) { pref -> + itemsIndexed(HomeRowViewOptions.OPTIONS) { index, pref -> pref as AppPreference val interactionSource = remember { MutableInteractionSource() } val value = pref.getter.invoke(viewOptions) @@ -51,7 +58,13 @@ fun HomeRowSettings( onApplyApplyAll.invoke() } }, - modifier = Modifier.background(MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)), + modifier = + Modifier + .background( + MaterialTheme.colorScheme.surfaceColorAtElevation( + 5.dp, + ), + ).ifElse(index == 0, Modifier.focusRequester(firstFocus)), ) } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt index 10398755dd..c08fe1f676 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt @@ -1,9 +1,11 @@ package com.github.damontecres.wholphin.ui.main.settings +import androidx.navigation3.runtime.NavKey + /** * Tracking the pages for selecting and configuring rows */ -sealed interface HomeSettingsDestination { +sealed interface HomeSettingsDestination : NavKey { data object RowList : HomeSettingsDestination data object ChooseLibrary : HomeSettingsDestination diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index 7c226ba1a0..72cfa7a711 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -15,12 +15,16 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel import androidx.tv.material3.MaterialTheme import com.github.damontecres.wholphin.ui.main.HomePageContent +import com.github.damontecres.wholphin.util.ExceptionHandler +import kotlinx.coroutines.launch +import timber.log.Timber val settingsWidth = 300.dp @@ -29,10 +33,12 @@ fun HomeSettingsPage( modifier: Modifier, viewModel: HomeSettingsViewModel = hiltViewModel(), ) { - val state by viewModel.state.collectAsState() + val scope = rememberCoroutineScope() val listState = rememberLazyListState() var destination by remember { mutableStateOf(HomeSettingsDestination.RowList) } + val state by viewModel.state.collectAsState() + BackHandler(destination is HomeSettingsDestination.ChooseRowType) { destination = HomeSettingsDestination.ChooseLibrary } @@ -62,10 +68,15 @@ fun HomeSettingsPage( HomeSettingsRowList( state = state, onClickAdd = { destination = HomeSettingsDestination.ChooseLibrary }, + onClickSaveLocal = { viewModel.saveToLocal() }, onClickMove = viewModel::moveRow, onClickDelete = viewModel::deleteRow, onClick = { index, row -> destination = HomeSettingsDestination.RowSettings(row.config.id) + scope.launch(ExceptionHandler()) { + Timber.v("Scroll to $index") + listState.scrollToItem(index) + } }, modifier = destModifier, ) @@ -121,6 +132,7 @@ fun HomeSettingsPage( showClock = false, onUpdateBackdrop = viewModel::updateBackdrop, listState = listState, + takeFocus = false, modifier = Modifier .fillMaxHeight() diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt index 49842fca5a..b1e72e92fc 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt @@ -13,8 +13,12 @@ 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 import androidx.compose.material.icons.filled.Delete +import androidx.compose.material3.HorizontalDivider import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -33,7 +37,7 @@ import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay import com.github.damontecres.wholphin.ui.FontAwesome import com.github.damontecres.wholphin.ui.components.Button -import com.github.damontecres.wholphin.ui.ifElse +import com.github.damontecres.wholphin.ui.tryRequestFocus enum class MoveDirection { UP, @@ -44,12 +48,14 @@ enum class MoveDirection { fun HomeSettingsRowList( state: HomePageSettingsState, onClick: (Int, HomeRowConfigDisplay) -> Unit, + onClickSaveLocal: () -> Unit, onClickAdd: () -> Unit, onClickMove: (MoveDirection, Int) -> Unit, onClickDelete: (Int) -> Unit, modifier: Modifier, firstFocus: FocusRequester = remember { FocusRequester() }, ) { + LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } Column(modifier = modifier) { LazyColumn( verticalArrangement = Arrangement.spacedBy(8.dp), @@ -58,6 +64,45 @@ fun HomeSettingsRowList( .fillMaxHeight() .focusRestorer(firstFocus), ) { + item { + ListItem( + selected = false, + headlineContent = { + Text( + text = stringResource(R.string.add_row), + ) + }, + leadingContent = { + Icon( + imageVector = Icons.Default.Add, + contentDescription = null, + ) + }, + onClick = onClickAdd, + modifier = Modifier.focusRequester(firstFocus), + ) + } + item { + ListItem( + selected = false, + headlineContent = { + Text( + text = stringResource(R.string.save), + ) + }, + leadingContent = { + Icon( + imageVector = Icons.Default.Create, + contentDescription = null, + ) + }, + onClick = onClickSaveLocal, + modifier = Modifier, + ) + } + item { + HorizontalDivider() + } itemsIndexed(state.rows, key = { _, row -> row.config.id }) { index, row -> HomeRowConfigContent( config = row, @@ -69,20 +114,9 @@ fun HomeSettingsRowList( onClick = { onClick.invoke(index, row) }, modifier = Modifier - .fillMaxWidth() - .ifElse(index == 0, Modifier.focusRequester(firstFocus)), + .fillMaxWidth(), ) } - item { - Button( - onClick = onClickAdd, - modifier = Modifier.ifElse(state.rows.isEmpty(), Modifier.focusRequester(firstFocus)), - ) { - Text( - text = stringResource(R.string.add_row), - ) - } - } } } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 275fe2025a..623a18c1a0 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -1,6 +1,7 @@ package com.github.damontecres.wholphin.ui.main.settings import android.content.Context +import android.widget.Toast import androidx.compose.runtime.Immutable import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope @@ -8,11 +9,13 @@ import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.NavDrawerItemRepository import com.github.damontecres.wholphin.data.ServerRepository import com.github.damontecres.wholphin.data.model.BaseItem +import com.github.damontecres.wholphin.data.model.HomePageSettings import com.github.damontecres.wholphin.data.model.HomeRowConfig import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay import com.github.damontecres.wholphin.data.model.HomeRowViewOptions import com.github.damontecres.wholphin.preferences.HomePagePreferences import com.github.damontecres.wholphin.services.BackdropService +import com.github.damontecres.wholphin.services.HomeSettingsService import com.github.damontecres.wholphin.services.ImageUrlService import com.github.damontecres.wholphin.services.LatestNextUpService import com.github.damontecres.wholphin.services.UserPreferencesService @@ -21,6 +24,7 @@ import com.github.damontecres.wholphin.ui.SlimItemFields import com.github.damontecres.wholphin.ui.components.getGenreImageMap import com.github.damontecres.wholphin.ui.launchIO import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem +import com.github.damontecres.wholphin.ui.showToast import com.github.damontecres.wholphin.util.GetGenresRequestHandler import com.github.damontecres.wholphin.util.GetItemsRequestHandler import com.github.damontecres.wholphin.util.HomeRowLoadingState @@ -40,6 +44,7 @@ import org.jellyfin.sdk.model.api.request.GetGenresRequest import org.jellyfin.sdk.model.api.request.GetItemsRequest import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest import org.jellyfin.sdk.model.serializer.toUUID +import timber.log.Timber import java.util.UUID import javax.inject.Inject @@ -49,6 +54,7 @@ class HomeSettingsViewModel constructor( @param:ApplicationContext private val context: Context, private val api: ApiClient, + private val homeSettingsService: HomeSettingsService, private val serverRepository: ServerRepository, private val userPreferencesService: UserPreferencesService, private val navDrawerItemRepository: NavDrawerItemRepository, @@ -73,91 +79,176 @@ class HomeSettingsViewModel } _state.update { it.copy(libraries = libraries) } - // TODO get config + val localSettings = + try { + homeSettingsService.loadFromLocal() + } catch (ex: Exception) { + Timber.e(ex) + showToast(context, "Error loading settings: ${ex.localizedMessage}") + null + } + if (localSettings != null) { + val displays = localSettings.rows.map { convert(it) } + _state.update { + it.copy(rows = displays) + } + } else { - // Or create default - val prefs = userPreferencesService.getCurrent().appPreferences.homePagePreferences - val includedIds = - navDrawerItemRepository - .getFilteredNavDrawerItems(navDrawerItems) - .filter { it is ServerNavDrawerItem } - .mapIndexed { index, it -> - val id = (it as ServerNavDrawerItem).itemId - val name = libraries.firstOrNull { it.itemId == id }?.name - val title = - name?.let { context.getString(R.string.recently_added_in, it) } - ?: context.getString(R.string.recently_added) - HomeRowConfigDisplay( - title, - HomeRowConfig.RecentlyAdded( - index, - id, - HomeRowViewOptions(), + // Or create default + val prefs = + userPreferencesService.getCurrent().appPreferences.homePagePreferences + val includedIds = + navDrawerItemRepository + .getFilteredNavDrawerItems(navDrawerItems) + .filter { it is ServerNavDrawerItem } + .mapIndexed { index, it -> + val id = (it as ServerNavDrawerItem).itemId + val name = libraries.firstOrNull { it.itemId == id }?.name + val title = + name?.let { context.getString(R.string.recently_added_in, it) } + ?: context.getString(R.string.recently_added) + HomeRowConfigDisplay( + title, + HomeRowConfig.RecentlyAdded( + index, + id, + HomeRowViewOptions(), + ), + ) + } + val continueWatchingRows = + if (prefs.combineContinueNext) { + listOf( + HomeRowConfigDisplay( + context.getString(R.string.combine_continue_next), + HomeRowConfig.ContinueWatchingCombined( + includedIds.size + 1, + HomeRowViewOptions(), + ), ), ) - } - val continueWatchingRows = - if (prefs.combineContinueNext) { - listOf( - HomeRowConfigDisplay( - context.getString(R.string.combine_continue_next), - HomeRowConfig.ContinueWatchingCombined( - includedIds.size + 1, - HomeRowViewOptions(), - ), - ), - ) - } else { - listOf( - HomeRowConfigDisplay( - context.getString(R.string.continue_watching), - HomeRowConfig.ContinueWatching( - includedIds.size + 1, - HomeRowViewOptions(), + } else { + listOf( + HomeRowConfigDisplay( + context.getString(R.string.continue_watching), + HomeRowConfig.ContinueWatching( + includedIds.size + 1, + HomeRowViewOptions(), + ), ), - ), - HomeRowConfigDisplay( - context.getString(R.string.next_up), - HomeRowConfig.NextUp( - includedIds.size + 2, - HomeRowViewOptions(), + HomeRowConfigDisplay( + context.getString(R.string.next_up), + HomeRowConfig.NextUp( + includedIds.size + 2, + HomeRowViewOptions(), + ), ), - ), - ) - } - val rowConfig = - continueWatchingRows + includedIds + - // TODO remove after testing - listOf( - HomeRowConfigDisplay( - "Collection", - HomeRowConfig.ByParent( - id = 100, - parentId = "34ab6fd1f51c41bb014981f2e334f465".toUUID(), - recursive = true, - viewOptions = HomeRowViewOptions(), + ) + } + val rowConfig = + continueWatchingRows + includedIds + + // TODO remove after testing + listOf( + HomeRowConfigDisplay( + "Collection", + HomeRowConfig.ByParent( + id = 100, + parentId = "34ab6fd1f51c41bb014981f2e334f465".toUUID(), + recursive = true, + viewOptions = HomeRowViewOptions(), + ), ), - ), - HomeRowConfigDisplay( - "Playlist", - HomeRowConfig.ByParent( - id = 101, - parentId = "f94be36e9836127a0bccfc7843b19e5b".toUUID(), - recursive = true, - viewOptions = HomeRowViewOptions(), + HomeRowConfigDisplay( + "Playlist", + HomeRowConfig.ByParent( + id = 101, + parentId = "f94be36e9836127a0bccfc7843b19e5b".toUUID(), + recursive = true, + viewOptions = HomeRowViewOptions(), + ), ), - ), - ) - _state.update { - it.copy(rows = rowConfig) + ) + _state.update { + it.copy(rows = rowConfig) + } } -// val json = Json.encodeToString(rowConfig) -// Timber.v("json=$json") fetchRowData() } } + private suspend fun convert(config: HomeRowConfig): HomeRowConfigDisplay = + when (config) { + is HomeRowConfig.ByParent -> { + val name = + api.userLibraryApi + .getItem(itemId = config.parentId) + .content.name ?: "" + HomeRowConfigDisplay( + name, + config, + ) + } + + is HomeRowConfig.ContinueWatching -> { + HomeRowConfigDisplay( + context.getString(R.string.continue_watching), + config, + ) + } + + is HomeRowConfig.ContinueWatchingCombined -> { + HomeRowConfigDisplay( + context.getString(R.string.combine_continue_next), + config, + ) + } + + is HomeRowConfig.Genres -> { + val name = + api.userLibraryApi + .getItem(itemId = config.parentId) + .content.name ?: "" + HomeRowConfigDisplay( + context.getString(R.string.genres_in, name), + config, + ) + } + + is HomeRowConfig.GetItems -> { + HomeRowConfigDisplay(config.name, config) + } + + is HomeRowConfig.NextUp -> { + HomeRowConfigDisplay( + context.getString(R.string.next_up), + config, + ) + } + + is HomeRowConfig.RecentlyAdded -> { + val name = + api.userLibraryApi + .getItem(itemId = config.parentId) + .content.name ?: "" + HomeRowConfigDisplay( + context.getString(R.string.recently_added_in, name), + config, + ) + } + + is HomeRowConfig.RecentlyReleased -> { + val name = + api.userLibraryApi + .getItem(itemId = config.parentId) + .content.name ?: "" + HomeRowConfigDisplay( + context.getString(R.string.recently_released_in, name), + config, + ) + } + } + fun updateBackdrop(item: BaseItem) { viewModelScope.launchIO { backdropService.submit(item) @@ -615,6 +706,20 @@ class HomeSettingsViewModel ) } } + + fun saveToLocal() { + viewModelScope.launchIO { + val rows = state.value.rows.map { it.config } + val settings = HomePageSettings(rows = rows) + try { + homeSettingsService.saveToLocal(settings) + showToast(context, context.getString(R.string.save), Toast.LENGTH_SHORT) + } catch (ex: Exception) { + Timber.e(ex) + showToast(context, "Error saving: ${ex.localizedMessage}") + } + } + } } data class HomePageSettingsState( From a174d981a86470ea706d14031073907cc8199bc5 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Sat, 24 Jan 2026 18:27:58 -0500 Subject: [PATCH 15/53] Refactoring to expose current configuration --- .../wholphin/data/ServerRepository.kt | 22 -- .../wholphin/data/model/HomeRowConfig.kt | 16 +- .../wholphin/services/HomeSettingsService.kt | 262 +++++++++++++++--- .../services/SeerrServerRepository.kt | 83 +++--- .../ui/main/settings/HomeSettingsViewModel.kt | 196 ++----------- 5 files changed, 311 insertions(+), 268 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/ServerRepository.kt b/app/src/main/java/com/github/damontecres/wholphin/data/ServerRepository.kt index c0cd962da8..f66dcfca0c 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/ServerRepository.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/ServerRepository.kt @@ -18,7 +18,6 @@ import kotlinx.coroutines.withContext import kotlinx.serialization.Serializable import org.jellyfin.sdk.Jellyfin import org.jellyfin.sdk.api.client.ApiClient -import org.jellyfin.sdk.api.client.extensions.displayPreferencesApi import org.jellyfin.sdk.api.client.extensions.systemApi import org.jellyfin.sdk.api.client.extensions.userApi import org.jellyfin.sdk.model.api.AuthenticationResult @@ -103,27 +102,6 @@ class ServerRepository currentUserId = updatedUser.id.toServerString() }.build() } - val settings = - apiClient.displayPreferencesApi - .getDisplayPreferences( - displayPreferencesId = "settings", - userId = user.id, - client = "wholphin", - ).content - val newSettings = - settings.copy( - customPrefs = - settings.customPrefs.toMutableMap().apply { - put("test_key", "test_value") - }, - ) - apiClient.displayPreferencesApi.updateDisplayPreferences( - displayPreferencesId = "settings", - userId = user.id, - client = "wholphin", - data = newSettings, - ) - Timber.v("settings=$settings") withContext(Dispatchers.Main) { _current.value = CurrentUser(updatedServer, updatedUser) _currentUserDto.value = userDto diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index 7c1faf745f..13d9678501 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -144,9 +144,21 @@ data class HomeRowConfigDisplay( @Serializable @SerialName("HomePageSettings") data class HomePageSettings( - val version: Int = 1, val rows: List, -) + val version: Int = 1, +) { + companion object { + val EMPTY = HomePageSettings(listOf()) + } +} + +data class HomePageResolvedSettings( + val rows: List, +) { + companion object { + val EMPTY = HomePageResolvedSettings(listOf()) + } +} @Serializable data class HomeRowViewOptions( diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index 31744ddab9..fc61192bae 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -2,17 +2,28 @@ package com.github.damontecres.wholphin.services import android.content.Context import com.github.damontecres.wholphin.R -import com.github.damontecres.wholphin.data.ServerRepository +import com.github.damontecres.wholphin.data.NavDrawerItemRepository +import com.github.damontecres.wholphin.data.model.HomePageResolvedSettings import com.github.damontecres.wholphin.data.model.HomePageSettings +import com.github.damontecres.wholphin.data.model.HomeRowConfig +import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay +import com.github.damontecres.wholphin.data.model.HomeRowViewOptions +import com.github.damontecres.wholphin.ui.main.settings.Library +import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem import com.github.damontecres.wholphin.ui.toServerString import dagger.hilt.android.qualifiers.ApplicationContext +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.update import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.Json import kotlinx.serialization.json.decodeFromStream import kotlinx.serialization.json.encodeToStream import org.jellyfin.sdk.api.client.ApiClient import org.jellyfin.sdk.api.client.extensions.displayPreferencesApi +import org.jellyfin.sdk.api.client.extensions.userLibraryApi import org.jellyfin.sdk.model.UUID +import org.jellyfin.sdk.model.serializer.toUUID +import timber.log.Timber import java.io.File import javax.inject.Inject import javax.inject.Singleton @@ -23,7 +34,8 @@ class HomeSettingsService constructor( @param:ApplicationContext private val context: Context, private val api: ApiClient, - private val serverRepository: ServerRepository, + private val userPreferencesService: UserPreferencesService, + private val navDrawerItemRepository: NavDrawerItemRepository, ) { val jsonParser = Json { @@ -31,32 +43,35 @@ class HomeSettingsService ignoreUnknownKeys = true } + val currentSettings = MutableStateFlow(HomePageResolvedSettings.EMPTY) + suspend fun saveToServer( + userId: UUID, settings: HomePageSettings, displayPreferencesId: String = DISPLAY_PREF_ID, ) { - serverRepository.currentUser.value?.let { user -> - val current = getDisplayPreferences(user.id, DISPLAY_PREF_ID) - val customPrefs = - current.customPrefs.toMutableMap().apply { - put(CUSTOM_PREF_ID, jsonParser.encodeToString(settings)) - } - api.displayPreferencesApi.updateDisplayPreferences( - displayPreferencesId = displayPreferencesId, - userId = user.id, - client = context.getString(R.string.app_name), - data = current.copy(customPrefs = customPrefs), - ) - } + val current = getDisplayPreferences(userId, DISPLAY_PREF_ID) + val customPrefs = + current.customPrefs.toMutableMap().apply { + put(CUSTOM_PREF_ID, jsonParser.encodeToString(settings)) + } + api.displayPreferencesApi.updateDisplayPreferences( + displayPreferencesId = displayPreferencesId, + userId = userId, + client = context.getString(R.string.app_name), + data = current.copy(customPrefs = customPrefs), + ) } - suspend fun loadFromServer(displayPreferencesId: String = DISPLAY_PREF_ID): HomePageSettings? = - serverRepository.currentUser.value?.let { user -> - val current = getDisplayPreferences(user.id, displayPreferencesId) - current.customPrefs[DISPLAY_PREF_ID]?.let { - Json.decodeFromString(it) - } + suspend fun loadFromServer( + userId: UUID, + displayPreferencesId: String = DISPLAY_PREF_ID, + ): HomePageSettings? { + val current = getDisplayPreferences(userId, displayPreferencesId) + return current.customPrefs[DISPLAY_PREF_ID]?.let { + Json.decodeFromString(it) } + } private suspend fun getDisplayPreferences( userId: UUID, @@ -71,27 +86,202 @@ class HomeSettingsService private fun filename(userId: UUID) = "${CUSTOM_PREF_ID}_${userId.toServerString()}.json" @OptIn(ExperimentalSerializationApi::class) - suspend fun saveToLocal(settings: HomePageSettings) { - serverRepository.currentUser.value?.let { user -> - val dir = File(context.filesDir, CUSTOM_PREF_ID) - dir.mkdirs() - File(dir, filename(user.id)).outputStream().use { - jsonParser.encodeToStream(settings, it) - } + suspend fun saveToLocal( + userId: UUID, + settings: HomePageSettings, + ) { + val dir = File(context.filesDir, CUSTOM_PREF_ID) + dir.mkdirs() + File(dir, filename(userId)).outputStream().use { + jsonParser.encodeToStream(settings, it) } } @OptIn(ExperimentalSerializationApi::class) - suspend fun loadFromLocal(): HomePageSettings? = - serverRepository.currentUser.value?.let { user -> - val dir = File(context.filesDir, CUSTOM_PREF_ID) - val file = File(dir, filename(user.id)) - if (file.exists()) { - file.inputStream().use { - jsonParser.decodeFromStream(it) + suspend fun loadFromLocal(userId: UUID): HomePageSettings? { + val dir = File(context.filesDir, CUSTOM_PREF_ID) + val file = File(dir, filename(userId)) + return if (file.exists()) { + file.inputStream().use { + jsonParser.decodeFromStream(it) + } + } else { + null + } + } + + suspend fun updateCurrent(userId: UUID) { + Timber.v("Getting setting for %s", userId) + // User local then server/remote otherwise create a default + val settings = loadFromLocal(userId) ?: loadFromServer(userId) + val resolvedSettings = + if (settings != null) { + Timber.v("Found settings") + // Resolve + val resolvedRows = settings.rows.map { convert(it) } + HomePageResolvedSettings(resolvedRows) + } else { + createDefault(userId) + } + + currentSettings.update { resolvedSettings } + } + + suspend fun createDefault(userId: UUID): HomePageResolvedSettings { + Timber.v("Creating default settings") + val navDrawerItems = navDrawerItemRepository.getNavDrawerItems() + val libraries = + navDrawerItems + .filter { it is ServerNavDrawerItem } + .map { + it as ServerNavDrawerItem + Library(it.itemId, it.name, it.type) } + val prefs = + userPreferencesService.getCurrent().appPreferences.homePagePreferences + val includedIds = + navDrawerItemRepository + .getFilteredNavDrawerItems(navDrawerItems) + .filter { it is ServerNavDrawerItem } + .mapIndexed { index, it -> + val id = (it as ServerNavDrawerItem).itemId + val name = libraries.firstOrNull { it.itemId == id }?.name + val title = + name?.let { context.getString(R.string.recently_added_in, it) } + ?: context.getString(R.string.recently_added) + HomeRowConfigDisplay( + title, + HomeRowConfig.RecentlyAdded( + index, + id, + HomeRowViewOptions(), + ), + ) + } + val continueWatchingRows = + if (prefs.combineContinueNext) { + listOf( + HomeRowConfigDisplay( + context.getString(R.string.combine_continue_next), + HomeRowConfig.ContinueWatchingCombined( + includedIds.size + 1, + HomeRowViewOptions(), + ), + ), + ) } else { - null + listOf( + HomeRowConfigDisplay( + context.getString(R.string.continue_watching), + HomeRowConfig.ContinueWatching( + includedIds.size + 1, + HomeRowViewOptions(), + ), + ), + HomeRowConfigDisplay( + context.getString(R.string.next_up), + HomeRowConfig.NextUp( + includedIds.size + 2, + HomeRowViewOptions(), + ), + ), + ) + } + val rowConfig = + continueWatchingRows + includedIds + + // TODO remove after testing + listOf( + HomeRowConfigDisplay( + "Collection", + HomeRowConfig.ByParent( + id = 100, + parentId = "34ab6fd1f51c41bb014981f2e334f465".toUUID(), + recursive = true, + viewOptions = HomeRowViewOptions(), + ), + ), + HomeRowConfigDisplay( + "Playlist", + HomeRowConfig.ByParent( + id = 101, + parentId = "f94be36e9836127a0bccfc7843b19e5b".toUUID(), + recursive = true, + viewOptions = HomeRowViewOptions(), + ), + ), + ) + return HomePageResolvedSettings(rowConfig) + } + + suspend fun convert(config: HomeRowConfig): HomeRowConfigDisplay = + when (config) { + is HomeRowConfig.ByParent -> { + val name = + api.userLibraryApi + .getItem(itemId = config.parentId) + .content.name ?: "" + HomeRowConfigDisplay( + name, + config, + ) + } + + is HomeRowConfig.ContinueWatching -> { + HomeRowConfigDisplay( + context.getString(R.string.continue_watching), + config, + ) + } + + is HomeRowConfig.ContinueWatchingCombined -> { + HomeRowConfigDisplay( + context.getString(R.string.combine_continue_next), + config, + ) + } + + is HomeRowConfig.Genres -> { + val name = + api.userLibraryApi + .getItem(itemId = config.parentId) + .content.name ?: "" + HomeRowConfigDisplay( + context.getString(R.string.genres_in, name), + config, + ) + } + + is HomeRowConfig.GetItems -> { + HomeRowConfigDisplay(config.name, config) + } + + is HomeRowConfig.NextUp -> { + HomeRowConfigDisplay( + context.getString(R.string.next_up), + config, + ) + } + + is HomeRowConfig.RecentlyAdded -> { + val name = + api.userLibraryApi + .getItem(itemId = config.parentId) + .content.name ?: "" + HomeRowConfigDisplay( + context.getString(R.string.recently_added_in, name), + config, + ) + } + + is HomeRowConfig.RecentlyReleased -> { + val name = + api.userLibraryApi + .getItem(itemId = config.parentId) + .content.name ?: "" + HomeRowConfigDisplay( + context.getString(R.string.recently_released_in, name), + config, + ) } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt b/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt index e267a12f95..f6d2578691 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt @@ -11,6 +11,7 @@ import com.github.damontecres.wholphin.api.seerr.model.PublicSettings import com.github.damontecres.wholphin.api.seerr.model.User import com.github.damontecres.wholphin.data.SeerrServerDao import com.github.damontecres.wholphin.data.ServerRepository +import com.github.damontecres.wholphin.data.model.HomePageResolvedSettings import com.github.damontecres.wholphin.data.model.SeerrAuthMethod import com.github.damontecres.wholphin.data.model.SeerrPermission import com.github.damontecres.wholphin.data.model.SeerrServer @@ -213,6 +214,7 @@ class UserSwitchListener private val seerrServerRepository: SeerrServerRepository, private val seerrServerDao: SeerrServerDao, private val seerrApi: SeerrApi, + private val homeSettingsService: HomeSettingsService, ) { init { context as AppCompatActivity @@ -220,41 +222,58 @@ class UserSwitchListener serverRepository.currentUser.asFlow().collect { user -> Timber.d("New user") seerrServerRepository.clear() + homeSettingsService.currentSettings.update { HomePageResolvedSettings.EMPTY } if (user != null) { - seerrServerDao - .getUsersByJellyfinUser(user.rowId) - .firstOrNull() - ?.let { seerrUser -> - val server = seerrServerDao.getServer(seerrUser.serverId)?.server - if (server != null) { - Timber.i("Found a seerr user & server") - seerrApi.update(server.url, seerrUser.credential) - val userConfig = - if (seerrUser.authMethod != SeerrAuthMethod.API_KEY) { - try { - login( - seerrApi.api, - seerrUser.authMethod, - seerrUser.username, - seerrUser.password, - ) - } catch (ex: Exception) { - Timber.w(ex, "Error logging into %s", server.url) - seerrServerRepository.clear() - return@let + // Check for home settings + launchIO { + homeSettingsService.updateCurrent(user.id) + } + // Check for seerr server + launchIO { + seerrServerDao + .getUsersByJellyfinUser(user.rowId) + .firstOrNull() + ?.let { seerrUser -> + val server = + seerrServerDao.getServer(seerrUser.serverId)?.server + if (server != null) { + Timber.i("Found a seerr user & server") + seerrApi.update(server.url, seerrUser.credential) + val userConfig = + if (seerrUser.authMethod != SeerrAuthMethod.API_KEY) { + try { + login( + seerrApi.api, + seerrUser.authMethod, + seerrUser.username, + seerrUser.password, + ) + } catch (ex: Exception) { + Timber.w( + ex, + "Error logging into %s", + server.url, + ) + seerrServerRepository.clear() + return@let + } + } else { + try { + seerrApi.api.usersApi.authMeGet() + } catch (ex: Exception) { + Timber.w( + ex, + "Error logging into %s", + server.url, + ) + seerrServerRepository.clear() + return@let + } } - } else { - try { - seerrApi.api.usersApi.authMeGet() - } catch (ex: Exception) { - Timber.w(ex, "Error logging into %s", server.url) - seerrServerRepository.clear() - return@let - } - } - seerrServerRepository.set(server, seerrUser, userConfig) + seerrServerRepository.set(server, seerrUser, userConfig) + } } - } + } } } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 623a18c1a0..8f148886a1 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -9,6 +9,7 @@ import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.NavDrawerItemRepository import com.github.damontecres.wholphin.data.ServerRepository import com.github.damontecres.wholphin.data.model.BaseItem +import com.github.damontecres.wholphin.data.model.HomePageResolvedSettings import com.github.damontecres.wholphin.data.model.HomePageSettings import com.github.damontecres.wholphin.data.model.HomeRowConfig import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay @@ -33,6 +34,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.update import org.jellyfin.sdk.api.client.ApiClient import org.jellyfin.sdk.api.client.extensions.userLibraryApi @@ -43,7 +45,6 @@ import org.jellyfin.sdk.model.api.UserDto import org.jellyfin.sdk.model.api.request.GetGenresRequest import org.jellyfin.sdk.model.api.request.GetItemsRequest import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest -import org.jellyfin.sdk.model.serializer.toUUID import timber.log.Timber import java.util.UUID import javax.inject.Inject @@ -77,178 +78,19 @@ class HomeSettingsViewModel it as ServerNavDrawerItem Library(it.itemId, it.name, it.type) } - _state.update { it.copy(libraries = libraries) } - - val localSettings = - try { - homeSettingsService.loadFromLocal() - } catch (ex: Exception) { - Timber.e(ex) - showToast(context, "Error loading settings: ${ex.localizedMessage}") - null - } - if (localSettings != null) { - val displays = localSettings.rows.map { convert(it) } - _state.update { - it.copy(rows = displays) - } - } else { - - // Or create default - val prefs = - userPreferencesService.getCurrent().appPreferences.homePagePreferences - val includedIds = - navDrawerItemRepository - .getFilteredNavDrawerItems(navDrawerItems) - .filter { it is ServerNavDrawerItem } - .mapIndexed { index, it -> - val id = (it as ServerNavDrawerItem).itemId - val name = libraries.firstOrNull { it.itemId == id }?.name - val title = - name?.let { context.getString(R.string.recently_added_in, it) } - ?: context.getString(R.string.recently_added) - HomeRowConfigDisplay( - title, - HomeRowConfig.RecentlyAdded( - index, - id, - HomeRowViewOptions(), - ), - ) - } - val continueWatchingRows = - if (prefs.combineContinueNext) { - listOf( - HomeRowConfigDisplay( - context.getString(R.string.combine_continue_next), - HomeRowConfig.ContinueWatchingCombined( - includedIds.size + 1, - HomeRowViewOptions(), - ), - ), - ) - } else { - listOf( - HomeRowConfigDisplay( - context.getString(R.string.continue_watching), - HomeRowConfig.ContinueWatching( - includedIds.size + 1, - HomeRowViewOptions(), - ), - ), - HomeRowConfigDisplay( - context.getString(R.string.next_up), - HomeRowConfig.NextUp( - includedIds.size + 2, - HomeRowViewOptions(), - ), - ), - ) - } - val rowConfig = - continueWatchingRows + includedIds + - // TODO remove after testing - listOf( - HomeRowConfigDisplay( - "Collection", - HomeRowConfig.ByParent( - id = 100, - parentId = "34ab6fd1f51c41bb014981f2e334f465".toUUID(), - recursive = true, - viewOptions = HomeRowViewOptions(), - ), - ), - HomeRowConfigDisplay( - "Playlist", - HomeRowConfig.ByParent( - id = 101, - parentId = "f94be36e9836127a0bccfc7843b19e5b".toUUID(), - recursive = true, - viewOptions = HomeRowViewOptions(), - ), - ), - ) - _state.update { - it.copy(rows = rowConfig) - } + val currentSettings = + homeSettingsService.currentSettings.first { it != HomePageResolvedSettings.EMPTY } + Timber.v("currentSettings=%s", currentSettings) + _state.update { + it.copy( + libraries = libraries, + rows = currentSettings.rows, + ) } - fetchRowData() } } - private suspend fun convert(config: HomeRowConfig): HomeRowConfigDisplay = - when (config) { - is HomeRowConfig.ByParent -> { - val name = - api.userLibraryApi - .getItem(itemId = config.parentId) - .content.name ?: "" - HomeRowConfigDisplay( - name, - config, - ) - } - - is HomeRowConfig.ContinueWatching -> { - HomeRowConfigDisplay( - context.getString(R.string.continue_watching), - config, - ) - } - - is HomeRowConfig.ContinueWatchingCombined -> { - HomeRowConfigDisplay( - context.getString(R.string.combine_continue_next), - config, - ) - } - - is HomeRowConfig.Genres -> { - val name = - api.userLibraryApi - .getItem(itemId = config.parentId) - .content.name ?: "" - HomeRowConfigDisplay( - context.getString(R.string.genres_in, name), - config, - ) - } - - is HomeRowConfig.GetItems -> { - HomeRowConfigDisplay(config.name, config) - } - - is HomeRowConfig.NextUp -> { - HomeRowConfigDisplay( - context.getString(R.string.next_up), - config, - ) - } - - is HomeRowConfig.RecentlyAdded -> { - val name = - api.userLibraryApi - .getItem(itemId = config.parentId) - .content.name ?: "" - HomeRowConfigDisplay( - context.getString(R.string.recently_added_in, name), - config, - ) - } - - is HomeRowConfig.RecentlyReleased -> { - val name = - api.userLibraryApi - .getItem(itemId = config.parentId) - .content.name ?: "" - HomeRowConfigDisplay( - context.getString(R.string.recently_released_in, name), - config, - ) - } - } - fun updateBackdrop(item: BaseItem) { viewModelScope.launchIO { backdropService.submit(item) @@ -709,14 +551,16 @@ class HomeSettingsViewModel fun saveToLocal() { viewModelScope.launchIO { - val rows = state.value.rows.map { it.config } - val settings = HomePageSettings(rows = rows) - try { - homeSettingsService.saveToLocal(settings) - showToast(context, context.getString(R.string.save), Toast.LENGTH_SHORT) - } catch (ex: Exception) { - Timber.e(ex) - showToast(context, "Error saving: ${ex.localizedMessage}") + serverRepository.currentUser.value?.let { user -> + val rows = state.value.rows.map { it.config } + val settings = HomePageSettings(rows = rows) + try { + homeSettingsService.saveToLocal(user.id, settings) + showToast(context, context.getString(R.string.save), Toast.LENGTH_SHORT) + } catch (ex: Exception) { + Timber.e(ex) + showToast(context, "Error saving: ${ex.localizedMessage}") + } } } } From 9834991392e471bfbf99536044330164325381ce Mon Sep 17 00:00:00 2001 From: Damontecres Date: Sat, 24 Jan 2026 21:12:46 -0500 Subject: [PATCH 16/53] Move data loading to HomeSettingsService --- .../wholphin/services/HomeSettingsService.kt | 255 ++++++++++++++++ .../wholphin/ui/components/GenreCardGrid.kt | 7 +- .../ui/main/settings/HomeSettingsViewModel.kt | 275 +----------------- 3 files changed, 275 insertions(+), 262 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index fc61192bae..16dc7db815 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -3,15 +3,24 @@ package com.github.damontecres.wholphin.services import android.content.Context import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.NavDrawerItemRepository +import com.github.damontecres.wholphin.data.model.BaseItem import com.github.damontecres.wholphin.data.model.HomePageResolvedSettings import com.github.damontecres.wholphin.data.model.HomePageSettings import com.github.damontecres.wholphin.data.model.HomeRowConfig import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay import com.github.damontecres.wholphin.data.model.HomeRowViewOptions +import com.github.damontecres.wholphin.preferences.HomePagePreferences +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.nav.ServerNavDrawerItem import com.github.damontecres.wholphin.ui.toServerString +import com.github.damontecres.wholphin.util.GetGenresRequestHandler +import com.github.damontecres.wholphin.util.GetItemsRequestHandler +import com.github.damontecres.wholphin.util.HomeRowLoadingState import dagger.hilt.android.qualifiers.ApplicationContext +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.update import kotlinx.serialization.ExperimentalSerializationApi @@ -22,6 +31,12 @@ import org.jellyfin.sdk.api.client.ApiClient import org.jellyfin.sdk.api.client.extensions.displayPreferencesApi import org.jellyfin.sdk.api.client.extensions.userLibraryApi import org.jellyfin.sdk.model.UUID +import org.jellyfin.sdk.model.api.ItemSortBy +import org.jellyfin.sdk.model.api.SortOrder +import org.jellyfin.sdk.model.api.UserDto +import org.jellyfin.sdk.model.api.request.GetGenresRequest +import org.jellyfin.sdk.model.api.request.GetItemsRequest +import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest import org.jellyfin.sdk.model.serializer.toUUID import timber.log.Timber import java.io.File @@ -36,6 +51,8 @@ class HomeSettingsService private val api: ApiClient, private val userPreferencesService: UserPreferencesService, private val navDrawerItemRepository: NavDrawerItemRepository, + private val latestNextUpService: LatestNextUpService, + private val imageUrlService: ImageUrlService, ) { val jsonParser = Json { @@ -285,6 +302,244 @@ class HomeSettingsService } } + suspend fun fetchDataForRow( + row: HomeRowConfig, + scope: CoroutineScope, + prefs: HomePagePreferences, + userDto: UserDto, + libraries: List, + limit: Int = prefs.maxItemsPerRow, + ): List = + when (row) { + is HomeRowConfig.ContinueWatching -> { + val resume = latestNextUpService.getResume(userDto.id, limit, true) + listOf( + HomeRowLoadingState.Success( + title = context.getString(R.string.continue_watching), + items = resume, + viewOptions = row.viewOptions, + ), + ) + } + + is HomeRowConfig.NextUp -> { + val nextUp = + latestNextUpService.getNextUp( + userDto.id, + limit, + prefs.enableRewatchingNextUp, + false, + ) + listOf( + HomeRowLoadingState.Success( + title = context.getString(R.string.next_up), + items = nextUp, + viewOptions = row.viewOptions, + ), + ) + } + + is HomeRowConfig.ContinueWatchingCombined -> { + val resume = + latestNextUpService.getResume(userDto.id, limit, true) + val nextUp = + latestNextUpService.getNextUp( + userDto.id, + limit, + prefs.enableRewatchingNextUp, + false, + ) + + listOf( + HomeRowLoadingState.Success( + title = context.getString(R.string.continue_watching), + items = + latestNextUpService.buildCombined( + resume, + nextUp, + ), + viewOptions = row.viewOptions, + ), + ) + } + + is HomeRowConfig.Genres -> { + val request = + GetGenresRequest( + parentId = row.parentId, + userId = userDto.id, + limit = limit, + ) + val items = + GetGenresRequestHandler + .execute(api, request) + .content.items + val genreIds = items.map { it.id } + val genreImages = + getGenreImageMap( + api = api, + scope = scope, + imageUrlService = imageUrlService, + genres = genreIds, + parentId = row.parentId, + includeItemTypes = null, + cardWidthPx = null, + ) + val genres = + items.map { + BaseItem(it, false, genreImages[it.id]) + } + + val name = + libraries + .firstOrNull { it.itemId == row.parentId } + ?.name + val title = + name?.let { context.getString(R.string.genres_in, it) } + ?: context.getString(R.string.genres) + listOf( + HomeRowLoadingState.Success( + title, + genres, + viewOptions = row.viewOptions, + ), + ) + } + + is HomeRowConfig.RecentlyAdded -> { + val name = + libraries + .firstOrNull { it.itemId == row.parentId } + ?.name + val title = + name?.let { context.getString(R.string.recently_added_in, it) } + ?: context.getString(R.string.recently_added) + val request = + GetLatestMediaRequest( + fields = SlimItemFields, + imageTypeLimit = 1, + parentId = row.parentId, + groupItems = true, + limit = limit, + isPlayed = null, // Server will handle user's preference + ) + val latest = + api.userLibraryApi + .getLatestMedia(request) + .content + .map { BaseItem.Companion.from(it, api, true) } + .let { + HomeRowLoadingState.Success( + title, + it, + row.viewOptions, + ) + } + listOf(latest) + } + + is HomeRowConfig.RecentlyReleased -> { + val name = + libraries + .firstOrNull { it.itemId == row.parentId } + ?.name + val title = + name?.let { + context.getString(R.string.recently_released_in, it) + } ?: context.getString(R.string.recently_released) + val request = + GetItemsRequest( + parentId = row.parentId, + limit = limit, + sortBy = listOf(ItemSortBy.PREMIERE_DATE), + sortOrder = listOf(SortOrder.DESCENDING), + fields = DefaultItemFields, + recursive = true, + ) + GetItemsRequestHandler + .execute(api, request) + .content.items + .map { BaseItem.Companion.from(it, api, true) } + .let { + listOf( + HomeRowLoadingState.Success( + title, + it, + row.viewOptions, + ), + ) + } + } + + is HomeRowConfig.ByParent -> { + val request = + GetItemsRequest( + userId = userDto.id, + parentId = row.parentId, + recursive = row.recursive, + sortBy = row.sort?.let { listOf(it.sort) }, + sortOrder = row.sort?.let { listOf(it.direction) }, + limit = limit, + fields = DefaultItemFields, + ) + val name = + api.userLibraryApi + .getItem(itemId = row.parentId) + .content.name + GetItemsRequestHandler + .execute(api, request) + .content.items + .map { BaseItem(it, true) } + .let { + listOf( + HomeRowLoadingState.Success( + name ?: context.getString(R.string.collection), + it, + row.viewOptions, + ), + ) + } + } + + is HomeRowConfig.GetItems -> { + val request = + row.getItems.let { + if (it.limit == null) { + it.copy( + userId = userDto.id, + limit = limit, + ) + } else { + it.copy( + userId = userDto.id, + ) + } + } + val name = + if (row.name == null && request.parentId != null) { + // If a name was not provided, use the parent's name if available + api.userLibraryApi + .getItem(itemId = request.parentId!!) + .content.name + } else { + row.name + } + GetItemsRequestHandler + .execute(api, request) + .content.items + .map { BaseItem.Companion.from(it, api, true) } + .let { + listOf( + HomeRowLoadingState.Success( + name ?: context.getString(R.string.collection), + it, + row.viewOptions, + ), + ) + } + } + } + companion object { const val DISPLAY_PREF_ID = "default" const val CUSTOM_PREF_ID = "home_settings" diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/components/GenreCardGrid.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/components/GenreCardGrid.kt index 9d6f662b14..84f36f02b9 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/components/GenreCardGrid.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/components/GenreCardGrid.kt @@ -41,6 +41,7 @@ import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll @@ -111,6 +112,7 @@ class GenreViewModel val genreToUrl = getGenreImageMap( api = api, + scope = viewModelScope, imageUrlService = imageUrlService, genres = genres.map { it.id }, parentId = itemId, @@ -141,8 +143,9 @@ class GenreViewModel } } -suspend fun ViewModel.getGenreImageMap( +suspend fun getGenreImageMap( api: ApiClient, + scope: CoroutineScope, imageUrlService: ImageUrlService, genres: List, parentId: UUID, @@ -153,7 +156,7 @@ suspend fun ViewModel.getGenreImageMap( val semaphore = Semaphore(4) genres .map { genreId -> - viewModelScope.async(Dispatchers.IO) { + scope.async(Dispatchers.IO) { semaphore.withPermit { val item = GetItemsRequestHandler diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 8f148886a1..98074c093b 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -14,20 +14,12 @@ import com.github.damontecres.wholphin.data.model.HomePageSettings import com.github.damontecres.wholphin.data.model.HomeRowConfig import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay import com.github.damontecres.wholphin.data.model.HomeRowViewOptions -import com.github.damontecres.wholphin.preferences.HomePagePreferences import com.github.damontecres.wholphin.services.BackdropService import com.github.damontecres.wholphin.services.HomeSettingsService -import com.github.damontecres.wholphin.services.ImageUrlService -import com.github.damontecres.wholphin.services.LatestNextUpService import com.github.damontecres.wholphin.services.UserPreferencesService -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.launchIO import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem import com.github.damontecres.wholphin.ui.showToast -import com.github.damontecres.wholphin.util.GetGenresRequestHandler -import com.github.damontecres.wholphin.util.GetItemsRequestHandler import com.github.damontecres.wholphin.util.HomeRowLoadingState import com.github.damontecres.wholphin.util.LoadingState import dagger.hilt.android.lifecycle.HiltViewModel @@ -36,15 +28,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.update -import org.jellyfin.sdk.api.client.ApiClient -import org.jellyfin.sdk.api.client.extensions.userLibraryApi import org.jellyfin.sdk.model.api.CollectionType -import org.jellyfin.sdk.model.api.ItemSortBy -import org.jellyfin.sdk.model.api.SortOrder -import org.jellyfin.sdk.model.api.UserDto -import org.jellyfin.sdk.model.api.request.GetGenresRequest -import org.jellyfin.sdk.model.api.request.GetItemsRequest -import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest import timber.log.Timber import java.util.UUID import javax.inject.Inject @@ -54,14 +38,11 @@ class HomeSettingsViewModel @Inject constructor( @param:ApplicationContext private val context: Context, - private val api: ApiClient, private val homeSettingsService: HomeSettingsService, private val serverRepository: ServerRepository, private val userPreferencesService: UserPreferencesService, private val navDrawerItemRepository: NavDrawerItemRepository, private val backdropService: BackdropService, - private val latestNextUpService: LatestNextUpService, - private val imageUrlService: ImageUrlService, ) : ViewModel() { private val _state = MutableStateFlow(HomePageSettingsState.EMPTY) val state: StateFlow = _state @@ -102,12 +83,21 @@ class HomeSettingsViewModel val rows = serverRepository.currentUserDto.value?.let { userDto -> val prefs = userPreferencesService.getCurrent().appPreferences.homePagePreferences - state.value.rows - .map { it.config } - .map { row -> - // TODO parallelize - parseRow(prefs, userDto, row, limit) - }.flatten() + state.value.let { state -> + state.rows + .map { it.config } + .map { row -> + // TODO parallelize + homeSettingsService.fetchDataForRow( + row = row, + scope = viewModelScope, + prefs = prefs, + userDto = userDto, + libraries = state.libraries, + limit = limit, + ) + }.flatten() + } } rows?.let { rows -> _state.update { @@ -116,241 +106,6 @@ class HomeSettingsViewModel } } - private suspend fun parseRow( - prefs: HomePagePreferences, - userDto: UserDto, - row: HomeRowConfig, - limit: Int, - ): List = - when (row) { - is HomeRowConfig.ContinueWatching -> { - val resume = latestNextUpService.getResume(userDto.id, limit, true) - listOf( - HomeRowLoadingState.Success( - title = context.getString(R.string.continue_watching), - items = resume, - viewOptions = row.viewOptions, - ), - ) - } - - is HomeRowConfig.NextUp -> { - val nextUp = - latestNextUpService.getNextUp( - userDto.id, - limit, - prefs.enableRewatchingNextUp, - false, - ) - listOf( - HomeRowLoadingState.Success( - title = context.getString(R.string.next_up), - items = nextUp, - viewOptions = row.viewOptions, - ), - ) - } - - is HomeRowConfig.ContinueWatchingCombined -> { - val resume = - latestNextUpService.getResume(userDto.id, limit, true) - val nextUp = - latestNextUpService.getNextUp( - userDto.id, - limit, - prefs.enableRewatchingNextUp, - false, - ) - - listOf( - HomeRowLoadingState.Success( - title = context.getString(R.string.continue_watching), - items = - latestNextUpService.buildCombined( - resume, - nextUp, - ), - viewOptions = row.viewOptions, - ), - ) - } - - is HomeRowConfig.Genres -> { - val request = - GetGenresRequest( - parentId = row.parentId, - userId = userDto.id, - limit = limit, - ) - val items = - GetGenresRequestHandler - .execute(api, request) - .content.items - val genreIds = items.map { it.id } - val genreImages = - getGenreImageMap( - api = api, - imageUrlService = imageUrlService, - genres = genreIds, - parentId = row.parentId, - includeItemTypes = null, - cardWidthPx = null, - ) - val genres = - items.map { - BaseItem(it, false, genreImages[it.id]) - } - - val name = - _state.value.libraries - .firstOrNull { it.itemId == row.parentId } - ?.name - val title = - name?.let { context.getString(R.string.genres_in, it) } - ?: context.getString(R.string.genres) - listOf( - HomeRowLoadingState.Success( - title, - genres, - viewOptions = row.viewOptions, - ), - ) - } - - is HomeRowConfig.RecentlyAdded -> { - val name = - _state.value.libraries - .firstOrNull { it.itemId == row.parentId } - ?.name - val title = - name?.let { context.getString(R.string.recently_added_in, it) } - ?: context.getString(R.string.recently_added) - val request = - GetLatestMediaRequest( - fields = SlimItemFields, - imageTypeLimit = 1, - parentId = row.parentId, - groupItems = true, - limit = limit, - isPlayed = null, // Server will handle user's preference - ) - val latest = - api.userLibraryApi - .getLatestMedia(request) - .content - .map { BaseItem.Companion.from(it, api, true) } - .let { - HomeRowLoadingState.Success( - title, - it, - row.viewOptions, - ) - } - listOf(latest) - } - - is HomeRowConfig.RecentlyReleased -> { - val name = - _state.value.libraries - .firstOrNull { it.itemId == row.parentId } - ?.name - val title = - name?.let { - context.getString(R.string.recently_released_in, it) - } ?: context.getString(R.string.recently_released) - val request = - GetItemsRequest( - parentId = row.parentId, - limit = limit, - sortBy = listOf(ItemSortBy.PREMIERE_DATE), - sortOrder = listOf(SortOrder.DESCENDING), - fields = DefaultItemFields, - recursive = true, - ) - GetItemsRequestHandler - .execute(api, request) - .content.items - .map { BaseItem.Companion.from(it, api, true) } - .let { - listOf( - HomeRowLoadingState.Success( - title, - it, - row.viewOptions, - ), - ) - } - } - - is HomeRowConfig.ByParent -> { - val request = - GetItemsRequest( - userId = userDto.id, - parentId = row.parentId, - recursive = row.recursive, - sortBy = row.sort?.let { listOf(it.sort) }, - sortOrder = row.sort?.let { listOf(it.direction) }, - limit = limit, - fields = DefaultItemFields, - ) - val name = - api.userLibraryApi - .getItem(itemId = row.parentId) - .content.name - GetItemsRequestHandler - .execute(api, request) - .content.items - .map { BaseItem(it, true) } - .let { - listOf( - HomeRowLoadingState.Success( - name ?: context.getString(R.string.collection), - it, - row.viewOptions, - ), - ) - } - } - - is HomeRowConfig.GetItems -> { - val request = - row.getItems.let { - if (it.limit == null) { - it.copy( - userId = userDto.id, - limit = limit, - ) - } else { - it.copy( - userId = userDto.id, - ) - } - } - val name = - if (row.name == null && request.parentId != null) { - // If a name was not provided, use the parent's name if available - api.userLibraryApi - .getItem(itemId = request.parentId!!) - .content.name - } else { - row.name - } - GetItemsRequestHandler - .execute(api, request) - .content.items - .map { BaseItem.Companion.from(it, api, true) } - .let { - listOf( - HomeRowLoadingState.Success( - name ?: context.getString(R.string.collection), - it, - row.viewOptions, - ), - ) - } - } - } - private fun List.move( direction: MoveDirection, index: Int, From ce4f8475b0a9c258054b22c8c40b47602624f20b Mon Sep 17 00:00:00 2001 From: Damontecres Date: Sat, 24 Jan 2026 21:54:57 -0500 Subject: [PATCH 17/53] Move home page over to use custom settings --- .../damontecres/wholphin/MainActivity.kt | 3 +- .../wholphin/services/HomeSettingsService.kt | 85 ++++++-------- .../damontecres/wholphin/ui/main/HomePage.kt | 11 +- .../wholphin/ui/main/HomeViewModel.kt | 109 +++++++++++++++++- .../ui/main/settings/HomeSettingsViewModel.kt | 2 +- 5 files changed, 150 insertions(+), 60 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt b/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt index f127944e20..c7b12bfc34 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt @@ -265,8 +265,7 @@ class MainActivity : AppCompatActivity() { server = current.server, startDestination = requestedDestination - // TODO Undo - ?: Destination.HomeSettings, + ?: Destination.Home(), navigationManager = navigationManager, preferences = preferences, modifier = Modifier.fillMaxSize(), diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index 16dc7db815..d9c184a3d3 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -309,16 +309,15 @@ class HomeSettingsService userDto: UserDto, libraries: List, limit: Int = prefs.maxItemsPerRow, - ): List = + ): HomeRowLoadingState = when (row) { is HomeRowConfig.ContinueWatching -> { val resume = latestNextUpService.getResume(userDto.id, limit, true) - listOf( - HomeRowLoadingState.Success( - title = context.getString(R.string.continue_watching), - items = resume, - viewOptions = row.viewOptions, - ), + + HomeRowLoadingState.Success( + title = context.getString(R.string.continue_watching), + items = resume, + viewOptions = row.viewOptions, ) } @@ -330,12 +329,11 @@ class HomeSettingsService prefs.enableRewatchingNextUp, false, ) - listOf( - HomeRowLoadingState.Success( - title = context.getString(R.string.next_up), - items = nextUp, - viewOptions = row.viewOptions, - ), + + HomeRowLoadingState.Success( + title = context.getString(R.string.next_up), + items = nextUp, + viewOptions = row.viewOptions, ) } @@ -350,16 +348,14 @@ class HomeSettingsService false, ) - listOf( - HomeRowLoadingState.Success( - title = context.getString(R.string.continue_watching), - items = - latestNextUpService.buildCombined( - resume, - nextUp, - ), - viewOptions = row.viewOptions, - ), + HomeRowLoadingState.Success( + title = context.getString(R.string.continue_watching), + items = + latestNextUpService.buildCombined( + resume, + nextUp, + ), + viewOptions = row.viewOptions, ) } @@ -397,12 +393,11 @@ class HomeSettingsService val title = name?.let { context.getString(R.string.genres_in, it) } ?: context.getString(R.string.genres) - listOf( - HomeRowLoadingState.Success( - title, - genres, - viewOptions = row.viewOptions, - ), + + HomeRowLoadingState.Success( + title, + genres, + viewOptions = row.viewOptions, ) } @@ -435,7 +430,7 @@ class HomeSettingsService row.viewOptions, ) } - listOf(latest) + latest } is HomeRowConfig.RecentlyReleased -> { @@ -461,12 +456,10 @@ class HomeSettingsService .content.items .map { BaseItem.Companion.from(it, api, true) } .let { - listOf( - HomeRowLoadingState.Success( - title, - it, - row.viewOptions, - ), + HomeRowLoadingState.Success( + title, + it, + row.viewOptions, ) } } @@ -491,12 +484,10 @@ class HomeSettingsService .content.items .map { BaseItem(it, true) } .let { - listOf( - HomeRowLoadingState.Success( - name ?: context.getString(R.string.collection), - it, - row.viewOptions, - ), + HomeRowLoadingState.Success( + name ?: context.getString(R.string.collection), + it, + row.viewOptions, ) } } @@ -529,12 +520,10 @@ class HomeSettingsService .content.items .map { BaseItem.Companion.from(it, api, true) } .let { - listOf( - HomeRowLoadingState.Success( - name ?: context.getString(R.string.collection), - it, - row.viewOptions, - ), + HomeRowLoadingState.Success( + name ?: context.getString(R.string.collection), + it, + row.viewOptions, ) } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt index 3bcea534cb..a218f98532 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt @@ -21,6 +21,7 @@ import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.mutableStateOf @@ -90,12 +91,10 @@ fun HomePage( LaunchedEffect(Unit) { viewModel.init() } - val loading by viewModel.loadingState.observeAsState(LoadingState.Loading) - val refreshing by viewModel.refreshState.observeAsState(LoadingState.Loading) - val watchingRows by viewModel.watchingRows.observeAsState(listOf()) - val latestRows by viewModel.latestRows.observeAsState(listOf()) - - val homeRows = remember(watchingRows, latestRows) { watchingRows + latestRows } + val state by viewModel.state.collectAsState() + val loading = state.loadingState + val refreshing = state.refreshState + val homeRows = state.homeRows when (val state = loading) { is LoadingState.Error -> { diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt index 1911e34da6..877ab014db 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt @@ -8,14 +8,16 @@ import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.NavDrawerItemRepository import com.github.damontecres.wholphin.data.ServerRepository import com.github.damontecres.wholphin.data.model.BaseItem -import com.github.damontecres.wholphin.preferences.UserPreferences +import com.github.damontecres.wholphin.data.model.HomePageResolvedSettings import com.github.damontecres.wholphin.services.BackdropService import com.github.damontecres.wholphin.services.DatePlayedService import com.github.damontecres.wholphin.services.FavoriteWatchManager +import com.github.damontecres.wholphin.services.HomeSettingsService import com.github.damontecres.wholphin.services.LatestNextUpService import com.github.damontecres.wholphin.services.NavigationManager import com.github.damontecres.wholphin.services.UserPreferencesService import com.github.damontecres.wholphin.ui.launchIO +import com.github.damontecres.wholphin.ui.main.settings.Library import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem import com.github.damontecres.wholphin.ui.setValueOnMain import com.github.damontecres.wholphin.ui.showToast @@ -26,7 +28,15 @@ import com.github.damontecres.wholphin.util.LoadingState import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch +import kotlinx.coroutines.sync.Semaphore +import kotlinx.coroutines.sync.withPermit import kotlinx.coroutines.withContext import org.jellyfin.sdk.api.client.ApiClient import org.jellyfin.sdk.model.api.CollectionType @@ -44,6 +54,7 @@ class HomeViewModel val navigationManager: NavigationManager, val serverRepository: ServerRepository, val navDrawerItemRepository: NavDrawerItemRepository, + private val homeSettingsService: HomeSettingsService, private val favoriteWatchManager: FavoriteWatchManager, private val datePlayedService: DatePlayedService, private val latestNextUpService: LatestNextUpService, @@ -55,7 +66,8 @@ class HomeViewModel val watchingRows = MutableLiveData>(listOf()) val latestRows = MutableLiveData>(listOf()) - private lateinit var preferences: UserPreferences + private val _state = MutableStateFlow(HomeState.EMPTY) + val state: StateFlow = _state init { datePlayedService.invalidateAll() @@ -76,12 +88,86 @@ class HomeViewModel loadingState.setValueOnMain(LoadingState.Loading) } refreshState.setValueOnMain(LoadingState.Loading) - this@HomeViewModel.preferences = userPreferencesService.getCurrent() + val preferences = userPreferencesService.getCurrent() val prefs = preferences.appPreferences.homePagePreferences val limit = prefs.maxItemsPerRow if (reload) { backdropService.clearBackdrop() } + + val navDrawerItems = + navDrawerItemRepository + .getNavDrawerItems() + val libraries = + navDrawerItems + .filter { it is ServerNavDrawerItem } + .map { + it as ServerNavDrawerItem + Library(it.itemId, it.name, it.type) + } + serverRepository.currentUserDto.value?.let { userDto -> + val settings = + homeSettingsService.currentSettings.first { it != HomePageResolvedSettings.EMPTY } + val state = state.value + + // Refreshing if a load has already occurred and the rows haven't significantly changed + val refresh = + state.loadingState == LoadingState.Success && state.settings == settings + + val semaphore = Semaphore(4) + val loadingRows = + if (refresh) { + state.homeRows + } else { + mutableListOf() + } + val deferred = + settings.rows.mapIndexed { index, row -> + if (refresh) { + (loadingRows as MutableList).add(HomeRowLoadingState.Loading(row.title)) + } + + viewModelScope.async(Dispatchers.IO) { + semaphore.withPermit { + Timber.v("Fetching row: %s", row) + try { + homeSettingsService.fetchDataForRow( + row = row.config, + scope = viewModelScope, + prefs = prefs, + userDto = userDto, + libraries = libraries, + limit = prefs.maxItemsPerRow, + ) + } catch (ex: Exception) { + Timber.e(ex, "Error on row %s", row) + HomeRowLoadingState.Error(row.title, exception = ex) + } + } + } + } + if (refresh) { + deferred.firstOrNull()?.await()?.let { + (loadingRows as MutableList)[0] = it + } + _state.update { + it.copy( + loadingState = LoadingState.Success, + homeRows = loadingRows, + ) + } + } + val rows = deferred.awaitAll() + Timber.v("Got all rows") + _state.update { + it.copy( + loadingState = LoadingState.Success, + refreshState = LoadingState.Success, + homeRows = rows, + ) + } + } + try { serverRepository.currentUserDto.value?.let { userDto -> val includedIds = @@ -192,3 +278,20 @@ data class LatestData( val title: String, val request: GetLatestMediaRequest, ) + +data class HomeState( + val loadingState: LoadingState, + val refreshState: LoadingState, + val homeRows: List, + val settings: HomePageResolvedSettings, +) { + companion object { + val EMPTY = + HomeState( + LoadingState.Pending, + LoadingState.Pending, + listOf(), + HomePageResolvedSettings.EMPTY, + ) + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 98074c093b..4b88834ec0 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -96,7 +96,7 @@ class HomeSettingsViewModel libraries = state.libraries, limit = limit, ) - }.flatten() + } } } rows?.let { rows -> From 025c253a42d364964e87a2a28a876781b20dd1d0 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Sat, 24 Jan 2026 22:01:58 -0500 Subject: [PATCH 18/53] Remove unused code --- .../wholphin/services/LatestNextUpService.kt | 17 +- .../wholphin/ui/main/HomeViewModel.kt | 243 +++++------------- 2 files changed, 86 insertions(+), 174 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/LatestNextUpService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/LatestNextUpService.kt index 44ed1a58d9..307125fbf9 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/LatestNextUpService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/LatestNextUpService.kt @@ -4,8 +4,6 @@ import android.content.Context import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.model.BaseItem import com.github.damontecres.wholphin.ui.SlimItemFields -import com.github.damontecres.wholphin.ui.main.LatestData -import com.github.damontecres.wholphin.ui.main.supportedLatestCollectionTypes import com.github.damontecres.wholphin.util.HomeRowLoadingState import com.github.damontecres.wholphin.util.supportItemKinds import dagger.hilt.android.qualifiers.ApplicationContext @@ -21,6 +19,7 @@ import org.jellyfin.sdk.api.client.extensions.tvShowsApi import org.jellyfin.sdk.api.client.extensions.userLibraryApi import org.jellyfin.sdk.api.client.extensions.userViewsApi import org.jellyfin.sdk.model.api.BaseItemKind +import org.jellyfin.sdk.model.api.CollectionType import org.jellyfin.sdk.model.api.UserDto import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest import org.jellyfin.sdk.model.api.request.GetNextUpRequest @@ -188,3 +187,17 @@ class LatestNextUpService return@withContext result } } + +val supportedLatestCollectionTypes = + setOf( + CollectionType.MOVIES, + CollectionType.TVSHOWS, + CollectionType.HOMEVIDEOS, + // Exclude Live TV because a recording folder view will be used instead + null, // Recordings & mixed collection types + ) + +data class LatestData( + val title: String, + val request: GetLatestMediaRequest, +) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt index 877ab014db..ebde16a854 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt @@ -1,10 +1,8 @@ package com.github.damontecres.wholphin.ui.main import android.content.Context -import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.NavDrawerItemRepository import com.github.damontecres.wholphin.data.ServerRepository import com.github.damontecres.wholphin.data.model.BaseItem @@ -13,17 +11,14 @@ import com.github.damontecres.wholphin.services.BackdropService import com.github.damontecres.wholphin.services.DatePlayedService import com.github.damontecres.wholphin.services.FavoriteWatchManager import com.github.damontecres.wholphin.services.HomeSettingsService -import com.github.damontecres.wholphin.services.LatestNextUpService import com.github.damontecres.wholphin.services.NavigationManager import com.github.damontecres.wholphin.services.UserPreferencesService import com.github.damontecres.wholphin.ui.launchIO import com.github.damontecres.wholphin.ui.main.settings.Library import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem -import com.github.damontecres.wholphin.ui.setValueOnMain import com.github.damontecres.wholphin.ui.showToast import com.github.damontecres.wholphin.util.ExceptionHandler import com.github.damontecres.wholphin.util.HomeRowLoadingState -import com.github.damontecres.wholphin.util.LoadingExceptionHandler import com.github.damontecres.wholphin.util.LoadingState import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext @@ -38,9 +33,6 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Semaphore import kotlinx.coroutines.sync.withPermit import kotlinx.coroutines.withContext -import org.jellyfin.sdk.api.client.ApiClient -import org.jellyfin.sdk.model.api.CollectionType -import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest import timber.log.Timber import java.util.UUID import javax.inject.Inject @@ -50,22 +42,15 @@ class HomeViewModel @Inject constructor( @param:ApplicationContext private val context: Context, - val api: ApiClient, - val navigationManager: NavigationManager, - val serverRepository: ServerRepository, - val navDrawerItemRepository: NavDrawerItemRepository, + private val serverRepository: ServerRepository, + private val navDrawerItemRepository: NavDrawerItemRepository, private val homeSettingsService: HomeSettingsService, private val favoriteWatchManager: FavoriteWatchManager, private val datePlayedService: DatePlayedService, - private val latestNextUpService: LatestNextUpService, private val backdropService: BackdropService, private val userPreferencesService: UserPreferencesService, + val navigationManager: NavigationManager, ) : ViewModel() { - val loadingState = MutableLiveData(LoadingState.Pending) - val refreshState = MutableLiveData(LoadingState.Pending) - val watchingRows = MutableLiveData>(listOf()) - val latestRows = MutableLiveData>(listOf()) - private val _state = MutableStateFlow(HomeState.EMPTY) val state: StateFlow = _state @@ -75,164 +60,92 @@ class HomeViewModel } fun init() { - viewModelScope.launch( - Dispatchers.IO + - LoadingExceptionHandler( - loadingState, - "Error loading home page", - ), - ) { + viewModelScope.launchIO { Timber.d("init HomeViewModel") - val reload = loadingState.value != LoadingState.Success - if (reload) { - loadingState.setValueOnMain(LoadingState.Loading) - } - refreshState.setValueOnMain(LoadingState.Loading) - val preferences = userPreferencesService.getCurrent() - val prefs = preferences.appPreferences.homePagePreferences - val limit = prefs.maxItemsPerRow - if (reload) { - backdropService.clearBackdrop() - } - - val navDrawerItems = - navDrawerItemRepository - .getNavDrawerItems() - val libraries = - navDrawerItems - .filter { it is ServerNavDrawerItem } - .map { - it as ServerNavDrawerItem - Library(it.itemId, it.name, it.type) - } - serverRepository.currentUserDto.value?.let { userDto -> - val settings = - homeSettingsService.currentSettings.first { it != HomePageResolvedSettings.EMPTY } - val state = state.value + try { + val preferences = userPreferencesService.getCurrent() + val prefs = preferences.appPreferences.homePagePreferences + + val navDrawerItems = + navDrawerItemRepository + .getNavDrawerItems() + val libraries = + navDrawerItems + .filter { it is ServerNavDrawerItem } + .map { + it as ServerNavDrawerItem + Library(it.itemId, it.name, it.type) + } + serverRepository.currentUserDto.value?.let { userDto -> + val settings = + homeSettingsService.currentSettings.first { it != HomePageResolvedSettings.EMPTY } + val state = state.value - // Refreshing if a load has already occurred and the rows haven't significantly changed - val refresh = - state.loadingState == LoadingState.Success && state.settings == settings + // Refreshing if a load has already occurred and the rows haven't significantly changed + val refresh = + state.loadingState == LoadingState.Success && state.settings == settings - val semaphore = Semaphore(4) - val loadingRows = - if (refresh) { - state.homeRows - } else { - mutableListOf() - } - val deferred = - settings.rows.mapIndexed { index, row -> + val semaphore = Semaphore(4) + val loadingRows = if (refresh) { - (loadingRows as MutableList).add(HomeRowLoadingState.Loading(row.title)) + state.homeRows + } else { + mutableListOf() } + val deferred = + settings.rows.mapIndexed { index, row -> + if (refresh) { + (loadingRows as MutableList).add(HomeRowLoadingState.Loading(row.title)) + } - viewModelScope.async(Dispatchers.IO) { - semaphore.withPermit { - Timber.v("Fetching row: %s", row) - try { - homeSettingsService.fetchDataForRow( - row = row.config, - scope = viewModelScope, - prefs = prefs, - userDto = userDto, - libraries = libraries, - limit = prefs.maxItemsPerRow, - ) - } catch (ex: Exception) { - Timber.e(ex, "Error on row %s", row) - HomeRowLoadingState.Error(row.title, exception = ex) + viewModelScope.async(Dispatchers.IO) { + semaphore.withPermit { + Timber.v("Fetching row: %s", row) + try { + homeSettingsService.fetchDataForRow( + row = row.config, + scope = viewModelScope, + prefs = prefs, + userDto = userDto, + libraries = libraries, + limit = prefs.maxItemsPerRow, + ) + } catch (ex: Exception) { + Timber.e(ex, "Error on row %s", row) + HomeRowLoadingState.Error(row.title, exception = ex) + } } } } + if (refresh) { + deferred.firstOrNull()?.await()?.let { + (loadingRows as MutableList)[0] = it + } + _state.update { + it.copy( + loadingState = LoadingState.Success, + homeRows = loadingRows, + ) + } } - if (refresh) { - deferred.firstOrNull()?.await()?.let { - (loadingRows as MutableList)[0] = it - } + val rows = deferred.awaitAll() + Timber.v("Got all rows") _state.update { it.copy( loadingState = LoadingState.Success, - homeRows = loadingRows, + refreshState = LoadingState.Success, + homeRows = rows, ) } } - val rows = deferred.awaitAll() - Timber.v("Got all rows") - _state.update { - it.copy( - loadingState = LoadingState.Success, - refreshState = LoadingState.Success, - homeRows = rows, - ) - } - } - - try { - serverRepository.currentUserDto.value?.let { userDto -> - val includedIds = - navDrawerItemRepository - .getFilteredNavDrawerItems(navDrawerItemRepository.getNavDrawerItems()) - .filter { it is ServerNavDrawerItem } - .map { (it as ServerNavDrawerItem).itemId } - val resume = latestNextUpService.getResume(userDto.id, limit, true) - val nextUp = - latestNextUpService.getNextUp( - userDto.id, - limit, - prefs.enableRewatchingNextUp, - false, - ) - val watching = - buildList { - if (prefs.combineContinueNext) { - val items = latestNextUpService.buildCombined(resume, nextUp) - add( - HomeRowLoadingState.Success( - title = context.getString(R.string.continue_watching), - items = items, - ), - ) - } else { - if (resume.isNotEmpty()) { - add( - HomeRowLoadingState.Success( - title = context.getString(R.string.continue_watching), - items = resume, - ), - ) - } - if (nextUp.isNotEmpty()) { - add( - HomeRowLoadingState.Success( - title = context.getString(R.string.next_up), - items = nextUp, - ), - ) - } - } - } - - val latest = latestNextUpService.getLatest(userDto, limit, includedIds) - val pendingLatest = latest.map { HomeRowLoadingState.Loading(it.title) } - - withContext(Dispatchers.Main) { - this@HomeViewModel.watchingRows.value = watching - if (reload) { - this@HomeViewModel.latestRows.value = pendingLatest - } - loadingState.value = LoadingState.Success - } - refreshState.setValueOnMain(LoadingState.Success) - val loadedLatest = latestNextUpService.loadLatest(latest) - this@HomeViewModel.latestRows.setValueOnMain(loadedLatest) - } } catch (ex: Exception) { - Timber.e(ex) - if (!reload) { - loadingState.setValueOnMain(LoadingState.Error(ex)) - } else { + Timber.e(ex, "Exception during home page loading") + if (state.value.loadingState == LoadingState.Success) { showToast(context, "Error refreshing home: ${ex.localizedMessage}") + } else { + _state.update { + it.copy(loadingState = LoadingState.Error(ex)) + } } } } @@ -265,20 +178,6 @@ class HomeViewModel } } -val supportedLatestCollectionTypes = - setOf( - CollectionType.MOVIES, - CollectionType.TVSHOWS, - CollectionType.HOMEVIDEOS, - // Exclude Live TV because a recording folder view will be used instead - null, // Recordings & mixed collection types - ) - -data class LatestData( - val title: String, - val request: GetLatestMediaRequest, -) - data class HomeState( val loadingState: LoadingState, val refreshState: LoadingState, From 2d0e5b84d49624a2d63dc47148a9ce6ef5066683 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Sat, 24 Jan 2026 22:15:14 -0500 Subject: [PATCH 19/53] Add settings to go to home settings --- .../wholphin/preferences/AppPreference.kt | 7 +++++++ .../ui/main/settings/HomeSettingsViewModel.kt | 21 ++++++++++++------- app/src/main/res/values/strings.xml | 1 + 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/preferences/AppPreference.kt b/app/src/main/java/com/github/damontecres/wholphin/preferences/AppPreference.kt index f1be13a4a3..27fd1d5bbe 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/preferences/AppPreference.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/preferences/AppPreference.kt @@ -617,6 +617,12 @@ sealed interface AppPreference { setter = { prefs, _ -> prefs }, ) + val CustomizeHome = + AppDestinationPreference( + title = R.string.customize_home, + destination = Destination.HomeSettings, + ) + val SendCrashReports = AppSwitchPreference( title = R.string.send_crash_reports, @@ -946,6 +952,7 @@ val basicPreferences = preferences = listOf( AppPreference.RequireProfilePin, + AppPreference.CustomizeHome, AppPreference.UserPinnedNavDrawerItems, ), ), diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 4b88834ec0..9bb22f7ecb 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -100,7 +100,7 @@ class HomeSettingsViewModel } } rows?.let { rows -> - _state.update { + updateState { it.copy(loading = LoadingState.Success, rowData = rows) } } @@ -128,7 +128,7 @@ class HomeSettingsViewModel direction: MoveDirection, index: Int, ) { - _state.update { + updateState { val rows = it.rows.move(direction, index) // TODO would be more efficient to move rowData, but uncombined continue watching is two rows // val rowData = it.rowData.move(direction, index) @@ -141,7 +141,7 @@ class HomeSettingsViewModel } fun deleteRow(index: Int) { - _state.update { + updateState { val rows = it.rows.toMutableList().apply { removeAt(index) } val rowData = it.rowData.toMutableList().apply { removeAt(index) } it.copy( @@ -186,7 +186,7 @@ class HomeSettingsViewModel ) } } - _state.update { + updateState { it.copy( loading = LoadingState.Loading, rows = it.rows.toMutableList().apply { add(newRow) }, @@ -246,7 +246,7 @@ class HomeSettingsViewModel ) } } - _state.update { + updateState { it.copy( loading = LoadingState.Loading, rows = it.rows.toMutableList().apply { add(newRow) }, @@ -261,7 +261,7 @@ class HomeSettingsViewModel viewOptions: HomeRowViewOptions, ) { viewModelScope.launchIO { - _state.update { + updateState { val index = it.rows.indexOfFirst { it.config.id == rowId } val newRowConfig = it.rows[index] @@ -290,7 +290,7 @@ class HomeSettingsViewModel } fun updateViewOptionsForAll(viewOptions: HomeRowViewOptions) { - _state.update { + updateState { it.copy( rowData = it.rowData.toMutableList().map { row -> @@ -319,6 +319,13 @@ class HomeSettingsViewModel } } } + + private fun updateState(update: (HomePageSettingsState) -> HomePageSettingsState) { + _state.update { + update.invoke(it) + } + homeSettingsService.currentSettings.update { HomePageResolvedSettings(state.value.rows) } + } } data class HomePageSettingsState( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f0f23aaac4..150d121399 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -467,6 +467,7 @@ Recently released in %1$s Height Apply to all rows + Customize home page Disabled From d7236e7bbf5d034769becb6fcbf316aaae6cf817 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Sat, 24 Jan 2026 22:20:38 -0500 Subject: [PATCH 20/53] Ensure home settings are saved --- .../wholphin/ui/main/settings/HomeSettingsViewModel.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 9bb22f7ecb..61c9187527 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -17,6 +17,7 @@ import com.github.damontecres.wholphin.data.model.HomeRowViewOptions import com.github.damontecres.wholphin.services.BackdropService import com.github.damontecres.wholphin.services.HomeSettingsService import com.github.damontecres.wholphin.services.UserPreferencesService +import com.github.damontecres.wholphin.services.hilt.IoCoroutineScope import com.github.damontecres.wholphin.ui.launchIO import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem import com.github.damontecres.wholphin.ui.showToast @@ -24,6 +25,7 @@ import com.github.damontecres.wholphin.util.HomeRowLoadingState 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.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.first @@ -43,11 +45,13 @@ class HomeSettingsViewModel private val userPreferencesService: UserPreferencesService, private val navDrawerItemRepository: NavDrawerItemRepository, private val backdropService: BackdropService, + @param:IoCoroutineScope private val ioScope: CoroutineScope, ) : ViewModel() { private val _state = MutableStateFlow(HomePageSettingsState.EMPTY) val state: StateFlow = _state init { + addCloseable { saveToLocal() } viewModelScope.launchIO { val navDrawerItems = navDrawerItemRepository @@ -305,11 +309,13 @@ class HomeSettingsViewModel } fun saveToLocal() { - viewModelScope.launchIO { + // This uses injected ioScope so that it will still run when the page is closing + ioScope.launchIO { serverRepository.currentUser.value?.let { user -> val rows = state.value.rows.map { it.config } val settings = HomePageSettings(rows = rows) try { + Timber.d("saveToLocal") homeSettingsService.saveToLocal(user.id, settings) showToast(context, context.getString(R.string.save), Toast.LENGTH_SHORT) } catch (ex: Exception) { From 668a3960f30bcbdddf84ed0c9b8093606604d8d6 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Sun, 25 Jan 2026 01:16:38 -0500 Subject: [PATCH 21/53] Refactoring --- .../wholphin/data/model/HomeRowConfig.kt | 58 ++++++++----------- .../wholphin/services/HomeSettingsService.kt | 24 ++++++-- .../services/SeerrServerRepository.kt | 1 - .../wholphin/ui/main/HomeViewModel.kt | 2 +- .../ui/main/settings/HomeSettingsRowList.kt | 4 +- .../ui/main/settings/HomeSettingsViewModel.kt | 12 ++-- 6 files changed, 56 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index 13d9678501..6f1bc36596 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -21,11 +21,11 @@ import org.jellyfin.sdk.model.serializer.UUIDSerializer import java.util.UUID @Serializable -sealed class HomeRowConfig { - abstract val id: Int - abstract val viewOptions: HomeRowViewOptions +sealed interface HomeRowConfig { + val id: Int + val viewOptions: HomeRowViewOptions - abstract fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig + fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig /** * Continue watching media that the user has started but not finished @@ -35,8 +35,8 @@ sealed class HomeRowConfig { data class ContinueWatching( override val id: Int, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): ContinueWatching = this.copy(viewOptions = viewOptions) } /** @@ -47,8 +47,8 @@ sealed class HomeRowConfig { data class NextUp( override val id: Int, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): NextUp = this.copy(viewOptions = viewOptions) } /** @@ -59,8 +59,8 @@ sealed class HomeRowConfig { data class ContinueWatchingCombined( override val id: Int, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): ContinueWatchingCombined = this.copy(viewOptions = viewOptions) } /** @@ -72,8 +72,8 @@ sealed class HomeRowConfig { override val id: Int, val parentId: UUID, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): RecentlyAdded = this.copy(viewOptions = viewOptions) } /** @@ -85,8 +85,8 @@ sealed class HomeRowConfig { override val id: Int, val parentId: UUID, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): RecentlyReleased = this.copy(viewOptions = viewOptions) } /** @@ -102,8 +102,8 @@ sealed class HomeRowConfig { heightDp = (Cards.HEIGHT_2X3_DP * .75f).toInt().let { it - it % 4 }, aspectRatio = AspectRatio.WIDE, ), - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): Genres = this.copy(viewOptions = viewOptions) } /** @@ -117,8 +117,8 @@ sealed class HomeRowConfig { val recursive: Boolean, val sort: SortAndDirection? = null, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): ByParent = this.copy(viewOptions = viewOptions) } /** @@ -131,34 +131,26 @@ sealed class HomeRowConfig { val name: String, val getItems: GetItemsRequest, override val viewOptions: HomeRowViewOptions, - ) : HomeRowConfig() { - override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): GetItems = this.copy(viewOptions = viewOptions) } } -data class HomeRowConfigDisplay( - val title: String, - val config: HomeRowConfig, -) - @Serializable @SerialName("HomePageSettings") data class HomePageSettings( val rows: List, - val version: Int = 1, + val version: Int = SUPPORTED_HOME_PAGE_SETTINGS_VERSION, ) { companion object { val EMPTY = HomePageSettings(listOf()) } } -data class HomePageResolvedSettings( - val rows: List, -) { - companion object { - val EMPTY = HomePageResolvedSettings(listOf()) - } -} +/** + * This is the max version supported by this version of the app + */ +const val SUPPORTED_HOME_PAGE_SETTINGS_VERSION = 1 @Serializable data class HomeRowViewOptions( diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index d9c184a3d3..995cae8c1b 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -4,11 +4,10 @@ import android.content.Context import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.NavDrawerItemRepository import com.github.damontecres.wholphin.data.model.BaseItem -import com.github.damontecres.wholphin.data.model.HomePageResolvedSettings import com.github.damontecres.wholphin.data.model.HomePageSettings import com.github.damontecres.wholphin.data.model.HomeRowConfig -import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay import com.github.damontecres.wholphin.data.model.HomeRowViewOptions +import com.github.damontecres.wholphin.data.model.SUPPORTED_HOME_PAGE_SETTINGS_VERSION import com.github.damontecres.wholphin.preferences.HomePagePreferences import com.github.damontecres.wholphin.ui.DefaultItemFields import com.github.damontecres.wholphin.ui.SlimItemFields @@ -86,7 +85,9 @@ class HomeSettingsService ): HomePageSettings? { val current = getDisplayPreferences(userId, displayPreferencesId) return current.customPrefs[DISPLAY_PREF_ID]?.let { - Json.decodeFromString(it) + Json + .decodeFromString(it) + .takeIf { it.version <= SUPPORTED_HOME_PAGE_SETTINGS_VERSION } } } @@ -120,7 +121,9 @@ class HomeSettingsService val file = File(dir, filename(userId)) return if (file.exists()) { file.inputStream().use { - jsonParser.decodeFromStream(it) + jsonParser + .decodeFromStream(it) + .takeIf { it.version <= SUPPORTED_HOME_PAGE_SETTINGS_VERSION } } } else { null @@ -534,3 +537,16 @@ class HomeSettingsService const val CUSTOM_PREF_ID = "home_settings" } } + +data class HomeRowConfigDisplay( + val title: String, + val config: HomeRowConfig, +) + +data class HomePageResolvedSettings( + val rows: List, +) { + companion object { + val EMPTY = HomePageResolvedSettings(listOf()) + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt b/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt index f6d2578691..41b3752066 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt @@ -11,7 +11,6 @@ import com.github.damontecres.wholphin.api.seerr.model.PublicSettings import com.github.damontecres.wholphin.api.seerr.model.User import com.github.damontecres.wholphin.data.SeerrServerDao import com.github.damontecres.wholphin.data.ServerRepository -import com.github.damontecres.wholphin.data.model.HomePageResolvedSettings import com.github.damontecres.wholphin.data.model.SeerrAuthMethod import com.github.damontecres.wholphin.data.model.SeerrPermission import com.github.damontecres.wholphin.data.model.SeerrServer diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt index ebde16a854..f51db306b9 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt @@ -6,10 +6,10 @@ import androidx.lifecycle.viewModelScope import com.github.damontecres.wholphin.data.NavDrawerItemRepository import com.github.damontecres.wholphin.data.ServerRepository import com.github.damontecres.wholphin.data.model.BaseItem -import com.github.damontecres.wholphin.data.model.HomePageResolvedSettings import com.github.damontecres.wholphin.services.BackdropService import com.github.damontecres.wholphin.services.DatePlayedService import com.github.damontecres.wholphin.services.FavoriteWatchManager +import com.github.damontecres.wholphin.services.HomePageResolvedSettings import com.github.damontecres.wholphin.services.HomeSettingsService import com.github.damontecres.wholphin.services.NavigationManager import com.github.damontecres.wholphin.services.UserPreferencesService diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt index b1e72e92fc..7740065bef 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt @@ -34,7 +34,7 @@ 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.data.model.HomeRowConfigDisplay +import com.github.damontecres.wholphin.services.HomeRowConfigDisplay import com.github.damontecres.wholphin.ui.FontAwesome import com.github.damontecres.wholphin.ui.components.Button import com.github.damontecres.wholphin.ui.tryRequestFocus @@ -108,7 +108,7 @@ fun HomeSettingsRowList( config = row, moveUpAllowed = index > 0, moveDownAllowed = index != state.rows.lastIndex, - deleteAllowed = true, + deleteAllowed = state.rows.size > 1, onClickMove = { onClickMove.invoke(it, index) }, onClickDelete = { onClickDelete.invoke(index) }, onClick = { onClick.invoke(index, row) }, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 61c9187527..8a3d3984a5 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -9,12 +9,12 @@ import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.NavDrawerItemRepository import com.github.damontecres.wholphin.data.ServerRepository import com.github.damontecres.wholphin.data.model.BaseItem -import com.github.damontecres.wholphin.data.model.HomePageResolvedSettings import com.github.damontecres.wholphin.data.model.HomePageSettings import com.github.damontecres.wholphin.data.model.HomeRowConfig -import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay import com.github.damontecres.wholphin.data.model.HomeRowViewOptions import com.github.damontecres.wholphin.services.BackdropService +import com.github.damontecres.wholphin.services.HomePageResolvedSettings +import com.github.damontecres.wholphin.services.HomeRowConfigDisplay import com.github.damontecres.wholphin.services.HomeSettingsService import com.github.damontecres.wholphin.services.UserPreferencesService import com.github.damontecres.wholphin.services.hilt.IoCoroutineScope @@ -316,8 +316,12 @@ class HomeSettingsViewModel val settings = HomePageSettings(rows = rows) try { Timber.d("saveToLocal") - homeSettingsService.saveToLocal(user.id, settings) - showToast(context, context.getString(R.string.save), Toast.LENGTH_SHORT) + val local = homeSettingsService.loadFromLocal(user.id) + // Only save if there are changes + if (local != settings) { + homeSettingsService.saveToLocal(user.id, settings) + showToast(context, context.getString(R.string.save), Toast.LENGTH_SHORT) + } } catch (ex: Exception) { Timber.e(ex) showToast(context, "Error saving: ${ex.localizedMessage}") From f58b371698f2e445c46acd128bb718c10399fc52 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Sun, 25 Jan 2026 01:32:14 -0500 Subject: [PATCH 22/53] Parse by row --- .../wholphin/data/model/HomeRowConfig.kt | 14 ++++---- .../wholphin/services/HomeSettingsService.kt | 35 +++++++++++++------ .../wholphin/test/TestHomeRowSamples.kt | 35 +++++++++++++++++++ 3 files changed, 67 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index 6f1bc36596..cef6561b52 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -34,7 +34,7 @@ sealed interface HomeRowConfig { @SerialName("ContinueWatching") data class ContinueWatching( override val id: Int, - override val viewOptions: HomeRowViewOptions, + override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) : HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): ContinueWatching = this.copy(viewOptions = viewOptions) } @@ -46,7 +46,7 @@ sealed interface HomeRowConfig { @SerialName("NextUp") data class NextUp( override val id: Int, - override val viewOptions: HomeRowViewOptions, + override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) : HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): NextUp = this.copy(viewOptions = viewOptions) } @@ -58,7 +58,7 @@ sealed interface HomeRowConfig { @SerialName("ContinueWatchingCombined") data class ContinueWatchingCombined( override val id: Int, - override val viewOptions: HomeRowViewOptions, + override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) : HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): ContinueWatchingCombined = this.copy(viewOptions = viewOptions) } @@ -71,7 +71,7 @@ sealed interface HomeRowConfig { data class RecentlyAdded( override val id: Int, val parentId: UUID, - override val viewOptions: HomeRowViewOptions, + override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) : HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): RecentlyAdded = this.copy(viewOptions = viewOptions) } @@ -84,7 +84,7 @@ sealed interface HomeRowConfig { data class RecentlyReleased( override val id: Int, val parentId: UUID, - override val viewOptions: HomeRowViewOptions, + override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) : HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): RecentlyReleased = this.copy(viewOptions = viewOptions) } @@ -116,7 +116,7 @@ sealed interface HomeRowConfig { val parentId: UUID, val recursive: Boolean, val sort: SortAndDirection? = null, - override val viewOptions: HomeRowViewOptions, + override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) : HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): ByParent = this.copy(viewOptions = viewOptions) } @@ -130,7 +130,7 @@ sealed interface HomeRowConfig { override val id: Int, val name: String, val getItems: GetItemsRequest, - override val viewOptions: HomeRowViewOptions, + override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) : HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): GetItems = this.copy(viewOptions = viewOptions) } diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index 995cae8c1b..a213707ea5 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -7,7 +7,6 @@ import com.github.damontecres.wholphin.data.model.BaseItem import com.github.damontecres.wholphin.data.model.HomePageSettings import com.github.damontecres.wholphin.data.model.HomeRowConfig import com.github.damontecres.wholphin.data.model.HomeRowViewOptions -import com.github.damontecres.wholphin.data.model.SUPPORTED_HOME_PAGE_SETTINGS_VERSION import com.github.damontecres.wholphin.preferences.HomePagePreferences import com.github.damontecres.wholphin.ui.DefaultItemFields import com.github.damontecres.wholphin.ui.SlimItemFields @@ -24,8 +23,11 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.update import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.Json -import kotlinx.serialization.json.decodeFromStream +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.decodeFromJsonElement import kotlinx.serialization.json.encodeToStream +import kotlinx.serialization.json.jsonArray +import kotlinx.serialization.json.jsonObject import org.jellyfin.sdk.api.client.ApiClient import org.jellyfin.sdk.api.client.extensions.displayPreferencesApi import org.jellyfin.sdk.api.client.extensions.userLibraryApi @@ -85,9 +87,8 @@ class HomeSettingsService ): HomePageSettings? { val current = getDisplayPreferences(userId, displayPreferencesId) return current.customPrefs[DISPLAY_PREF_ID]?.let { - Json - .decodeFromString(it) - .takeIf { it.version <= SUPPORTED_HOME_PAGE_SETTINGS_VERSION } + val jsonElement = jsonParser.parseToJsonElement(it) + decode(jsonElement) } } @@ -120,16 +121,30 @@ class HomeSettingsService val dir = File(context.filesDir, CUSTOM_PREF_ID) val file = File(dir, filename(userId)) return if (file.exists()) { - file.inputStream().use { - jsonParser - .decodeFromStream(it) - .takeIf { it.version <= SUPPORTED_HOME_PAGE_SETTINGS_VERSION } - } + val fileContents = file.readText() + val jsonElement = jsonParser.parseToJsonElement(fileContents) + decode(jsonElement) } else { null } } + fun decode(element: JsonElement): HomePageSettings { + val rowsElement = element.jsonObject["rows"]?.jsonArray + val rows = + rowsElement + ?.mapNotNull { row -> + try { + jsonParser.decodeFromJsonElement(row) + } catch (ex: Exception) { + Timber.w(ex, "Unknown row %s", row) + // TODO maybe use placeholder instead of null? + null + } + }.orEmpty() + return HomePageSettings(rows) + } + suspend fun updateCurrent(userId: UUID) { Timber.v("Getting setting for %s", userId) // User local then server/remote otherwise create a default diff --git a/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt b/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt index 5ab69cadcf..d028934857 100644 --- a/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt +++ b/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt @@ -3,9 +3,11 @@ package com.github.damontecres.wholphin.test import com.github.damontecres.wholphin.data.model.HomeRowConfig import com.github.damontecres.wholphin.data.model.HomeRowViewOptions import com.github.damontecres.wholphin.preferences.PrefContentScale +import com.github.damontecres.wholphin.services.HomeSettingsService import com.github.damontecres.wholphin.ui.AspectRatio import com.github.damontecres.wholphin.ui.components.ViewOptionImageType import com.github.damontecres.wholphin.ui.data.SortAndDirection +import io.mockk.mockk import kotlinx.serialization.json.Json import org.jellyfin.sdk.model.UUID import org.jellyfin.sdk.model.api.BaseItemKind @@ -112,4 +114,37 @@ class TestHomeRowSamples { println(string) json.decodeFromString>(string) } + + @Test + fun test() { + val service = + HomeSettingsService( + context = mockk(), + api = mockk(), + userPreferencesService = mockk(), + navDrawerItemRepository = mockk(), + latestNextUpService = mockk(), + imageUrlService = mockk(), + ) + + val str = """{ + "type": "HomePageSettings", + "version": 1, + "rows": [ + { + "type": "RecentlyAdded", + "id": 0, + "parentId": "1dd1c2fd-2e1b-48e4-ba94-17a2350fe9cf" + }, + { + "type": "Does not exist", + "viewOptions": {} + } + ] + }""" + + val jsonElement = service.jsonParser.parseToJsonElement(str) + val settings = service.decode(jsonElement) + Assert.assertEquals(1, settings.rows.size) + } } From 15ce562957e08c5bfb113155d784358ae714cb3f Mon Sep 17 00:00:00 2001 From: Damontecres Date: Sun, 25 Jan 2026 11:08:45 -0500 Subject: [PATCH 23/53] Move ID into display models & add documentation --- .../wholphin/data/model/HomeRowConfig.kt | 19 +-- .../wholphin/services/HomeSettingsService.kt | 143 +++++++++++------- .../services/SeerrServerRepository.kt | 2 +- .../ui/main/settings/HomeSettingsPage.kt | 4 +- .../ui/main/settings/HomeSettingsRowList.kt | 2 +- .../ui/main/settings/HomeSettingsViewModel.kt | 52 +++---- .../wholphin/test/TestHomeRowSamples.kt | 11 +- 7 files changed, 123 insertions(+), 110 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index cef6561b52..8e98d947fc 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -22,7 +22,6 @@ import java.util.UUID @Serializable sealed interface HomeRowConfig { - val id: Int val viewOptions: HomeRowViewOptions fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig @@ -33,7 +32,6 @@ sealed interface HomeRowConfig { @Serializable @SerialName("ContinueWatching") data class ContinueWatching( - override val id: Int, override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) : HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): ContinueWatching = this.copy(viewOptions = viewOptions) @@ -45,7 +43,6 @@ sealed interface HomeRowConfig { @Serializable @SerialName("NextUp") data class NextUp( - override val id: Int, override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) : HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): NextUp = this.copy(viewOptions = viewOptions) @@ -57,7 +54,6 @@ sealed interface HomeRowConfig { @Serializable @SerialName("ContinueWatchingCombined") data class ContinueWatchingCombined( - override val id: Int, override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) : HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): ContinueWatchingCombined = this.copy(viewOptions = viewOptions) @@ -69,7 +65,6 @@ sealed interface HomeRowConfig { @Serializable @SerialName("RecentlyAdded") data class RecentlyAdded( - override val id: Int, val parentId: UUID, override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) : HomeRowConfig { @@ -82,7 +77,6 @@ sealed interface HomeRowConfig { @Serializable @SerialName("RecentlyReleased") data class RecentlyReleased( - override val id: Int, val parentId: UUID, override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) : HomeRowConfig { @@ -95,7 +89,6 @@ sealed interface HomeRowConfig { @Serializable @SerialName("Genres") data class Genres( - override val id: Int, val parentId: UUID, override val viewOptions: HomeRowViewOptions = HomeRowViewOptions( @@ -112,7 +105,6 @@ sealed interface HomeRowConfig { @Serializable @SerialName("ByParent") data class ByParent( - override val id: Int, val parentId: UUID, val recursive: Boolean, val sort: SortAndDirection? = null, @@ -127,7 +119,6 @@ sealed interface HomeRowConfig { @Serializable @SerialName("GetItems") data class GetItems( - override val id: Int, val name: String, val getItems: GetItemsRequest, override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), @@ -136,6 +127,11 @@ sealed interface HomeRowConfig { } } +/** + * Root class for home page settings + * + * Contains the list of rows and a version + */ @Serializable @SerialName("HomePageSettings") data class HomePageSettings( @@ -152,6 +148,11 @@ data class HomePageSettings( */ const val SUPPORTED_HOME_PAGE_SETTINGS_VERSION = 1 +/** + * View options for displaying a row + * + * Allows for changing things like height or aspect ratio + */ @Serializable data class HomeRowViewOptions( val heightDp: Int = Cards.HEIGHT_2X3_DP, diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index a213707ea5..c1c4d7303b 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -6,7 +6,6 @@ import com.github.damontecres.wholphin.data.NavDrawerItemRepository import com.github.damontecres.wholphin.data.model.BaseItem import com.github.damontecres.wholphin.data.model.HomePageSettings import com.github.damontecres.wholphin.data.model.HomeRowConfig -import com.github.damontecres.wholphin.data.model.HomeRowViewOptions import com.github.damontecres.wholphin.preferences.HomePagePreferences import com.github.damontecres.wholphin.ui.DefaultItemFields import com.github.damontecres.wholphin.ui.SlimItemFields @@ -38,7 +37,6 @@ import org.jellyfin.sdk.model.api.UserDto import org.jellyfin.sdk.model.api.request.GetGenresRequest import org.jellyfin.sdk.model.api.request.GetItemsRequest import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest -import org.jellyfin.sdk.model.serializer.toUUID import timber.log.Timber import java.io.File import javax.inject.Inject @@ -63,6 +61,11 @@ class HomeSettingsService val currentSettings = MutableStateFlow(HomePageResolvedSettings.EMPTY) + /** + * Saves a [HomePageSettings] to the server for the user under the display preference ID + * + * @see loadFromServer + */ suspend fun saveToServer( userId: UUID, settings: HomePageSettings, @@ -81,6 +84,13 @@ class HomeSettingsService ) } + /** + * Reads a [HomePageSettings] from the server for the user and display preference ID + * + * Returns null if there is none saved + * + * @see saveToServer + */ suspend fun loadFromServer( userId: UUID, displayPreferencesId: String = DISPLAY_PREF_ID, @@ -102,8 +112,16 @@ class HomeSettingsService client = context.getString(R.string.app_name), ).content + /** + * Computes the filename for locally saved [HomePageSettings] + */ private fun filename(userId: UUID) = "${CUSTOM_PREF_ID}_${userId.toServerString()}.json" + /** + * Save the [HomePageSettings] for the user locally on the device + * + * @see loadFromLocal + */ @OptIn(ExperimentalSerializationApi::class) suspend fun saveToLocal( userId: UUID, @@ -116,6 +134,11 @@ class HomeSettingsService } } + /** + * Reads [HomePageSettings] for the user if it exists + * + * @see saveToLocal + */ @OptIn(ExperimentalSerializationApi::class) suspend fun loadFromLocal(userId: UUID): HomePageSettings? { val dir = File(context.filesDir, CUSTOM_PREF_ID) @@ -129,6 +152,11 @@ class HomeSettingsService } } + /** + * Decodes [HomePageSettings] from a [JsonElement] skipping any unknown/unparsable rows + * + * This is public only for testing + */ fun decode(element: JsonElement): HomePageSettings { val rowsElement = element.jsonObject["rows"]?.jsonArray val rows = @@ -145,7 +173,14 @@ class HomeSettingsService return HomePageSettings(rows) } - suspend fun updateCurrent(userId: UUID) { + /** + * Loads [HomePageSettings] into [currentSettings] + * + * First checks locally, then on the server, and finally creates a default if needed + * + * Does not persist either the server nor default + */ + suspend fun loadCurrentSettings(userId: UUID) { Timber.v("Getting setting for %s", userId) // User local then server/remote otherwise create a default val settings = loadFromLocal(userId) ?: loadFromServer(userId) @@ -153,7 +188,10 @@ class HomeSettingsService if (settings != null) { Timber.v("Found settings") // Resolve - val resolvedRows = settings.rows.map { convert(it) } + val resolvedRows = + settings.rows.mapIndexed { index, config -> + resolve(index, config) + } HomePageResolvedSettings(resolvedRows) } else { createDefault(userId) @@ -162,7 +200,10 @@ class HomeSettingsService currentSettings.update { resolvedSettings } } - suspend fun createDefault(userId: UUID): HomePageResolvedSettings { + /** + * Create a default [HomePageResolvedSettings] using the available libraries + */ + private suspend fun createDefault(userId: UUID): HomePageResolvedSettings { Timber.v("Creating default settings") val navDrawerItems = navDrawerItemRepository.getNavDrawerItems() val libraries = @@ -179,76 +220,51 @@ class HomeSettingsService .getFilteredNavDrawerItems(navDrawerItems) .filter { it is ServerNavDrawerItem } .mapIndexed { index, it -> - val id = (it as ServerNavDrawerItem).itemId - val name = libraries.firstOrNull { it.itemId == id }?.name + val parentId = (it as ServerNavDrawerItem).itemId + val name = libraries.firstOrNull { it.itemId == parentId }?.name val title = name?.let { context.getString(R.string.recently_added_in, it) } ?: context.getString(R.string.recently_added) HomeRowConfigDisplay( - title, - HomeRowConfig.RecentlyAdded( - index, - id, - HomeRowViewOptions(), - ), + id = index, + title = title, + config = HomeRowConfig.RecentlyAdded(parentId), ) } val continueWatchingRows = - if (prefs.combineContinueNext) { + if (prefs.combineContinueNext) { // TODO listOf( HomeRowConfigDisplay( - context.getString(R.string.combine_continue_next), - HomeRowConfig.ContinueWatchingCombined( - includedIds.size + 1, - HomeRowViewOptions(), - ), + id = includedIds.size + 1, + title = context.getString(R.string.combine_continue_next), + config = HomeRowConfig.ContinueWatchingCombined(), ), ) } else { listOf( HomeRowConfigDisplay( - context.getString(R.string.continue_watching), - HomeRowConfig.ContinueWatching( - includedIds.size + 1, - HomeRowViewOptions(), - ), + id = includedIds.size + 1, + title = context.getString(R.string.continue_watching), + config = HomeRowConfig.ContinueWatching(), ), HomeRowConfigDisplay( - context.getString(R.string.next_up), - HomeRowConfig.NextUp( - includedIds.size + 2, - HomeRowViewOptions(), - ), + id = includedIds.size + 2, + title = context.getString(R.string.next_up), + config = HomeRowConfig.NextUp(), ), ) } - val rowConfig = - continueWatchingRows + includedIds + - // TODO remove after testing - listOf( - HomeRowConfigDisplay( - "Collection", - HomeRowConfig.ByParent( - id = 100, - parentId = "34ab6fd1f51c41bb014981f2e334f465".toUUID(), - recursive = true, - viewOptions = HomeRowViewOptions(), - ), - ), - HomeRowConfigDisplay( - "Playlist", - HomeRowConfig.ByParent( - id = 101, - parentId = "f94be36e9836127a0bccfc7843b19e5b".toUUID(), - recursive = true, - viewOptions = HomeRowViewOptions(), - ), - ), - ) + val rowConfig = continueWatchingRows + includedIds return HomePageResolvedSettings(rowConfig) } - suspend fun convert(config: HomeRowConfig): HomeRowConfigDisplay = + /** + * Converts a [HomeRowConfig] into [HomeRowConfigDisplay] for UI purposes + */ + private suspend fun resolve( + id: Int, + config: HomeRowConfig, + ): HomeRowConfigDisplay = when (config) { is HomeRowConfig.ByParent -> { val name = @@ -256,6 +272,7 @@ class HomeSettingsService .getItem(itemId = config.parentId) .content.name ?: "" HomeRowConfigDisplay( + id, name, config, ) @@ -263,6 +280,7 @@ class HomeSettingsService is HomeRowConfig.ContinueWatching -> { HomeRowConfigDisplay( + id, context.getString(R.string.continue_watching), config, ) @@ -270,6 +288,7 @@ class HomeSettingsService is HomeRowConfig.ContinueWatchingCombined -> { HomeRowConfigDisplay( + id, context.getString(R.string.combine_continue_next), config, ) @@ -281,17 +300,19 @@ class HomeSettingsService .getItem(itemId = config.parentId) .content.name ?: "" HomeRowConfigDisplay( + id, context.getString(R.string.genres_in, name), config, ) } is HomeRowConfig.GetItems -> { - HomeRowConfigDisplay(config.name, config) + HomeRowConfigDisplay(id, config.name, config) } is HomeRowConfig.NextUp -> { HomeRowConfigDisplay( + id, context.getString(R.string.next_up), config, ) @@ -303,6 +324,7 @@ class HomeSettingsService .getItem(itemId = config.parentId) .content.name ?: "" HomeRowConfigDisplay( + id, context.getString(R.string.recently_added_in, name), config, ) @@ -314,12 +336,16 @@ class HomeSettingsService .getItem(itemId = config.parentId) .content.name ?: "" HomeRowConfigDisplay( + id, context.getString(R.string.recently_released_in, name), config, ) } } + /** + * Fetch the data from the server for a given [HomeRowConfig] + */ suspend fun fetchDataForRow( row: HomeRowConfig, scope: CoroutineScope, @@ -553,11 +579,20 @@ class HomeSettingsService } } +/** + * A [HomeRowConfig] with a resolved ID and title so it is usable in the UI + */ data class HomeRowConfigDisplay( + val id: Int, val title: String, val config: HomeRowConfig, ) +/** + * List of resolved [HomeRowConfig]s as [HomeRowConfigDisplay]s + * + * @see HomePageSettings + */ data class HomePageResolvedSettings( val rows: List, ) { diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt b/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt index 41b3752066..b28b682ba6 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/SeerrServerRepository.kt @@ -225,7 +225,7 @@ class UserSwitchListener if (user != null) { // Check for home settings launchIO { - homeSettingsService.updateCurrent(user.id) + homeSettingsService.loadCurrentSettings(user.id) } // Check for seerr server launchIO { diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index 72cfa7a711..56aee366cd 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -72,7 +72,7 @@ fun HomeSettingsPage( onClickMove = viewModel::moveRow, onClickDelete = viewModel::deleteRow, onClick = { index, row -> - destination = HomeSettingsDestination.RowSettings(row.config.id) + destination = HomeSettingsDestination.RowSettings(row.id) scope.launch(ExceptionHandler()) { Timber.v("Scroll to $index") listState.scrollToItem(index) @@ -108,7 +108,7 @@ fun HomeSettingsPage( is HomeSettingsDestination.RowSettings -> { val row = state.rows - .first { it.config.id == dest.rowId } + .first { it.id == dest.rowId } HomeRowSettings( title = row.title, viewOptions = row.config.viewOptions, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt index 7740065bef..52cd0f835c 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt @@ -103,7 +103,7 @@ fun HomeSettingsRowList( item { HorizontalDivider() } - itemsIndexed(state.rows, key = { _, row -> row.config.id }) { index, row -> + itemsIndexed(state.rows, key = { _, row -> row.id }) { index, row -> HomeRowConfigContent( config = row, moveUpAllowed = index > 0, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 8a3d3984a5..0881dc72c7 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -162,31 +162,25 @@ class HomeSettingsViewModel when (type) { MetaRowType.CONTINUE_WATCHING -> { HomeRowConfigDisplay( - context.getString(R.string.continue_watching), - HomeRowConfig.ContinueWatching( - id, - HomeRowViewOptions(), - ), + id = id, + title = context.getString(R.string.continue_watching), + config = HomeRowConfig.ContinueWatching(), ) } MetaRowType.NEXT_UP -> { HomeRowConfigDisplay( - context.getString(R.string.continue_watching), - HomeRowConfig.NextUp( - id, - HomeRowViewOptions(), - ), + id = id, + title = context.getString(R.string.continue_watching), + config = HomeRowConfig.NextUp(), ) } MetaRowType.COMBINED_CONTINUE_WATCHING -> { HomeRowConfigDisplay( - context.getString(R.string.combine_continue_next), - HomeRowConfig.ContinueWatchingCombined( - id, - HomeRowViewOptions(), - ), + id = id, + title = context.getString(R.string.combine_continue_next), + config = HomeRowConfig.ContinueWatchingCombined(), ) } } @@ -212,12 +206,9 @@ class HomeSettingsViewModel val title = library.name.let { context.getString(R.string.recently_added_in, it) } HomeRowConfigDisplay( - title, - HomeRowConfig.RecentlyAdded( - id, - library.itemId, - HomeRowViewOptions(), - ), + id = id, + title = title, + config = HomeRowConfig.RecentlyAdded(library.itemId), ) } @@ -230,23 +221,18 @@ class HomeSettingsViewModel ) } HomeRowConfigDisplay( - title, - HomeRowConfig.RecentlyReleased( - id, - library.itemId, - HomeRowViewOptions(), - ), + id = id, + title = title, + config = HomeRowConfig.RecentlyReleased(library.itemId), ) } LibraryRowType.GENRES -> { val title = library.name.let { context.getString(R.string.genres_in, it) } HomeRowConfigDisplay( - title, - HomeRowConfig.Genres( - id, - library.itemId, - ), + id = id, + title = title, + config = HomeRowConfig.Genres(library.itemId), ) } } @@ -266,7 +252,7 @@ class HomeSettingsViewModel ) { viewModelScope.launchIO { updateState { - val index = it.rows.indexOfFirst { it.config.id == rowId } + val index = it.rows.indexOfFirst { it.id == rowId } val newRowConfig = it.rows[index] .config diff --git a/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt b/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt index d028934857..ab4d170ac5 100644 --- a/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt +++ b/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt @@ -23,7 +23,6 @@ class TestHomeRowSamples { val SAMPLES = listOf( HomeRowConfig.RecentlyAdded( - id = 0, parentId = UUID.randomUUID(), viewOptions = HomeRowViewOptions( @@ -37,36 +36,29 @@ class TestHomeRowSamples { ), ), HomeRowConfig.RecentlyReleased( - id = 0, parentId = UUID.randomUUID(), viewOptions = HomeRowViewOptions(), ), HomeRowConfig.Genres( - id = 0, parentId = UUID.randomUUID(), viewOptions = HomeRowViewOptions(), ), HomeRowConfig.ContinueWatching( - id = 0, viewOptions = HomeRowViewOptions(), ), HomeRowConfig.NextUp( - id = 0, viewOptions = HomeRowViewOptions(), ), HomeRowConfig.ContinueWatchingCombined( - id = 0, viewOptions = HomeRowViewOptions(), ), HomeRowConfig.ByParent( - id = 0, parentId = UUID.randomUUID(), recursive = true, sort = SortAndDirection(ItemSortBy.CRITIC_RATING, SortOrder.ASCENDING), viewOptions = HomeRowViewOptions(), ), HomeRowConfig.GetItems( - id = 0, name = "Episodes by date created", getItems = GetItemsRequest( @@ -116,7 +108,7 @@ class TestHomeRowSamples { } @Test - fun test() { + fun `Parse list of rows with an unknown type`() { val service = HomeSettingsService( context = mockk(), @@ -133,7 +125,6 @@ class TestHomeRowSamples { "rows": [ { "type": "RecentlyAdded", - "id": 0, "parentId": "1dd1c2fd-2e1b-48e4-ba94-17a2350fe9cf" }, { From efb87bd692556723bdad6d7be2d69ad4c98d2c93 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Sun, 25 Jan 2026 19:01:33 -0500 Subject: [PATCH 24/53] UI controls --- .../damontecres/wholphin/MainActivity.kt | 4 +- .../wholphin/data/model/HomeRowConfig.kt | 113 +---------------- .../wholphin/services/HomeSettingsService.kt | 13 +- .../ui/main/settings/HomeRowSettings.kt | 119 +++++++++++++++++- .../ui/main/settings/HomeSettingsPage.kt | 3 + .../ui/main/settings/HomeSettingsRowList.kt | 38 ++++++ .../ui/main/settings/HomeSettingsViewModel.kt | 22 ++++ 7 files changed, 186 insertions(+), 126 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt b/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt index c7b12bfc34..b6772df8a9 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt @@ -265,7 +265,9 @@ class MainActivity : AppCompatActivity() { server = current.server, startDestination = requestedDestination - ?: Destination.Home(), + // TODO undo after testing + // ?: Destination.Home(), + ?: Destination.HomeSettings, navigationManager = navigationManager, preferences = preferences, modifier = Modifier.fillMaxSize(), diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index 8e98d947fc..46c3e664fa 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -2,16 +2,10 @@ package com.github.damontecres.wholphin.data.model -import com.github.damontecres.wholphin.R -import com.github.damontecres.wholphin.preferences.AppChoicePreference -import com.github.damontecres.wholphin.preferences.AppClickablePreference -import com.github.damontecres.wholphin.preferences.AppSliderPreference -import com.github.damontecres.wholphin.preferences.AppSwitchPreference import com.github.damontecres.wholphin.preferences.PrefContentScale import com.github.damontecres.wholphin.ui.AspectRatio import com.github.damontecres.wholphin.ui.Cards import com.github.damontecres.wholphin.ui.components.ViewOptionImageType -import com.github.damontecres.wholphin.ui.components.ViewOptions import com.github.damontecres.wholphin.ui.data.SortAndDirection import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -160,109 +154,6 @@ data class HomeRowViewOptions( val contentScale: PrefContentScale = PrefContentScale.FIT, val aspectRatio: AspectRatio = AspectRatio.TALL, val imageType: ViewOptionImageType = ViewOptionImageType.PRIMARY, - val showTitles: Boolean = true, + val showTitles: Boolean = false, val useSeries: Boolean = true, -) { - companion object { - val ViewOptionsColumns = - AppSliderPreference( - title = R.string.height, - defaultValue = Cards.HEIGHT_2X3_DP.toLong(), - min = 64L, - max = Cards.HEIGHT_2X3_DP + 64L, - interval = 4, - getter = { it.heightDp.toLong() }, - setter = { prefs, value -> prefs.copy(heightDp = value.toInt()) }, - ) - val ViewOptionsSpacing = - AppSliderPreference( - title = R.string.spacing, - defaultValue = 16, - min = 0, - max = 32, - interval = 2, - getter = { it.spacing.toLong() }, - setter = { prefs, value -> prefs.copy(spacing = value.toInt()) }, - ) - - val ViewOptionsContentScale = - AppChoicePreference( - title = R.string.global_content_scale, - defaultValue = PrefContentScale.FIT, - displayValues = R.array.content_scale, - getter = { it.contentScale }, - setter = { viewOptions, value -> viewOptions.copy(contentScale = value) }, - indexToValue = { PrefContentScale.forNumber(it) }, - valueToIndex = { it.number }, - ) - - val ViewOptionsAspectRatio = - AppChoicePreference( - title = R.string.aspect_ratio, - defaultValue = AspectRatio.TALL, - displayValues = R.array.aspect_ratios, - getter = { it.aspectRatio }, - setter = { viewOptions, value -> viewOptions.copy(aspectRatio = value) }, - indexToValue = { AspectRatio.entries[it] }, - valueToIndex = { it.ordinal }, - ) - - val ViewOptionsShowTitles = - AppSwitchPreference( - title = R.string.show_titles, - defaultValue = true, - getter = { it.showTitles }, - setter = { vo, value -> vo.copy(showTitles = value) }, - ) - - val ViewOptionsUseSeries = - AppSwitchPreference( - title = R.string.go_to_series, // TODO - defaultValue = true, - getter = { it.useSeries }, - setter = { vo, value -> vo.copy(useSeries = value) }, - ) - - val ViewOptionsImageType = - AppChoicePreference( - title = R.string.image_type, - defaultValue = ViewOptionImageType.PRIMARY, - displayValues = R.array.image_types, - getter = { it.imageType }, - setter = { viewOptions, value -> - val aspectRatio = - when (value) { - ViewOptionImageType.PRIMARY -> AspectRatio.TALL - ViewOptionImageType.THUMB -> AspectRatio.WIDE - } - viewOptions.copy(imageType = value, aspectRatio = aspectRatio) - }, - indexToValue = { ViewOptionImageType.entries[it] }, - valueToIndex = { it.ordinal }, - ) - - val ViewOptionsApplyAll = - AppClickablePreference( - title = R.string.apply_all_rows, - ) - - val ViewOptionsReset = - AppClickablePreference( - title = R.string.reset, - ) - - val OPTIONS = - listOf( - ViewOptionsImageType, - ViewOptionsAspectRatio, - // TODO -// ViewOptionsShowTitles, -// ViewOptionsUseSeries, - ViewOptionsColumns, - ViewOptionsSpacing, - ViewOptionsContentScale, - ViewOptionsApplyAll, - ViewOptionsReset, - ) - } -} +) diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index c1c4d7303b..94766fb884 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -550,22 +550,13 @@ class HomeSettingsService ) } } - val name = - if (row.name == null && request.parentId != null) { - // If a name was not provided, use the parent's name if available - api.userLibraryApi - .getItem(itemId = request.parentId!!) - .content.name - } else { - row.name - } GetItemsRequestHandler .execute(api, request) .content.items - .map { BaseItem.Companion.from(it, api, true) } + .map { BaseItem(it, true) } .let { HomeRowLoadingState.Success( - name ?: context.getString(R.string.collection), + row.name, it, row.viewOptions, ) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt index 5946fe4b01..5858a02808 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt @@ -15,8 +15,18 @@ import androidx.compose.ui.unit.dp 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.data.model.HomeRowViewOptions +import com.github.damontecres.wholphin.preferences.AppChoicePreference +import com.github.damontecres.wholphin.preferences.AppClickablePreference import com.github.damontecres.wholphin.preferences.AppPreference +import com.github.damontecres.wholphin.preferences.AppSliderPreference +import com.github.damontecres.wholphin.preferences.AppSwitchPreference +import com.github.damontecres.wholphin.preferences.PrefContentScale +import com.github.damontecres.wholphin.ui.AspectRatio +import com.github.damontecres.wholphin.ui.Cards +import com.github.damontecres.wholphin.ui.components.ViewOptionImageType +import com.github.damontecres.wholphin.ui.components.ViewOptions import com.github.damontecres.wholphin.ui.ifElse import com.github.damontecres.wholphin.ui.preferences.ComposablePreference import com.github.damontecres.wholphin.ui.tryRequestFocus @@ -39,7 +49,7 @@ fun HomeRowSettings( color = MaterialTheme.colorScheme.onSurface, ) LazyColumn { - itemsIndexed(HomeRowViewOptions.OPTIONS) { index, pref -> + itemsIndexed(Options.OPTIONS) { index, pref -> pref as AppPreference val interactionSource = remember { MutableInteractionSource() } val value = pref.getter.invoke(viewOptions) @@ -52,9 +62,9 @@ fun HomeRowSettings( }, interactionSource = interactionSource, onClickPreference = { pref -> - if (pref == HomeRowViewOptions.ViewOptionsReset) { + if (pref == Options.ViewOptionsReset) { onViewOptionsChange.invoke(defaultViewOptions) - } else if (pref == HomeRowViewOptions.ViewOptionsApplyAll) { + } else if (pref == Options.ViewOptionsApplyAll) { onApplyApplyAll.invoke() } }, @@ -70,3 +80,106 @@ fun HomeRowSettings( } } } + +internal object Options { + val ViewOptionsColumns = + AppSliderPreference( + title = R.string.height, + defaultValue = Cards.HEIGHT_2X3_DP.toLong(), + min = 64L, + max = Cards.HEIGHT_2X3_DP + 64L, + interval = 4, + getter = { it.heightDp.toLong() }, + setter = { prefs, value -> prefs.copy(heightDp = value.toInt()) }, + ) + val ViewOptionsSpacing = + AppSliderPreference( + title = R.string.spacing, + defaultValue = 16, + min = 0, + max = 32, + interval = 2, + getter = { it.spacing.toLong() }, + setter = { prefs, value -> prefs.copy(spacing = value.toInt()) }, + ) + + val ViewOptionsContentScale = + AppChoicePreference( + title = R.string.global_content_scale, + defaultValue = PrefContentScale.FIT, + displayValues = R.array.content_scale, + getter = { it.contentScale }, + setter = { viewOptions, value -> viewOptions.copy(contentScale = value) }, + indexToValue = { PrefContentScale.forNumber(it) }, + valueToIndex = { it.number }, + ) + + val ViewOptionsAspectRatio = + AppChoicePreference( + title = R.string.aspect_ratio, + defaultValue = AspectRatio.TALL, + displayValues = R.array.aspect_ratios, + getter = { it.aspectRatio }, + setter = { viewOptions, value -> viewOptions.copy(aspectRatio = value) }, + indexToValue = { AspectRatio.entries[it] }, + valueToIndex = { it.ordinal }, + ) + + val ViewOptionsShowTitles = + AppSwitchPreference( + title = R.string.show_titles, + defaultValue = true, + getter = { it.showTitles }, + setter = { vo, value -> vo.copy(showTitles = value) }, + ) + + val ViewOptionsUseSeries = + AppSwitchPreference( + title = R.string.go_to_series, // TODO + defaultValue = true, + getter = { it.useSeries }, + setter = { vo, value -> vo.copy(useSeries = value) }, + ) + + val ViewOptionsImageType = + AppChoicePreference( + title = R.string.image_type, + defaultValue = ViewOptionImageType.PRIMARY, + displayValues = R.array.image_types, + getter = { it.imageType }, + setter = { viewOptions, value -> + val aspectRatio = + when (value) { + ViewOptionImageType.PRIMARY -> AspectRatio.TALL + ViewOptionImageType.THUMB -> AspectRatio.WIDE + } + viewOptions.copy(imageType = value, aspectRatio = aspectRatio) + }, + indexToValue = { ViewOptionImageType.entries[it] }, + valueToIndex = { it.ordinal }, + ) + + val ViewOptionsApplyAll = + AppClickablePreference( + title = R.string.apply_all_rows, + ) + + val ViewOptionsReset = + AppClickablePreference( + title = R.string.reset, + ) + + val OPTIONS = + listOf( + ViewOptionsImageType, + ViewOptionsAspectRatio, + // TODO +// ViewOptionsShowTitles, +// ViewOptionsUseSeries, + ViewOptionsColumns, + ViewOptionsSpacing, + ViewOptionsContentScale, + ViewOptionsApplyAll, + ViewOptionsReset, + ) +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index 56aee366cd..289d1e85a7 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -78,6 +78,9 @@ fun HomeSettingsPage( listState.scrollToItem(index) } }, + onClickResize = { + viewModel.resizeCards(it) + }, modifier = destModifier, ) } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt index 52cd0f835c..c6761776c7 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt @@ -16,6 +16,7 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.Create import androidx.compose.material.icons.filled.Delete +import androidx.compose.material.icons.filled.Edit import androidx.compose.material3.HorizontalDivider import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -48,6 +49,7 @@ enum class MoveDirection { fun HomeSettingsRowList( state: HomePageSettingsState, onClick: (Int, HomeRowConfigDisplay) -> Unit, + onClickResize: (Int) -> Unit, onClickSaveLocal: () -> Unit, onClickAdd: () -> Unit, onClickMove: (MoveDirection, Int) -> Unit, @@ -82,6 +84,42 @@ fun HomeSettingsRowList( modifier = Modifier.focusRequester(firstFocus), ) } + item { + ListItem( + selected = false, + headlineContent = { + Text( + text = "Increase card sizes", + ) + }, + leadingContent = { + Icon( + imageVector = Icons.Default.Edit, + contentDescription = null, + ) + }, + onClick = { onClickResize.invoke(1) }, + modifier = Modifier, + ) + } + item { + ListItem( + selected = false, + headlineContent = { + Text( + text = "Decrease card sizes", + ) + }, + leadingContent = { + Icon( + imageVector = Icons.Default.Edit, + contentDescription = null, + ) + }, + onClick = { onClickResize.invoke(-1) }, + modifier = Modifier, + ) + } item { ListItem( selected = false, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 0881dc72c7..a5c1293d49 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -322,6 +322,28 @@ class HomeSettingsViewModel } homeSettingsService.currentSettings.update { HomePageResolvedSettings(state.value.rows) } } + + fun resizeCards(relative: Int) { + updateState { + val newRows = + it.rows.toMutableList().map { row -> + val vo = row.config.viewOptions + val newVo = vo.copy(heightDp = vo.heightDp + (4 * relative)) + row.copy(config = row.config.updateViewOptions(newVo)) + } + it.copy( + rows = newRows, + rowData = + it.rowData.toMutableList().mapIndexed { index, row -> + if (row is HomeRowLoadingState.Success) { + row.copy(viewOptions = newRows[index].config.viewOptions) + } else { + row + } + }, + ) + } + } } data class HomePageSettingsState( From ccb79257fdc8db2fc3762f1a2af280d310b7ed1a Mon Sep 17 00:00:00 2001 From: Damontecres Date: Tue, 27 Jan 2026 13:40:44 -0500 Subject: [PATCH 25/53] Add row for favorite items --- .../wholphin/data/model/HomeRowConfig.kt | 23 ++++- .../wholphin/services/HomeSettingsService.kt | 86 +++++++++++++++++-- .../damontecres/wholphin/ui/UiConstants.kt | 3 +- .../main/settings/HomeSettingsDestination.kt | 4 + .../main/settings/HomeSettingsFavoriteList.kt | 69 +++++++++++++++ .../main/settings/HomeSettingsLibraryList.kt | 72 +++++++++++++++- .../ui/main/settings/HomeSettingsPage.kt | 47 ++++++++-- .../ui/main/settings/HomeSettingsRowList.kt | 12 ++- .../ui/main/settings/HomeSettingsViewModel.kt | 42 ++++++++- 9 files changed, 334 insertions(+), 24 deletions(-) create mode 100644 app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index 46c3e664fa..ef0d77d41b 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -10,6 +10,7 @@ import com.github.damontecres.wholphin.ui.data.SortAndDirection import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers +import org.jellyfin.sdk.model.api.BaseItemKind import org.jellyfin.sdk.model.api.request.GetItemsRequest import org.jellyfin.sdk.model.serializer.UUIDSerializer import java.util.UUID @@ -86,13 +87,33 @@ sealed interface HomeRowConfig { val parentId: UUID, override val viewOptions: HomeRowViewOptions = HomeRowViewOptions( - heightDp = (Cards.HEIGHT_2X3_DP * .75f).toInt().let { it - it % 4 }, + heightDp = Cards.HEIGHT_EPISODE, aspectRatio = AspectRatio.WIDE, ), ) : HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): Genres = this.copy(viewOptions = viewOptions) } + /** + * Favorites for a specific type + */ + @Serializable + @SerialName("Favorite") + data class Favorite( + val kind: BaseItemKind, + override val viewOptions: HomeRowViewOptions = + if (kind == BaseItemKind.EPISODE) { + HomeRowViewOptions( + heightDp = Cards.HEIGHT_EPISODE, + aspectRatio = AspectRatio.WIDE, + ) + } else { + HomeRowViewOptions() + }, + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): Favorite = this.copy(viewOptions = viewOptions) + } + /** * Fetch by parent ID such as a library, collection, or playlist with optional simple sorting */ diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index 94766fb884..25ad869398 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -15,7 +15,9 @@ import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem import com.github.damontecres.wholphin.ui.toServerString import com.github.damontecres.wholphin.util.GetGenresRequestHandler import com.github.damontecres.wholphin.util.GetItemsRequestHandler +import com.github.damontecres.wholphin.util.GetPersonsHandler import com.github.damontecres.wholphin.util.HomeRowLoadingState +import com.github.damontecres.wholphin.util.HomeRowLoadingState.Success import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow @@ -31,12 +33,15 @@ import org.jellyfin.sdk.api.client.ApiClient import org.jellyfin.sdk.api.client.extensions.displayPreferencesApi import org.jellyfin.sdk.api.client.extensions.userLibraryApi import org.jellyfin.sdk.model.UUID +import org.jellyfin.sdk.model.api.BaseItemKind +import org.jellyfin.sdk.model.api.ImageType import org.jellyfin.sdk.model.api.ItemSortBy import org.jellyfin.sdk.model.api.SortOrder import org.jellyfin.sdk.model.api.UserDto import org.jellyfin.sdk.model.api.request.GetGenresRequest import org.jellyfin.sdk.model.api.request.GetItemsRequest import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest +import org.jellyfin.sdk.model.api.request.GetPersonsRequest import timber.log.Timber import java.io.File import javax.inject.Inject @@ -183,7 +188,19 @@ class HomeSettingsService suspend fun loadCurrentSettings(userId: UUID) { Timber.v("Getting setting for %s", userId) // User local then server/remote otherwise create a default - val settings = loadFromLocal(userId) ?: loadFromServer(userId) + val settings = + try { + loadFromLocal(userId) + } catch (ex: Exception) { + Timber.w(ex, "Error loading local settings") + // TODO show toast? + null + } ?: try { + loadFromServer(userId) + } catch (ex: Exception) { + Timber.w(ex, "Error loading remote settings") + null + } val resolvedSettings = if (settings != null) { Timber.v("Found settings") @@ -341,6 +358,11 @@ class HomeSettingsService config, ) } + + is HomeRowConfig.Favorite -> { + val name = context.getString(R.string.favorites) // TODO "Favorite " + HomeRowConfigDisplay(id, name, config) + } } /** @@ -358,7 +380,7 @@ class HomeSettingsService is HomeRowConfig.ContinueWatching -> { val resume = latestNextUpService.getResume(userDto.id, limit, true) - HomeRowLoadingState.Success( + Success( title = context.getString(R.string.continue_watching), items = resume, viewOptions = row.viewOptions, @@ -374,7 +396,7 @@ class HomeSettingsService false, ) - HomeRowLoadingState.Success( + Success( title = context.getString(R.string.next_up), items = nextUp, viewOptions = row.viewOptions, @@ -392,7 +414,7 @@ class HomeSettingsService false, ) - HomeRowLoadingState.Success( + Success( title = context.getString(R.string.continue_watching), items = latestNextUpService.buildCombined( @@ -438,7 +460,7 @@ class HomeSettingsService name?.let { context.getString(R.string.genres_in, it) } ?: context.getString(R.string.genres) - HomeRowLoadingState.Success( + Success( title, genres, viewOptions = row.viewOptions, @@ -468,7 +490,7 @@ class HomeSettingsService .content .map { BaseItem.Companion.from(it, api, true) } .let { - HomeRowLoadingState.Success( + Success( title, it, row.viewOptions, @@ -500,7 +522,7 @@ class HomeSettingsService .content.items .map { BaseItem.Companion.from(it, api, true) } .let { - HomeRowLoadingState.Success( + Success( title, it, row.viewOptions, @@ -528,7 +550,7 @@ class HomeSettingsService .content.items .map { BaseItem(it, true) } .let { - HomeRowLoadingState.Success( + Success( name ?: context.getString(R.string.collection), it, row.viewOptions, @@ -555,13 +577,59 @@ class HomeSettingsService .content.items .map { BaseItem(it, true) } .let { - HomeRowLoadingState.Success( + Success( row.name, it, row.viewOptions, ) } } + + is HomeRowConfig.Favorite -> { + if (row.kind == BaseItemKind.PERSON) { + val request = + GetPersonsRequest( + userId = userDto.id, + limit = limit, + fields = DefaultItemFields, + isFavorite = true, + enableImages = true, + enableImageTypes = listOf(ImageType.PRIMARY), + ) + GetPersonsHandler + .execute(api, request) + .content.items + .map { BaseItem(it, true) } + .let { + Success( + context.getString(R.string.favorites), // TODO + it, + row.viewOptions, + ) + } + } else { + val request = + GetItemsRequest( + userId = userDto.id, + recursive = true, + limit = limit, + fields = DefaultItemFields, + includeItemTypes = listOf(row.kind), + isFavorite = true, + ) + GetItemsRequestHandler + .execute(api, request) + .content.items + .map { BaseItem(it, false) } + .let { + Success( + context.getString(R.string.favorites), // TODO + it, + row.viewOptions, + ) + } + } + } } companion object { diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/UiConstants.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/UiConstants.kt index 0ea92dcd5f..ce1a735213 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/UiConstants.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/UiConstants.kt @@ -75,7 +75,8 @@ val SlimItemFields = object Cards { const val HEIGHT_2X3_DP = 172 val height2x3 = HEIGHT_2X3_DP.dp - val heightEpisode = height2x3 * .75f + val HEIGHT_EPISODE = (HEIGHT_2X3_DP * .75f).toInt().let { it - it % 4 } + val heightEpisode = HEIGHT_EPISODE.dp val playedPercentHeight = 6.dp val serverUserCircle = height2x3 * .75f } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt index c08fe1f676..e3f4cb62e0 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt @@ -17,4 +17,8 @@ sealed interface HomeSettingsDestination : NavKey { data class RowSettings( val rowId: Int, ) : HomeSettingsDestination + + data object ChooseFavorite : HomeSettingsDestination + + data object ChooseDiscover : HomeSettingsDestination } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt new file mode 100644 index 0000000000..6a0cfcceee --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt @@ -0,0 +1,69 @@ +package com.github.damontecres.wholphin.ui.main.settings + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.itemsIndexed +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +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 +import com.github.damontecres.wholphin.ui.tryRequestFocus +import org.jellyfin.sdk.model.api.BaseItemKind + +@Composable +fun HomeSettingsFavoriteList( + onClick: (BaseItemKind) -> Unit, + modifier: Modifier = Modifier, + firstFocus: FocusRequester = remember { FocusRequester() }, +) { + LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } + Column(modifier = modifier) { + Text( + text = "Add favorites row...", + ) + LazyColumn( + contentPadding = PaddingValues(8.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + modifier = + modifier + .fillMaxHeight() + .focusRestorer(firstFocus), + ) { + itemsIndexed(favoriteOptionsList) { index, type -> + ListItem( + selected = false, + headlineContent = { + Text( + text = stringResource(favoriteOptions[type]!!), + ) + }, + onClick = { onClick.invoke(type) }, + modifier = Modifier.ifElse(index == 0, Modifier.focusRequester(firstFocus)), + ) + } + } + } +} + +val favoriteOptions = + mapOf( + BaseItemKind.MOVIE to R.string.movies, + BaseItemKind.SERIES to R.string.tv_shows, + BaseItemKind.EPISODE to R.string.episodes, + BaseItemKind.VIDEO to R.string.videos, + BaseItemKind.PLAYLIST to R.string.playlists, + BaseItemKind.PERSON to R.string.people, + ) +val favoriteOptionsList = favoriteOptions.keys.toList() diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsLibraryList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsLibraryList.kt index 998b634dca..e8dd5c6c8e 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsLibraryList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsLibraryList.kt @@ -5,6 +5,8 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.material3.HorizontalDivider @@ -16,8 +18,10 @@ import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester 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 import com.github.damontecres.wholphin.ui.ifElse @@ -26,6 +30,7 @@ import com.github.damontecres.wholphin.ui.tryRequestFocus @Composable fun HomeSettingsLibraryList( libraries: List, + showDiscover: Boolean, onClick: (Library) -> Unit, onClickMeta: (MetaRowType) -> Unit, modifier: Modifier, @@ -44,7 +49,25 @@ fun HomeSettingsLibraryList( .fillMaxHeight() .focusRestorer(firstFocus), ) { - itemsIndexed(MetaRowType.entries) { index, type -> + item { + Text( + text = stringResource(R.string.continue_watching), + style = MaterialTheme.typography.titleMedium, + color = MaterialTheme.colorScheme.onSurface, + textAlign = TextAlign.Start, + modifier = + Modifier + .fillMaxWidth() + .padding(top = 8.dp, bottom = 4.dp), + ) + } + itemsIndexed( + listOf( + MetaRowType.CONTINUE_WATCHING, + MetaRowType.NEXT_UP, + MetaRowType.COMBINED_CONTINUE_WATCHING, + ), + ) { index, type -> ListItem( selected = false, headlineContent = { @@ -56,6 +79,16 @@ fun HomeSettingsLibraryList( } item { HorizontalDivider() + Text( + text = stringResource(R.string.library), + style = MaterialTheme.typography.titleMedium, + color = MaterialTheme.colorScheme.onSurface, + textAlign = TextAlign.Start, + modifier = + Modifier + .fillMaxWidth() + .padding(top = 8.dp, bottom = 4.dp), + ) } itemsIndexed(libraries) { index, library -> ListItem( @@ -67,6 +100,41 @@ fun HomeSettingsLibraryList( modifier = Modifier, // .ifElse(index == 0, Modifier.focusRequester(firstFocus)), ) } + item { + HorizontalDivider() + Text( + text = stringResource(R.string.more), + style = MaterialTheme.typography.titleMedium, + color = MaterialTheme.colorScheme.onSurface, + textAlign = TextAlign.Start, + modifier = + Modifier + .fillMaxWidth() + .padding(top = 8.dp, bottom = 4.dp), + ) + } + item { + ListItem( + selected = false, + headlineContent = { + Text(stringResource(MetaRowType.FAVORITES.stringId)) + }, + onClick = { onClickMeta.invoke(MetaRowType.FAVORITES) }, + modifier = Modifier, + ) + } + if (showDiscover) { + item { + ListItem( + selected = false, + headlineContent = { + Text(stringResource(MetaRowType.DISCOVER.stringId)) + }, + onClick = { onClickMeta.invoke(MetaRowType.DISCOVER) }, + modifier = Modifier, + ) + } + } } } } @@ -77,4 +145,6 @@ enum class MetaRowType( CONTINUE_WATCHING(R.string.continue_watching), NEXT_UP(R.string.next_up), COMBINED_CONTINUE_WATCHING(R.string.combine_continue_next), + FAVORITES(R.string.favorites), + DISCOVER(R.string.discover), } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index 289d1e85a7..ae605e9ade 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -22,6 +22,8 @@ import androidx.compose.ui.unit.dp import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel import androidx.tv.material3.MaterialTheme 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.launch import timber.log.Timber @@ -38,14 +40,15 @@ fun HomeSettingsPage( var destination by remember { mutableStateOf(HomeSettingsDestination.RowList) } val state by viewModel.state.collectAsState() + val discoverEnabled by viewModel.discoverEnabled.collectAsState(false) - BackHandler(destination is HomeSettingsDestination.ChooseRowType) { + BackHandler(destination is ChooseRowType) { destination = HomeSettingsDestination.ChooseLibrary } BackHandler(destination is HomeSettingsDestination.ChooseLibrary) { destination = HomeSettingsDestination.RowList } - BackHandler(destination is HomeSettingsDestination.RowSettings) { + BackHandler(destination is RowSettings) { destination = HomeSettingsDestination.RowList } Row( @@ -72,7 +75,7 @@ fun HomeSettingsPage( onClickMove = viewModel::moveRow, onClickDelete = viewModel::deleteRow, onClick = { index, row -> - destination = HomeSettingsDestination.RowSettings(row.id) + destination = RowSettings(row.id) scope.launch(ExceptionHandler()) { Timber.v("Scroll to $index") listState.scrollToItem(index) @@ -88,16 +91,32 @@ fun HomeSettingsPage( is HomeSettingsDestination.ChooseLibrary -> { HomeSettingsLibraryList( libraries = state.libraries, - onClick = { destination = HomeSettingsDestination.ChooseRowType(it) }, + showDiscover = discoverEnabled, + onClick = { destination = ChooseRowType(it) }, onClickMeta = { - viewModel.addRow(it) - destination = HomeSettingsDestination.RowList + when (it) { + MetaRowType.CONTINUE_WATCHING, + MetaRowType.NEXT_UP, + MetaRowType.COMBINED_CONTINUE_WATCHING, + -> { + viewModel.addRow(it) + destination = HomeSettingsDestination.RowList + } + + MetaRowType.FAVORITES -> { + destination = HomeSettingsDestination.ChooseFavorite + } + + MetaRowType.DISCOVER -> { + destination = HomeSettingsDestination.ChooseDiscover + } + } }, modifier = destModifier, ) } - is HomeSettingsDestination.ChooseRowType -> { + is ChooseRowType -> { HomeLibraryRowTypeList( library = dest.library, onClick = { @@ -108,7 +127,7 @@ fun HomeSettingsPage( ) } - is HomeSettingsDestination.RowSettings -> { + is RowSettings -> { val row = state.rows .first { it.id == dest.rowId } @@ -124,6 +143,18 @@ fun HomeSettingsPage( modifier = destModifier, ) } + + HomeSettingsDestination.ChooseDiscover -> { + TODO() + } + + HomeSettingsDestination.ChooseFavorite -> { + HomeSettingsFavoriteList( + onClick = { type -> + viewModel.addFavoriteRow(type) + }, + ) + } } } HomePageContent( diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt index c6761776c7..ff6ff4f7ea 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt @@ -23,9 +23,11 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusDirection import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.focusRestorer +import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp @@ -57,6 +59,7 @@ fun HomeSettingsRowList( modifier: Modifier, firstFocus: FocusRequester = remember { FocusRequester() }, ) { + val focusManager = LocalFocusManager.current LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } Column(modifier = modifier) { LazyColumn( @@ -148,7 +151,14 @@ fun HomeSettingsRowList( moveDownAllowed = index != state.rows.lastIndex, deleteAllowed = state.rows.size > 1, onClickMove = { onClickMove.invoke(it, index) }, - onClickDelete = { onClickDelete.invoke(index) }, + onClickDelete = { + if (index != state.rows.lastIndex) { + focusManager.moveFocus(FocusDirection.Down) + } else { + focusManager.moveFocus(FocusDirection.Up) + } + onClickDelete.invoke(index) + }, onClick = { onClick.invoke(index, row) }, modifier = Modifier diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index a5c1293d49..1e89437ab1 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -11,11 +11,15 @@ import com.github.damontecres.wholphin.data.ServerRepository import com.github.damontecres.wholphin.data.model.BaseItem import com.github.damontecres.wholphin.data.model.HomePageSettings import com.github.damontecres.wholphin.data.model.HomeRowConfig +import com.github.damontecres.wholphin.data.model.HomeRowConfig.ContinueWatching +import com.github.damontecres.wholphin.data.model.HomeRowConfig.ContinueWatchingCombined +import com.github.damontecres.wholphin.data.model.HomeRowConfig.NextUp import com.github.damontecres.wholphin.data.model.HomeRowViewOptions import com.github.damontecres.wholphin.services.BackdropService import com.github.damontecres.wholphin.services.HomePageResolvedSettings import com.github.damontecres.wholphin.services.HomeRowConfigDisplay import com.github.damontecres.wholphin.services.HomeSettingsService +import com.github.damontecres.wholphin.services.SeerrServerRepository import com.github.damontecres.wholphin.services.UserPreferencesService import com.github.damontecres.wholphin.services.hilt.IoCoroutineScope import com.github.damontecres.wholphin.ui.launchIO @@ -30,6 +34,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.update +import org.jellyfin.sdk.model.api.BaseItemKind import org.jellyfin.sdk.model.api.CollectionType import timber.log.Timber import java.util.UUID @@ -45,11 +50,14 @@ class HomeSettingsViewModel private val userPreferencesService: UserPreferencesService, private val navDrawerItemRepository: NavDrawerItemRepository, private val backdropService: BackdropService, + private val seerrServerRepository: SeerrServerRepository, @param:IoCoroutineScope private val ioScope: CoroutineScope, ) : ViewModel() { private val _state = MutableStateFlow(HomePageSettingsState.EMPTY) val state: StateFlow = _state + val discoverEnabled = seerrServerRepository.active + init { addCloseable { saveToLocal() } viewModelScope.launchIO { @@ -164,7 +172,7 @@ class HomeSettingsViewModel HomeRowConfigDisplay( id = id, title = context.getString(R.string.continue_watching), - config = HomeRowConfig.ContinueWatching(), + config = ContinueWatching(), ) } @@ -172,7 +180,7 @@ class HomeSettingsViewModel HomeRowConfigDisplay( id = id, title = context.getString(R.string.continue_watching), - config = HomeRowConfig.NextUp(), + config = NextUp(), ) } @@ -180,9 +188,17 @@ class HomeSettingsViewModel HomeRowConfigDisplay( id = id, title = context.getString(R.string.combine_continue_next), - config = HomeRowConfig.ContinueWatchingCombined(), + config = ContinueWatchingCombined(), ) } + + MetaRowType.FAVORITES -> { + throw IllegalArgumentException("Should use addRow(BaseItemKind) instead") + } + + MetaRowType.DISCOVER -> { + TODO() + } } updateState { it.copy( @@ -246,6 +262,26 @@ class HomeSettingsViewModel } } + fun addFavoriteRow(type: BaseItemKind) { + viewModelScope.launchIO { + Timber.v("Adding favorite row for $type") + val id = state.value.rows.size + val newRow = + HomeRowConfigDisplay( + id = id, + title = context.getString(favoriteOptions[type]!!), + config = HomeRowConfig.Favorite(type), + ) + updateState { + it.copy( + loading = LoadingState.Loading, + rows = it.rows.toMutableList().apply { add(newRow) }, + ) + } + fetchRowData() + } + } + fun updateViewOptions( rowId: Int, viewOptions: HomeRowViewOptions, From 9cd3e7df4e065cbf0aca6c568345f2a440957e72 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Wed, 28 Jan 2026 10:30:11 -0500 Subject: [PATCH 26/53] WIP live tv home rows --- .../wholphin/data/model/HomeRowConfig.kt | 22 +++ .../wholphin/services/HomeSettingsService.kt | 175 ++++++++++++++++-- .../damontecres/wholphin/util/Constants.kt | 8 + 3 files changed, 193 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index ef0d77d41b..36c2838807 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -114,6 +114,28 @@ sealed interface HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): Favorite = this.copy(viewOptions = viewOptions) } + /** + * + */ + @Serializable + @SerialName("Recordings") + data class Recordings( + override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): Recordings = this.copy(viewOptions = viewOptions) + } + + /** + * + */ + @Serializable + @SerialName("TvPrograms") + data class TvPrograms( + override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): TvPrograms = this.copy(viewOptions = viewOptions) + } + /** * Fetch by parent ID such as a library, collection, or playlist with optional simple sorting */ diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index 25ad869398..955a173da1 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -6,6 +6,7 @@ import com.github.damontecres.wholphin.data.NavDrawerItemRepository import com.github.damontecres.wholphin.data.model.BaseItem import com.github.damontecres.wholphin.data.model.HomePageSettings import com.github.damontecres.wholphin.data.model.HomeRowConfig +import com.github.damontecres.wholphin.preferences.DefaultUserConfiguration import com.github.damontecres.wholphin.preferences.HomePagePreferences import com.github.damontecres.wholphin.ui.DefaultItemFields import com.github.damontecres.wholphin.ui.SlimItemFields @@ -18,6 +19,7 @@ import com.github.damontecres.wholphin.util.GetItemsRequestHandler import com.github.damontecres.wholphin.util.GetPersonsHandler import com.github.damontecres.wholphin.util.HomeRowLoadingState import com.github.damontecres.wholphin.util.HomeRowLoadingState.Success +import com.github.damontecres.wholphin.util.supportedHomeCollectionTypes import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow @@ -31,7 +33,9 @@ import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject import org.jellyfin.sdk.api.client.ApiClient import org.jellyfin.sdk.api.client.extensions.displayPreferencesApi +import org.jellyfin.sdk.api.client.extensions.userApi import org.jellyfin.sdk.api.client.extensions.userLibraryApi +import org.jellyfin.sdk.api.client.extensions.userViewsApi import org.jellyfin.sdk.model.UUID import org.jellyfin.sdk.model.api.BaseItemKind import org.jellyfin.sdk.model.api.ImageType @@ -42,6 +46,7 @@ import org.jellyfin.sdk.model.api.request.GetGenresRequest import org.jellyfin.sdk.model.api.request.GetItemsRequest import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest import org.jellyfin.sdk.model.api.request.GetPersonsRequest +import org.jellyfin.sdk.model.api.request.GetRecordingsRequest import timber.log.Timber import java.io.File import javax.inject.Inject @@ -58,10 +63,12 @@ class HomeSettingsService private val latestNextUpService: LatestNextUpService, private val imageUrlService: ImageUrlService, ) { + @OptIn(ExperimentalSerializationApi::class) val jsonParser = Json { isLenient = true ignoreUnknownKeys = true + allowTrailingComma = true } val currentSettings = MutableStateFlow(HomePageResolvedSettings.EMPTY) @@ -201,18 +208,18 @@ class HomeSettingsService Timber.w(ex, "Error loading remote settings") null } - val resolvedSettings = - if (settings != null) { - Timber.v("Found settings") - // Resolve - val resolvedRows = - settings.rows.mapIndexed { index, config -> - resolve(index, config) - } - HomePageResolvedSettings(resolvedRows) - } else { - createDefault(userId) - } + val resolvedSettings = parseFromWebConfig(userId)!! + if (settings != null) { + Timber.v("Found settings") + // Resolve + val resolvedRows = + settings.rows.mapIndexed { index, config -> + resolve(index, config) + } + HomePageResolvedSettings(resolvedRows) + } else { + createDefault(userId) + } currentSettings.update { resolvedSettings } } @@ -275,6 +282,112 @@ class HomeSettingsService return HomePageResolvedSettings(rowConfig) } + suspend fun parseFromWebConfig(userId: UUID): HomePageResolvedSettings? { + val customPrefs = + api.displayPreferencesApi + .getDisplayPreferences( + displayPreferencesId = "usersettings", + userId = userId, + client = "emby", + ).content.customPrefs + val userDto by api.userApi.getUserById(userId) + val config = userDto.configuration ?: DefaultUserConfiguration + val libraries = + api.userViewsApi + .getUserViews(userId = userId) + .content.items + .filter { + it.collectionType in supportedHomeCollectionTypes && + it.id !in config.latestItemsExcludes + } + + return if (customPrefs.isNotEmpty()) { + var id = 0 + val rowConfigs = + (0..9) + .mapNotNull { idx -> + val sectionType = + HomeSectionType.fromString(customPrefs["homesection$idx"]?.lowercase()) + Timber.v( + "sectionType=$sectionType, %s", + customPrefs["homesection$idx"]?.lowercase(), + ) + val config = + when (sectionType) { + HomeSectionType.ACTIVE_RECORDINGS -> { + // GetRecordingsRequest + TODO() + } + + HomeSectionType.RESUME -> { + HomeRowConfigDisplay( + id = id++, + title = context.getString(R.string.continue_watching), + config = HomeRowConfig.ContinueWatching(), + ) + } + + HomeSectionType.NEXT_UP -> { + HomeRowConfigDisplay( + id = id++, + title = context.getString(R.string.next_up), + config = HomeRowConfig.NextUp(), + ) + } + + HomeSectionType.LIVE_TV -> { + if (userDto.policy?.enableLiveTvAccess == true) { + // GetRecommendedProgramsRequest + TODO() + } else { + null + } + } + + HomeSectionType.LATEST_MEDIA -> { + // Handled below + null + } + + // Unsupported + HomeSectionType.RESUME_AUDIO, + HomeSectionType.RESUME_BOOK, + -> { + null + } + + HomeSectionType.SMALL_LIBRARY_TILES, + HomeSectionType.LIBRARY_BUTTONS, + HomeSectionType.NONE, + null, + -> { + null + } + } + if (sectionType == HomeSectionType.LATEST_MEDIA) { + libraries.map { + HomeRowConfigDisplay( + id = id++, + title = + context.getString( + R.string.recently_added_in, + it.name ?: "", + ), + config = HomeRowConfig.RecentlyAdded(it.id), + ) + } + } else if (config != null) { + listOf(config) + } else { + null + } + }.flatten() + HomePageResolvedSettings(rowConfigs) + } else { + null + } + } + /** * Converts a [HomeRowConfig] into [HomeRowConfigDisplay] for UI purposes */ @@ -363,6 +476,14 @@ class HomeSettingsService val name = context.getString(R.string.favorites) // TODO "Favorite " HomeRowConfigDisplay(id, name, config) } + + is HomeRowConfig.Recordings -> { + TODO() + } + + is HomeRowConfig.TvPrograms -> { + TODO() + } } /** @@ -630,6 +751,15 @@ class HomeSettingsService } } } + + is HomeRowConfig.Recordings -> { + GetRecordingsRequest() + TODO() + } + + is HomeRowConfig.TvPrograms -> { + TODO() + } } companion object { @@ -659,3 +789,24 @@ data class HomePageResolvedSettings( val EMPTY = HomePageResolvedSettings(listOf()) } } + +// https://github.com/jellyfin/jellyfin/blob/v10.11.6/src/Jellyfin.Database/Jellyfin.Database.Implementations/Enums/HomeSectionType.cs +enum class HomeSectionType( + val serialName: String, +) { + NONE("none"), + SMALL_LIBRARY_TILES("smalllibrarytitles"), + LIBRARY_BUTTONS("librarybuttons"), + ACTIVE_RECORDINGS("activerecordings"), + RESUME("resume"), + RESUME_AUDIO("resumeaudio"), + LATEST_MEDIA("latestmedia"), + NEXT_UP("nextup"), + LIVE_TV("livetv"), + RESUME_BOOK("resumebook"), + ; + + companion object { + fun fromString(homeKey: String?) = homeKey?.let { entries.firstOrNull { it.serialName == homeKey } } + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/util/Constants.kt b/app/src/main/java/com/github/damontecres/wholphin/util/Constants.kt index c0e9355647..da246f73c4 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/util/Constants.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/util/Constants.kt @@ -34,6 +34,14 @@ val supportedCollectionTypes = null, // Mixed ) +val supportedHomeCollectionTypes = + setOf( + CollectionType.MOVIES, + CollectionType.TVSHOWS, + CollectionType.HOMEVIDEOS, + null, // Mixed + ) + val supportedPlayableTypes = setOf( BaseItemKind.MOVIE, From 75183802e78a6b6b7d1aef8d55dcb496cb79a929 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 29 Jan 2026 14:57:50 -0500 Subject: [PATCH 27/53] Use navigation --- .../wholphin/services/HomeSettingsService.kt | 70 +++++- ...gsLibraryList.kt => HomeSettingsAddRow.kt} | 2 +- .../main/settings/HomeSettingsDestination.kt | 10 +- .../ui/main/settings/HomeSettingsPage.kt | 206 +++++++++--------- .../ui/main/settings/HomeSettingsViewModel.kt | 5 +- 5 files changed, 182 insertions(+), 111 deletions(-) rename app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/{HomeSettingsLibraryList.kt => HomeSettingsAddRow.kt} (99%) diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index 955a173da1..b6a784b001 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -33,6 +33,7 @@ import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject import org.jellyfin.sdk.api.client.ApiClient import org.jellyfin.sdk.api.client.extensions.displayPreferencesApi +import org.jellyfin.sdk.api.client.extensions.liveTvApi import org.jellyfin.sdk.api.client.extensions.userApi import org.jellyfin.sdk.api.client.extensions.userLibraryApi import org.jellyfin.sdk.api.client.extensions.userViewsApi @@ -46,6 +47,7 @@ import org.jellyfin.sdk.model.api.request.GetGenresRequest import org.jellyfin.sdk.model.api.request.GetItemsRequest import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest import org.jellyfin.sdk.model.api.request.GetPersonsRequest +import org.jellyfin.sdk.model.api.request.GetRecommendedProgramsRequest import org.jellyfin.sdk.model.api.request.GetRecordingsRequest import timber.log.Timber import java.io.File @@ -315,8 +317,11 @@ class HomeSettingsService val config = when (sectionType) { HomeSectionType.ACTIVE_RECORDINGS -> { - // GetRecordingsRequest - TODO() + HomeRowConfigDisplay( + id = id++, + title = context.getString(R.string.active_recordings), + config = HomeRowConfig.Recordings(), + ) } HomeSectionType.RESUME -> { @@ -337,8 +342,11 @@ class HomeSettingsService HomeSectionType.LIVE_TV -> { if (userDto.policy?.enableLiveTvAccess == true) { - // GetRecommendedProgramsRequest - TODO() + HomeRowConfigDisplay( + id = id++, + title = context.getString(R.string.live_tv), + config = HomeRowConfig.TvPrograms(), + ) } else { null } @@ -478,11 +486,19 @@ class HomeSettingsService } is HomeRowConfig.Recordings -> { - TODO() + HomeRowConfigDisplay( + id = id, + title = context.getString(R.string.active_recordings), + config, + ) } is HomeRowConfig.TvPrograms -> { - TODO() + HomeRowConfigDisplay( + id = id, + title = context.getString(R.string.live_tv), + config, + ) } } @@ -753,12 +769,48 @@ class HomeSettingsService } is HomeRowConfig.Recordings -> { - GetRecordingsRequest() - TODO() + val request = + GetRecordingsRequest( + userId = userDto.id, + isInProgress = true, + fields = DefaultItemFields, + limit = limit, + enableImages = true, + enableUserData = true, + ) + api.liveTvApi + .getRecordings(request) + .content.items + .map { BaseItem(it, true) } + .let { + Success( + context.getString(R.string.active_recordings), + it, + row.viewOptions, + ) + } } is HomeRowConfig.TvPrograms -> { - TODO() + val request = + GetRecommendedProgramsRequest( + userId = userDto.id, + fields = DefaultItemFields, + limit = limit, + enableImages = true, + enableUserData = true, + ) + api.liveTvApi + .getRecommendedPrograms(request) + .content.items + .map { BaseItem(it, true) } + .let { + Success( + context.getString(R.string.live_tv), + it, + row.viewOptions, + ) + } } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsLibraryList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt similarity index 99% rename from app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsLibraryList.kt rename to app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt index e8dd5c6c8e..7fa15ceb40 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsLibraryList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt @@ -28,7 +28,7 @@ import com.github.damontecres.wholphin.ui.ifElse import com.github.damontecres.wholphin.ui.tryRequestFocus @Composable -fun HomeSettingsLibraryList( +fun HomeSettingsAddRow( libraries: List, showDiscover: Boolean, onClick: (Library) -> Unit, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt index e3f4cb62e0..7aa65db997 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt @@ -1,24 +1,32 @@ package com.github.damontecres.wholphin.ui.main.settings import androidx.navigation3.runtime.NavKey +import kotlinx.serialization.Serializable /** * Tracking the pages for selecting and configuring rows */ +@Serializable sealed interface HomeSettingsDestination : NavKey { + @Serializable data object RowList : HomeSettingsDestination - data object ChooseLibrary : HomeSettingsDestination + @Serializable + data object AddRow : HomeSettingsDestination + @Serializable data class ChooseRowType( val library: Library, ) : HomeSettingsDestination + @Serializable data class RowSettings( val rowId: Int, ) : HomeSettingsDestination + @Serializable data object ChooseFavorite : HomeSettingsDestination + @Serializable data object ChooseDiscover : HomeSettingsDestination } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index ae605e9ade..3c3bdf9baf 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -1,6 +1,5 @@ package com.github.damontecres.wholphin.ui.main.settings -import androidx.activity.compose.BackHandler import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -13,14 +12,17 @@ import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel +import androidx.lifecycle.viewmodel.navigation3.rememberViewModelStoreNavEntryDecorator +import androidx.navigation3.runtime.NavEntry +import androidx.navigation3.runtime.rememberNavBackStack +import androidx.navigation3.runtime.rememberSaveableStateHolderNavEntryDecorator +import androidx.navigation3.ui.NavDisplay import androidx.tv.material3.MaterialTheme +import androidx.tv.material3.surfaceColorAtElevation 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 @@ -37,20 +39,11 @@ fun HomeSettingsPage( ) { val scope = rememberCoroutineScope() val listState = rememberLazyListState() - var destination by remember { mutableStateOf(HomeSettingsDestination.RowList) } + val backStack = rememberNavBackStack(HomeSettingsDestination.RowList) val state by viewModel.state.collectAsState() val discoverEnabled by viewModel.discoverEnabled.collectAsState(false) - BackHandler(destination is ChooseRowType) { - destination = HomeSettingsDestination.ChooseLibrary - } - BackHandler(destination is HomeSettingsDestination.ChooseLibrary) { - destination = HomeSettingsDestination.RowList - } - BackHandler(destination is RowSettings) { - destination = HomeSettingsDestination.RowList - } Row( horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = modifier, @@ -62,100 +55,115 @@ fun HomeSettingsPage( .fillMaxHeight() .background(color = MaterialTheme.colorScheme.surface), ) { - val destModifier = - Modifier - .fillMaxSize() - .padding(4.dp) - when (val dest = destination) { - HomeSettingsDestination.RowList -> { - HomeSettingsRowList( - state = state, - onClickAdd = { destination = HomeSettingsDestination.ChooseLibrary }, - onClickSaveLocal = { viewModel.saveToLocal() }, - onClickMove = viewModel::moveRow, - onClickDelete = viewModel::deleteRow, - onClick = { index, row -> - destination = RowSettings(row.id) - scope.launch(ExceptionHandler()) { - Timber.v("Scroll to $index") - listState.scrollToItem(index) + NavDisplay( + backStack = backStack, +// onBack = { navigationManager.goBack() }, + entryDecorators = + listOf( + rememberSaveableStateHolderNavEntryDecorator(), + rememberViewModelStoreNavEntryDecorator(), + ), + modifier = Modifier.background(MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp)), + entryProvider = { key -> + key as HomeSettingsDestination + NavEntry(key, contentKey = key.toString()) { + val destModifier = + Modifier + .fillMaxSize() + .padding(4.dp) + when (val dest = key) { + HomeSettingsDestination.RowList -> { + HomeSettingsRowList( + state = state, + onClickAdd = { backStack.add(HomeSettingsDestination.AddRow) }, + onClickSaveLocal = { viewModel.saveToLocal() }, + onClickMove = viewModel::moveRow, + onClickDelete = viewModel::deleteRow, + onClick = { index, row -> + backStack.add(RowSettings(row.id)) + scope.launch(ExceptionHandler()) { + Timber.v("Scroll to $index") + listState.scrollToItem(index) + } + }, + onClickResize = { + viewModel.resizeCards(it) + }, + modifier = destModifier, + ) } - }, - onClickResize = { - viewModel.resizeCards(it) - }, - modifier = destModifier, - ) - } - is HomeSettingsDestination.ChooseLibrary -> { - HomeSettingsLibraryList( - libraries = state.libraries, - showDiscover = discoverEnabled, - onClick = { destination = ChooseRowType(it) }, - onClickMeta = { - when (it) { - MetaRowType.CONTINUE_WATCHING, - MetaRowType.NEXT_UP, - MetaRowType.COMBINED_CONTINUE_WATCHING, - -> { - viewModel.addRow(it) - destination = HomeSettingsDestination.RowList - } + is HomeSettingsDestination.AddRow -> { + HomeSettingsAddRow( + libraries = state.libraries, + showDiscover = discoverEnabled, + onClick = { backStack.add(ChooseRowType(it)) }, + onClickMeta = { + when (it) { + MetaRowType.CONTINUE_WATCHING, + MetaRowType.NEXT_UP, + MetaRowType.COMBINED_CONTINUE_WATCHING, + -> { + viewModel.addRow(it) + backStack.add(HomeSettingsDestination.RowList) + } - MetaRowType.FAVORITES -> { - destination = HomeSettingsDestination.ChooseFavorite - } + MetaRowType.FAVORITES -> { + backStack.add(HomeSettingsDestination.ChooseFavorite) + } - MetaRowType.DISCOVER -> { - destination = HomeSettingsDestination.ChooseDiscover - } + MetaRowType.DISCOVER -> { + backStack.add(HomeSettingsDestination.ChooseDiscover) + } + } + }, + modifier = destModifier, + ) } - }, - modifier = destModifier, - ) - } - is ChooseRowType -> { - HomeLibraryRowTypeList( - library = dest.library, - onClick = { - viewModel.addRow(dest.library, it) - destination = HomeSettingsDestination.RowList - }, - modifier = destModifier, - ) - } + is ChooseRowType -> { + HomeLibraryRowTypeList( + library = dest.library, + onClick = { + viewModel.addRow(dest.library, it) + backStack.add(HomeSettingsDestination.RowList) + }, + modifier = destModifier, + ) + } - is RowSettings -> { - val row = - state.rows - .first { it.id == dest.rowId } - HomeRowSettings( - title = row.title, - viewOptions = row.config.viewOptions, - onViewOptionsChange = { - viewModel.updateViewOptions(dest.rowId, it) - }, - onApplyApplyAll = { - viewModel.updateViewOptionsForAll(row.config.viewOptions) - }, - modifier = destModifier, - ) - } + is RowSettings -> { + val row = + state.rows + .first { it.id == dest.rowId } + HomeRowSettings( + title = row.title, + viewOptions = row.config.viewOptions, + onViewOptionsChange = { + viewModel.updateViewOptions(dest.rowId, it) + }, + onApplyApplyAll = { + viewModel.updateViewOptionsForAll(row.config.viewOptions) + }, + modifier = destModifier, + ) + } - HomeSettingsDestination.ChooseDiscover -> { - TODO() - } + HomeSettingsDestination.ChooseDiscover -> { + TODO() + } - HomeSettingsDestination.ChooseFavorite -> { - HomeSettingsFavoriteList( - onClick = { type -> - viewModel.addFavoriteRow(type) - }, - ) - } - } + HomeSettingsDestination.ChooseFavorite -> { + HomeSettingsFavoriteList( + onClick = { type -> + viewModel.addFavoriteRow(type) + }, + ) + } + } + } + }, + ) } HomePageContent( loadingState = state.loading, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 1e89437ab1..348cbf7b47 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -34,8 +34,10 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.update +import kotlinx.serialization.Serializable import org.jellyfin.sdk.model.api.BaseItemKind import org.jellyfin.sdk.model.api.CollectionType +import org.jellyfin.sdk.model.serializer.UUIDSerializer import timber.log.Timber import java.util.UUID import javax.inject.Inject @@ -400,8 +402,9 @@ data class HomePageSettingsState( } @Immutable +@Serializable data class Library( - val itemId: UUID, + @Serializable(UUIDSerializer::class) val itemId: UUID, val name: String, val collectionType: CollectionType, ) From e11b9ecc72452c8020cd5d877460c81cb5959fb0 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 29 Jan 2026 15:19:33 -0500 Subject: [PATCH 28/53] Scroll to new rows --- .../ui/main/settings/HomeSettingsAddRow.kt | 9 ++++---- .../main/settings/HomeSettingsFavoriteList.kt | 3 +-- .../ui/main/settings/HomeSettingsPage.kt | 20 ++++++++++++------ .../ui/main/settings/HomeSettingsRowList.kt | 21 ++++++------------- .../ui/main/settings/HomeSettingsViewModel.kt | 19 +++++++++++------ 5 files changed, 38 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt index 7fa15ceb40..11f0ba0a0b 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt @@ -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)) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt index 6a0cfcceee..c71e62eb55 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt @@ -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( diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index 3c3bdf9baf..82ae6f9a26 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -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) } }, ) } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt index ff6ff4f7ea..41188e6332 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt @@ -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( diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 348cbf7b47..ceba6b30a2 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -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, From f315531db783a3fbb593786c12f01215354a1872 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 29 Jan 2026 15:49:25 -0500 Subject: [PATCH 29/53] Save/load from server --- .../wholphin/services/HomeSettingsService.kt | 2 +- .../ui/main/settings/HomeSettingsListItem.kt | 56 ++++++++++++ .../ui/main/settings/HomeSettingsPage.kt | 29 ++++++- .../ui/main/settings/HomeSettingsRowList.kt | 85 ++++++++++++------- .../ui/main/settings/HomeSettingsViewModel.kt | 46 ++++++++++ app/src/main/res/values/fa_strings.xml | 2 + app/src/main/res/values/strings.xml | 3 + 7 files changed, 191 insertions(+), 32 deletions(-) create mode 100644 app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsListItem.kt diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index b6a784b001..6bf03b7e02 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -399,7 +399,7 @@ class HomeSettingsService /** * Converts a [HomeRowConfig] into [HomeRowConfigDisplay] for UI purposes */ - private suspend fun resolve( + suspend fun resolve( id: Int, config: HomeRowConfig, ): HomeRowConfigDisplay = diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsListItem.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsListItem.kt new file mode 100644 index 0000000000..c9ea14d6a8 --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsListItem.kt @@ -0,0 +1,56 @@ +package com.github.damontecres.wholphin.ui.main.settings + +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.BoxScope +import androidx.compose.runtime.Composable +import androidx.compose.runtime.NonRestartableComposable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import androidx.tv.material3.ListItem +import androidx.tv.material3.ListItemBorder +import androidx.tv.material3.ListItemColors +import androidx.tv.material3.ListItemDefaults +import androidx.tv.material3.ListItemGlow +import androidx.tv.material3.ListItemScale +import androidx.tv.material3.ListItemShape + +@Composable +@NonRestartableComposable +fun HomeSettingsListItem( + selected: Boolean, + onClick: () -> Unit, + headlineContent: @Composable () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + onLongClick: (() -> Unit)? = null, + overlineContent: (@Composable () -> Unit)? = null, + supportingContent: (@Composable () -> Unit)? = null, + leadingContent: (@Composable BoxScope.() -> Unit)? = null, + trailingContent: (@Composable () -> Unit)? = null, + tonalElevation: Dp = 3.dp, + shape: ListItemShape = ListItemDefaults.shape(), + colors: ListItemColors = ListItemDefaults.colors(), + scale: ListItemScale = ListItemDefaults.scale(), + border: ListItemBorder = ListItemDefaults.border(), + glow: ListItemGlow = ListItemDefaults.glow(), + interactionSource: MutableInteractionSource? = null, +) = ListItem( + selected = selected, + onClick = onClick, + headlineContent = headlineContent, + modifier = modifier, + enabled = enabled, + onLongClick = onLongClick, + overlineContent = overlineContent, + supportingContent = supportingContent, + leadingContent = leadingContent, + trailingContent = trailingContent, + tonalElevation = tonalElevation, + shape = shape, + colors = colors, + scale = scale, + border = border, + glow = glow, + interactionSource = interactionSource, +) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index 82ae6f9a26..1076d727f5 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -12,8 +12,12 @@ import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel import androidx.lifecycle.viewmodel.navigation3.rememberViewModelStoreNavEntryDecorator @@ -23,6 +27,8 @@ import androidx.navigation3.runtime.rememberSaveableStateHolderNavEntryDecorator import androidx.navigation3.ui.NavDisplay import androidx.tv.material3.MaterialTheme import androidx.tv.material3.surfaceColorAtElevation +import com.github.damontecres.wholphin.R +import com.github.damontecres.wholphin.ui.components.ConfirmDialog 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 @@ -41,6 +47,7 @@ fun HomeSettingsPage( val scope = rememberCoroutineScope() val listState = rememberLazyListState() val backStack = rememberNavBackStack(HomeSettingsDestination.RowList) + var showConfirmDialog by remember { mutableStateOf<(() -> Unit)?>(null) } val state by viewModel.state.collectAsState() val discoverEnabled by viewModel.discoverEnabled.collectAsState(false) @@ -86,7 +93,16 @@ fun HomeSettingsPage( HomeSettingsRowList( state = state, onClickAdd = { backStack.add(HomeSettingsDestination.AddRow) }, - onClickSaveLocal = { viewModel.saveToLocal() }, + onClickSave = { + showConfirmDialog = { + viewModel.saveToRemote() + } + }, + onClickLoad = { + showConfirmDialog = { + viewModel.loadFromRemote() + } + }, onClickMove = viewModel::moveRow, onClickDelete = viewModel::deleteRow, onClick = { index, row -> @@ -189,4 +205,15 @@ fun HomeSettingsPage( .weight(1f), ) } + showConfirmDialog?.let { onConfirm -> + ConfirmDialog( + title = stringResource(R.string.confirm), + body = "Overwrite?", + onCancel = { showConfirmDialog = null }, + onConfirm = { + onConfirm.invoke() + showConfirmDialog = null + }, + ) + } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt index 41188e6332..9d0cd9f1fb 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt @@ -12,7 +12,6 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add -import androidx.compose.material.icons.filled.Create import androidx.compose.material.icons.filled.Delete import androidx.compose.material.icons.filled.Edit import androidx.compose.material3.HorizontalDivider @@ -27,9 +26,11 @@ import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.focusRestorer import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.tv.material3.Icon +import androidx.tv.material3.MaterialTheme import androidx.tv.material3.Text import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.services.HomeRowConfigDisplay @@ -47,7 +48,8 @@ fun HomeSettingsRowList( state: HomePageSettingsState, onClick: (Int, HomeRowConfigDisplay) -> Unit, onClickResize: (Int) -> Unit, - onClickSaveLocal: () -> Unit, + onClickSave: () -> Unit, + onClickLoad: () -> Unit, onClickAdd: () -> Unit, onClickMove: (MoveDirection, Int) -> Unit, onClickDelete: (Int) -> Unit, @@ -83,38 +85,56 @@ fun HomeSettingsRowList( ) } item { - HomeSettingsListItem( - selected = false, - headlineContent = { - Text( - text = "Increase card sizes", - ) - }, - leadingContent = { - Icon( - imageVector = Icons.Default.Edit, - contentDescription = null, - ) - }, - onClick = { onClickResize.invoke(1) }, - modifier = Modifier, - ) + Row { + HomeSettingsListItem( + selected = false, + headlineContent = { + Text( + text = "Increase card sizes", + ) + }, + leadingContent = { + Icon( + imageVector = Icons.Default.Edit, + contentDescription = null, + ) + }, + onClick = { onClickResize.invoke(1) }, + modifier = Modifier.weight(1f), + ) + HomeSettingsListItem( + selected = false, + headlineContent = { + Text( + text = "Decrease card sizes", + ) + }, + leadingContent = { + Icon( + imageVector = Icons.Default.Edit, + contentDescription = null, + ) + }, + onClick = { onClickResize.invoke(-1) }, + modifier = Modifier.weight(1f), + ) + } } item { HomeSettingsListItem( selected = false, headlineContent = { Text( - text = "Decrease card sizes", + text = stringResource(R.string.save_to_server), ) }, leadingContent = { - Icon( - imageVector = Icons.Default.Edit, - contentDescription = null, + Text( + text = stringResource(R.string.fa_cloud_arrow_up), + fontFamily = FontAwesome, ) }, - onClick = { onClickResize.invoke(-1) }, + onClick = onClickSave, modifier = Modifier, ) } @@ -123,20 +143,26 @@ fun HomeSettingsRowList( selected = false, headlineContent = { Text( - text = stringResource(R.string.save), + text = stringResource(R.string.load_from_server), ) }, leadingContent = { - Icon( - imageVector = Icons.Default.Create, - contentDescription = null, + Text( + text = stringResource(R.string.fa_cloud_arrow_down), + fontFamily = FontAwesome, ) }, - onClick = onClickSaveLocal, + onClick = onClickLoad, modifier = Modifier, ) } item { + Text( + text = stringResource(R.string.home_rows), + style = MaterialTheme.typography.titleLarge, + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth(), + ) HorizontalDivider() } itemsIndexed(state.rows, key = { _, row -> row.id }) { index, row -> @@ -192,8 +218,7 @@ fun HomeRowConfigContent( Text( text = config.title, overflow = TextOverflow.Ellipsis, - modifier = - Modifier, + modifier = Modifier, ) }, onClick = onClick, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index ceba6b30a2..11962c185d 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -339,6 +339,52 @@ class HomeSettingsViewModel } } + fun saveToRemote() { + viewModelScope.launchIO { + serverRepository.currentUser.value?.let { user -> + Timber.d("Saving home settings to remote") + val rows = state.value.rows.map { it.config } + val settings = HomePageSettings(rows = rows) + try { + Timber.d("saveToRemote") + homeSettingsService.saveToServer(user.id, settings) + } catch (ex: Exception) { + Timber.e(ex) + showToast(context, "Error saving: ${ex.localizedMessage}") + } + } + } + } + + fun loadFromRemote() { + viewModelScope.launchIO { + serverRepository.currentUser.value?.let { user -> + Timber.d("Loading home settings from remote") + try { + _state.update { it.copy(loading = LoadingState.Loading) } + val result = homeSettingsService.loadFromServer(user.id) + if (result != null) { + Timber.v("Got remote settings") + val newRows = + result.rows.mapIndexed { index, config -> + homeSettingsService.resolve(index, config) + } + _state.update { + it.copy(rows = newRows) + } + } else { + Timber.v("No remote settings") + showToast(context, "No server-side settings found") + } + fetchRowData() + } catch (ex: Exception) { + Timber.e(ex) + showToast(context, "Error: ${ex.localizedMessage}") + } + } + } + } + fun saveToLocal() { // This uses injected ioScope so that it will still run when the page is closing ioScope.launchIO { diff --git a/app/src/main/res/values/fa_strings.xml b/app/src/main/res/values/fa_strings.xml index ae2a4ae1fb..adf2c254d6 100644 --- a/app/src/main/res/values/fa_strings.xml +++ b/app/src/main/res/values/fa_strings.xml @@ -50,4 +50,6 @@ + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 150d121399..b3050ad83f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -468,6 +468,9 @@ Height Apply to all rows Customize home page + Home rows + Load from server + Save to server Disabled From b73900b698edba5ef78c438efd9ee2e8c8a12821 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 29 Jan 2026 16:03:27 -0500 Subject: [PATCH 30/53] Move some settings to new page --- .../main/settings/HomeSettingsDestination.kt | 3 + .../ui/main/settings/HomeSettingsGlobal.kt | 146 ++++++++++++++++++ .../ui/main/settings/HomeSettingsPage.kt | 39 +++-- .../ui/main/settings/HomeSettingsRowList.kt | 76 ++------- app/src/main/res/values/strings.xml | 1 + 5 files changed, 186 insertions(+), 79 deletions(-) create mode 100644 app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt index 7aa65db997..8148e6199e 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt @@ -29,4 +29,7 @@ sealed interface HomeSettingsDestination : NavKey { @Serializable data object ChooseDiscover : HomeSettingsDestination + + @Serializable + data object GlobalSettings : HomeSettingsDestination } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt new file mode 100644 index 0000000000..309d7d8861 --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt @@ -0,0 +1,146 @@ +package com.github.damontecres.wholphin.ui.main.settings + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.KeyboardArrowDown +import androidx.compose.material.icons.filled.KeyboardArrowUp +import androidx.compose.material3.HorizontalDivider +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +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.Icon +import androidx.tv.material3.MaterialTheme +import androidx.tv.material3.Text +import com.github.damontecres.wholphin.R +import com.github.damontecres.wholphin.ui.FontAwesome +import com.github.damontecres.wholphin.ui.tryRequestFocus + +@Composable +fun HomeSettingsGlobal( + onClickResize: (Int) -> Unit, + onClickSave: () -> Unit, + onClickLoad: () -> Unit, + onClickLoadWeb: () -> Unit, + modifier: Modifier = Modifier, +) { + val firstFocus: FocusRequester = remember { FocusRequester() } + LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } + Column(modifier = modifier) { + Text( + text = stringResource(R.string.settings), + style = MaterialTheme.typography.titleLarge, + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth(), + ) + HorizontalDivider() + LazyColumn( + verticalArrangement = Arrangement.spacedBy(8.dp), + modifier = + modifier + .fillMaxHeight() + .focusRestorer(firstFocus), + ) { + item { + HomeSettingsListItem( + selected = false, + headlineContent = { + Text( + text = "Increase card sizes", + ) + }, + leadingContent = { + Icon( + imageVector = Icons.Default.KeyboardArrowUp, + contentDescription = null, + ) + }, + onClick = { onClickResize.invoke(1) }, + modifier = Modifier, + ) + } + item { + HomeSettingsListItem( + selected = false, + headlineContent = { + Text( + text = "Decrease card sizes", + ) + }, + leadingContent = { + Icon( + imageVector = Icons.Default.KeyboardArrowDown, + contentDescription = null, + ) + }, + onClick = { onClickResize.invoke(-1) }, + modifier = Modifier, + ) + } + item { HorizontalDivider() } + item { + HomeSettingsListItem( + selected = false, + headlineContent = { + Text( + text = stringResource(R.string.save_to_server), + ) + }, + leadingContent = { + Text( + text = stringResource(R.string.fa_cloud_arrow_up), + fontFamily = FontAwesome, + ) + }, + onClick = onClickSave, + modifier = Modifier, + ) + } + item { + HomeSettingsListItem( + selected = false, + headlineContent = { + Text( + text = stringResource(R.string.load_from_server), + ) + }, + leadingContent = { + Text( + text = stringResource(R.string.fa_cloud_arrow_down), + fontFamily = FontAwesome, + ) + }, + onClick = onClickLoad, + modifier = Modifier, + ) + } + item { + HomeSettingsListItem( + selected = false, + headlineContent = { + Text( + text = stringResource(R.string.load_from_web_client), + ) + }, + leadingContent = { + Text( + text = stringResource(R.string.fa_download), + fontFamily = FontAwesome, + ) + }, + onClick = onClickLoadWeb, + modifier = Modifier, + ) + } + } + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index 1076d727f5..386eae8795 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -82,27 +82,18 @@ fun HomeSettingsPage( ), modifier = Modifier.background(MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp)), entryProvider = { key -> - key as HomeSettingsDestination - NavEntry(key, contentKey = key.toString()) { + val dest = key as HomeSettingsDestination + NavEntry(dest, contentKey = key.toString()) { val destModifier = Modifier .fillMaxSize() .padding(4.dp) - when (val dest = key) { + when (dest) { HomeSettingsDestination.RowList -> { HomeSettingsRowList( state = state, onClickAdd = { backStack.add(HomeSettingsDestination.AddRow) }, - onClickSave = { - showConfirmDialog = { - viewModel.saveToRemote() - } - }, - onClickLoad = { - showConfirmDialog = { - viewModel.loadFromRemote() - } - }, + onClickSettings = { backStack.add(HomeSettingsDestination.GlobalSettings) }, onClickMove = viewModel::moveRow, onClickDelete = viewModel::deleteRow, onClick = { index, row -> @@ -112,9 +103,6 @@ fun HomeSettingsPage( listState.scrollToItem(index) } }, - onClickResize = { - viewModel.resizeCards(it) - }, modifier = destModifier, ) } @@ -184,6 +172,25 @@ fun HomeSettingsPage( }, ) } + + HomeSettingsDestination.GlobalSettings -> { + HomeSettingsGlobal( + onClickResize = { viewModel.resizeCards(it) }, + onClickSave = { + showConfirmDialog = { + viewModel.saveToRemote() + } + }, + onClickLoad = { + showConfirmDialog = { + viewModel.loadFromRemote() + } + }, + onClickLoadWeb = { + }, + modifier = destModifier, + ) + } } } }, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt index 9d0cd9f1fb..59199ecaa0 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt @@ -13,7 +13,7 @@ import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.Delete -import androidx.compose.material.icons.filled.Edit +import androidx.compose.material.icons.filled.Settings import androidx.compose.material3.HorizontalDivider import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -47,10 +47,8 @@ enum class MoveDirection { fun HomeSettingsRowList( state: HomePageSettingsState, onClick: (Int, HomeRowConfigDisplay) -> Unit, - onClickResize: (Int) -> Unit, - onClickSave: () -> Unit, - onClickLoad: () -> Unit, onClickAdd: () -> Unit, + onClickSettings: () -> Unit, onClickMove: (MoveDirection, Int) -> Unit, onClickDelete: (Int) -> Unit, modifier: Modifier, @@ -59,6 +57,12 @@ fun HomeSettingsRowList( val focusManager = LocalFocusManager.current LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } Column(modifier = modifier) { + Text( + text = stringResource(R.string.customize_home), + style = MaterialTheme.typography.titleLarge, + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth(), + ) LazyColumn( verticalArrangement = Arrangement.spacedBy(8.dp), modifier = @@ -84,75 +88,21 @@ fun HomeSettingsRowList( modifier = Modifier.focusRequester(firstFocus), ) } - item { - Row { - HomeSettingsListItem( - selected = false, - headlineContent = { - Text( - text = "Increase card sizes", - ) - }, - leadingContent = { - Icon( - imageVector = Icons.Default.Edit, - contentDescription = null, - ) - }, - onClick = { onClickResize.invoke(1) }, - modifier = Modifier.weight(1f), - ) - HomeSettingsListItem( - selected = false, - headlineContent = { - Text( - text = "Decrease card sizes", - ) - }, - leadingContent = { - Icon( - imageVector = Icons.Default.Edit, - contentDescription = null, - ) - }, - onClick = { onClickResize.invoke(-1) }, - modifier = Modifier.weight(1f), - ) - } - } - item { - HomeSettingsListItem( - selected = false, - headlineContent = { - Text( - text = stringResource(R.string.save_to_server), - ) - }, - leadingContent = { - Text( - text = stringResource(R.string.fa_cloud_arrow_up), - fontFamily = FontAwesome, - ) - }, - onClick = onClickSave, - modifier = Modifier, - ) - } item { HomeSettingsListItem( selected = false, headlineContent = { Text( - text = stringResource(R.string.load_from_server), + text = stringResource(R.string.settings), ) }, leadingContent = { - Text( - text = stringResource(R.string.fa_cloud_arrow_down), - fontFamily = FontAwesome, + Icon( + imageVector = Icons.Default.Settings, + contentDescription = null, ) }, - onClick = onClickLoad, + onClick = onClickSettings, modifier = Modifier, ) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b3050ad83f..55c15cfb85 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -471,6 +471,7 @@ Home rows Load from server Save to server + Load from web client Disabled From 44a08f27c1d0b457ba4dfc2c7f70372be4fc80ff Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 29 Jan 2026 16:29:52 -0500 Subject: [PATCH 31/53] Add toggle for using series image --- .../wholphin/services/HomeSettingsService.kt | 33 +++++++++++++------ .../wholphin/services/LatestNextUpService.kt | 6 ++-- .../ui/main/settings/HomeRowSettings.kt | 6 ++-- .../ui/main/settings/HomeSettingsViewModel.kt | 13 +++++--- app/src/main/res/values/strings.xml | 1 + 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index 6bf03b7e02..4e82ba0a9e 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -110,7 +110,7 @@ class HomeSettingsService displayPreferencesId: String = DISPLAY_PREF_ID, ): HomePageSettings? { val current = getDisplayPreferences(userId, displayPreferencesId) - return current.customPrefs[DISPLAY_PREF_ID]?.let { + return current.customPrefs[CUSTOM_PREF_ID]?.let { val jsonElement = jsonParser.parseToJsonElement(it) decode(jsonElement) } @@ -515,7 +515,13 @@ class HomeSettingsService ): HomeRowLoadingState = when (row) { is HomeRowConfig.ContinueWatching -> { - val resume = latestNextUpService.getResume(userDto.id, limit, true) + val resume = + latestNextUpService.getResume( + userDto.id, + limit, + true, + row.viewOptions.useSeries, + ) Success( title = context.getString(R.string.continue_watching), @@ -531,6 +537,7 @@ class HomeSettingsService limit, prefs.enableRewatchingNextUp, false, + row.viewOptions.useSeries, ) Success( @@ -542,13 +549,19 @@ class HomeSettingsService is HomeRowConfig.ContinueWatchingCombined -> { val resume = - latestNextUpService.getResume(userDto.id, limit, true) + latestNextUpService.getResume( + userDto.id, + limit, + true, + row.viewOptions.useSeries, + ) val nextUp = latestNextUpService.getNextUp( userDto.id, limit, prefs.enableRewatchingNextUp, false, + row.viewOptions.useSeries, ) Success( @@ -625,7 +638,7 @@ class HomeSettingsService api.userLibraryApi .getLatestMedia(request) .content - .map { BaseItem.Companion.from(it, api, true) } + .map { BaseItem.Companion.from(it, api, row.viewOptions.useSeries) } .let { Success( title, @@ -657,7 +670,7 @@ class HomeSettingsService GetItemsRequestHandler .execute(api, request) .content.items - .map { BaseItem.Companion.from(it, api, true) } + .map { BaseItem.Companion.from(it, api, row.viewOptions.useSeries) } .let { Success( title, @@ -685,7 +698,7 @@ class HomeSettingsService GetItemsRequestHandler .execute(api, request) .content.items - .map { BaseItem(it, true) } + .map { BaseItem(it, row.viewOptions.useSeries) } .let { Success( name ?: context.getString(R.string.collection), @@ -712,7 +725,7 @@ class HomeSettingsService GetItemsRequestHandler .execute(api, request) .content.items - .map { BaseItem(it, true) } + .map { BaseItem(it, row.viewOptions.useSeries) } .let { Success( row.name, @@ -757,7 +770,7 @@ class HomeSettingsService GetItemsRequestHandler .execute(api, request) .content.items - .map { BaseItem(it, false) } + .map { BaseItem(it, row.viewOptions.useSeries) } .let { Success( context.getString(R.string.favorites), // TODO @@ -781,7 +794,7 @@ class HomeSettingsService api.liveTvApi .getRecordings(request) .content.items - .map { BaseItem(it, true) } + .map { BaseItem(it, row.viewOptions.useSeries) } .let { Success( context.getString(R.string.active_recordings), @@ -803,7 +816,7 @@ class HomeSettingsService api.liveTvApi .getRecommendedPrograms(request) .content.items - .map { BaseItem(it, true) } + .map { BaseItem(it, row.viewOptions.useSeries) } .let { Success( context.getString(R.string.live_tv), diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/LatestNextUpService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/LatestNextUpService.kt index 307125fbf9..c9c989f2ee 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/LatestNextUpService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/LatestNextUpService.kt @@ -43,6 +43,7 @@ class LatestNextUpService userId: UUID, limit: Int, includeEpisodes: Boolean, + useSeriesForPrimary: Boolean = true, ): List { val request = GetResumeItemsRequest( @@ -65,7 +66,7 @@ class LatestNextUpService .getResumeItems(request) .content .items - .map { BaseItem.from(it, api, true) } + .map { BaseItem.from(it, api, useSeriesForPrimary) } return items } @@ -74,6 +75,7 @@ class LatestNextUpService limit: Int, enableRewatching: Boolean, enableResumable: Boolean, + useSeriesForPrimary: Boolean = true, ): List { val request = GetNextUpRequest( @@ -91,7 +93,7 @@ class LatestNextUpService .getNextUp(request) .content .items - .map { BaseItem.from(it, api, true) } + .map { BaseItem.from(it, api, useSeriesForPrimary) } return nextUp } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt index 5858a02808..457a7e3dca 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt @@ -135,7 +135,7 @@ internal object Options { val ViewOptionsUseSeries = AppSwitchPreference( - title = R.string.go_to_series, // TODO + title = R.string.use_series, defaultValue = true, getter = { it.useSeries }, setter = { vo, value -> vo.copy(useSeries = value) }, @@ -175,11 +175,11 @@ internal object Options { ViewOptionsAspectRatio, // TODO // ViewOptionsShowTitles, -// ViewOptionsUseSeries, + ViewOptionsUseSeries, ViewOptionsColumns, ViewOptionsSpacing, ViewOptionsContentScale, - ViewOptionsApplyAll, +// ViewOptionsApplyAll, ViewOptionsReset, ) } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 11962c185d..a4f4a33887 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -296,13 +296,15 @@ class HomeSettingsViewModel viewOptions: HomeRowViewOptions, ) { viewModelScope.launchIO { + var fetchData = false updateState { val index = it.rows.indexOfFirst { it.id == rowId } - val newRowConfig = - it.rows[index] - .config - .updateViewOptions(viewOptions) + val config = it.rows[index].config + val newRowConfig = config.updateViewOptions(viewOptions) val newRow = it.rows[index].copy(config = newRowConfig) + if (config.viewOptions.useSeries != viewOptions.useSeries) { + fetchData = true + } it.copy( rows = it.rows.toMutableList().apply { @@ -321,6 +323,9 @@ class HomeSettingsViewModel }, ) } + if (fetchData) { + fetchRowData() + } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 55c15cfb85..f81e123b68 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -472,6 +472,7 @@ Load from server Save to server Load from web client + Use series image Disabled From 43fde88695474d14916ed871f767bccce8fa9ea8 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 29 Jan 2026 16:56:11 -0500 Subject: [PATCH 32/53] Disable discover & use different settings for genre rows --- .../wholphin/ui/main/settings/HomeRowSettings.kt | 15 ++++++++++++--- .../ui/main/settings/HomeSettingsFavoriteList.kt | 5 +++-- .../wholphin/ui/main/settings/HomeSettingsPage.kt | 5 ++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt index 457a7e3dca..b31245e8c5 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt @@ -37,9 +37,11 @@ fun HomeRowSettings( viewOptions: HomeRowViewOptions, onViewOptionsChange: (HomeRowViewOptions) -> Unit, onApplyApplyAll: () -> Unit, + userGenreSettings: Boolean, modifier: Modifier = Modifier, defaultViewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) { + val options = if (userGenreSettings) Options.GENRE_OPTIONS else Options.OPTIONS val firstFocus = remember { FocusRequester() } LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } Column(modifier = modifier) { @@ -49,7 +51,7 @@ fun HomeRowSettings( color = MaterialTheme.colorScheme.onSurface, ) LazyColumn { - itemsIndexed(Options.OPTIONS) { index, pref -> + itemsIndexed(options) { index, pref -> pref as AppPreference val interactionSource = remember { MutableInteractionSource() } val value = pref.getter.invoke(viewOptions) @@ -82,7 +84,7 @@ fun HomeRowSettings( } internal object Options { - val ViewOptionsColumns = + val ViewOptionsCardHeight = AppSliderPreference( title = R.string.height, defaultValue = Cards.HEIGHT_2X3_DP.toLong(), @@ -176,10 +178,17 @@ internal object Options { // TODO // ViewOptionsShowTitles, ViewOptionsUseSeries, - ViewOptionsColumns, + ViewOptionsCardHeight, ViewOptionsSpacing, ViewOptionsContentScale, // ViewOptionsApplyAll, ViewOptionsReset, ) + + val GENRE_OPTIONS = + listOf( + ViewOptionsCardHeight, + ViewOptionsSpacing, + ViewOptionsReset, + ) } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt index c71e62eb55..7e78e73936 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt @@ -56,7 +56,7 @@ fun HomeSettingsFavoriteList( } } -val favoriteOptions = +val favoriteOptions by lazy { mapOf( BaseItemKind.MOVIE to R.string.movies, BaseItemKind.SERIES to R.string.tv_shows, @@ -65,4 +65,5 @@ val favoriteOptions = BaseItemKind.PLAYLIST to R.string.playlists, BaseItemKind.PERSON to R.string.people, ) -val favoriteOptionsList = favoriteOptions.keys.toList() +} +val favoriteOptionsList by lazy { favoriteOptions.keys.toList() } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index 386eae8795..cd61e39122 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -28,6 +28,7 @@ import androidx.navigation3.ui.NavDisplay import androidx.tv.material3.MaterialTheme import androidx.tv.material3.surfaceColorAtElevation import com.github.damontecres.wholphin.R +import com.github.damontecres.wholphin.data.model.HomeRowConfig import com.github.damontecres.wholphin.ui.components.ConfirmDialog import com.github.damontecres.wholphin.ui.main.HomePageContent import com.github.damontecres.wholphin.ui.main.settings.HomeSettingsDestination.ChooseRowType @@ -50,7 +51,8 @@ fun HomeSettingsPage( var showConfirmDialog by remember { mutableStateOf<(() -> Unit)?>(null) } val state by viewModel.state.collectAsState() - val discoverEnabled by viewModel.discoverEnabled.collectAsState(false) + // TODO discover rows + 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) { @@ -157,6 +159,7 @@ fun HomeSettingsPage( onApplyApplyAll = { viewModel.updateViewOptionsForAll(row.config.viewOptions) }, + userGenreSettings = row.config is HomeRowConfig.Genres, modifier = destModifier, ) } From 7e53f9505479ebfed021782cc41bb199bfc4f743 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 29 Jan 2026 18:13:32 -0500 Subject: [PATCH 33/53] Focus improvements --- .../ui/main/settings/HomeSettingsAddRow.kt | 4 +- .../ui/main/settings/HomeSettingsGlobal.kt | 3 +- .../ui/main/settings/HomeSettingsRowList.kt | 54 ++++++++++++++--- .../ui/main/settings/HomeSettingsViewModel.kt | 59 +++++++++++-------- 4 files changed, 84 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt index 11f0ba0a0b..d805c4beb3 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt @@ -11,7 +11,6 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.material3.HorizontalDivider import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester @@ -24,7 +23,6 @@ import androidx.tv.material3.MaterialTheme import androidx.tv.material3.Text import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.ui.ifElse -import com.github.damontecres.wholphin.ui.tryRequestFocus @Composable fun HomeSettingsAddRow( @@ -35,7 +33,7 @@ fun HomeSettingsAddRow( modifier: Modifier, firstFocus: FocusRequester = remember { FocusRequester() }, ) { - LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } +// LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } Column(modifier = modifier) { Text( text = "Add row for...", diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt index 309d7d8861..3c619e4e7a 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt @@ -14,6 +14,7 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.focusRestorer import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign @@ -65,7 +66,7 @@ fun HomeSettingsGlobal( ) }, onClick = { onClickResize.invoke(1) }, - modifier = Modifier, + modifier = Modifier.focusRequester(firstFocus), ) } item { diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt index 59199ecaa0..3a1da2fd1a 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt @@ -10,6 +10,7 @@ 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.lazy.rememberLazyListState import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.Delete @@ -17,7 +18,10 @@ import androidx.compose.material.icons.filled.Settings import androidx.compose.material3.HorizontalDivider import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusDirection @@ -36,7 +40,9 @@ import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.services.HomeRowConfigDisplay import com.github.damontecres.wholphin.ui.FontAwesome import com.github.damontecres.wholphin.ui.components.Button +import com.github.damontecres.wholphin.ui.rememberInt import com.github.damontecres.wholphin.ui.tryRequestFocus +import kotlinx.coroutines.launch enum class MoveDirection { UP, @@ -55,7 +61,16 @@ fun HomeSettingsRowList( firstFocus: FocusRequester = remember { FocusRequester() }, ) { val focusManager = LocalFocusManager.current - LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } + val scope = rememberCoroutineScope() + val listState = rememberLazyListState() + + val itemsBeforeRows = 3 + val focusRequesters = + remember(state.rows.size) { List(itemsBeforeRows + state.rows.size) { FocusRequester() } } + + var position by rememberInt(0) + + LaunchedEffect(Unit) { focusRequesters.getOrNull(position)?.tryRequestFocus() } Column(modifier = modifier) { Text( text = stringResource(R.string.customize_home), @@ -64,6 +79,7 @@ fun HomeSettingsRowList( modifier = Modifier.fillMaxWidth(), ) LazyColumn( + state = listState, verticalArrangement = Arrangement.spacedBy(8.dp), modifier = modifier @@ -84,8 +100,11 @@ fun HomeSettingsRowList( contentDescription = null, ) }, - onClick = onClickAdd, - modifier = Modifier.focusRequester(firstFocus), + onClick = { + position = 0 + onClickAdd.invoke() + }, + modifier = Modifier.focusRequester(focusRequesters[0]), ) } item { @@ -102,8 +121,11 @@ fun HomeSettingsRowList( contentDescription = null, ) }, - onClick = onClickSettings, - modifier = Modifier, + onClick = { + position = 1 + onClickSettings.invoke() + }, + modifier = Modifier.focusRequester(focusRequesters[1]), ) } item { @@ -121,7 +143,18 @@ fun HomeSettingsRowList( moveUpAllowed = index > 0, moveDownAllowed = index != state.rows.lastIndex, deleteAllowed = state.rows.size > 1, - onClickMove = { onClickMove.invoke(it, index) }, + onClickMove = { + onClickMove.invoke(it, index) + scope.launch { + val scrollIndex = + itemsBeforeRows + if (it == MoveDirection.UP) index - 1 else index + 1 + if (scrollIndex < listState.firstVisibleItemIndex || + scrollIndex > listState.layoutInfo.visibleItemsInfo.lastIndex + ) { + listState.animateScrollToItem(scrollIndex) + } + } + }, onClickDelete = { if (index != state.rows.lastIndex) { focusManager.moveFocus(FocusDirection.Down) @@ -130,10 +163,15 @@ fun HomeSettingsRowList( } onClickDelete.invoke(index) }, - onClick = { onClick.invoke(index, row) }, + onClick = { + position = itemsBeforeRows + index + onClick.invoke(index, row) + }, modifier = Modifier - .fillMaxWidth(), + .fillMaxWidth() + .animateItem() + .focusRequester(focusRequesters[itemsBeforeRows + index]), ) } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index a4f4a33887..12db733237 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -30,11 +30,16 @@ 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.Dispatchers import kotlinx.coroutines.Job +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.update +import kotlinx.coroutines.sync.Semaphore +import kotlinx.coroutines.sync.withPermit import kotlinx.serialization.Serializable import org.jellyfin.sdk.model.api.BaseItemKind import org.jellyfin.sdk.model.api.CollectionType @@ -95,24 +100,29 @@ class HomeSettingsViewModel private suspend fun fetchRowData() { val limit = 6 + val semaphore = Semaphore(4) val rows = serverRepository.currentUserDto.value?.let { userDto -> val prefs = userPreferencesService.getCurrent().appPreferences.homePagePreferences - state.value.let { state -> - state.rows - .map { it.config } - .map { row -> - // TODO parallelize - homeSettingsService.fetchDataForRow( - row = row, - scope = viewModelScope, - prefs = prefs, - userDto = userDto, - libraries = state.libraries, - limit = limit, - ) - } - } + state.value + .let { state -> + state.rows + .map { it.config } + .map { row -> + viewModelScope.async(Dispatchers.IO) { + semaphore.withPermit { + homeSettingsService.fetchDataForRow( + row = row, + scope = viewModelScope, + prefs = prefs, + userDto = userDto, + libraries = state.libraries, + limit = limit, + ) + } + } + } + }.awaitAll() } rows?.let { rows -> rows @@ -152,16 +162,17 @@ class HomeSettingsViewModel direction: MoveDirection, index: Int, ) { - updateState { - val rows = it.rows.move(direction, index) - // TODO would be more efficient to move rowData, but uncombined continue watching is two rows -// val rowData = it.rowData.move(direction, index) - it.copy( - loading = LoadingState.Loading, - rows = rows, - ) + viewModelScope.launchIO { + updateState { + val rows = it.rows.move(direction, index) + val rowData = it.rowData.move(direction, index) + it.copy( + rows = rows, + rowData = rowData, + ) + } } - viewModelScope.launchIO { fetchRowData() } +// viewModelScope.launchIO { fetchRowData() } } fun deleteRow(index: Int) { From fb891799c76affb58d16cf9fcff4ea1f0c909a30 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 29 Jan 2026 18:30:18 -0500 Subject: [PATCH 34/53] Backdrops for genre cards --- .../damontecres/wholphin/services/BackdropService.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/BackdropService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/BackdropService.kt index a64fc9d974..e082c5faa5 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/BackdropService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/BackdropService.kt @@ -26,6 +26,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.update import kotlinx.coroutines.withContext +import org.jellyfin.sdk.model.api.BaseItemKind import org.jellyfin.sdk.model.api.ImageType import timber.log.Timber import javax.inject.Inject @@ -47,7 +48,12 @@ class BackdropService suspend fun submit(item: BaseItem) = withContext(Dispatchers.IO) { - val imageUrl = imageUrlService.getItemImageUrl(item, ImageType.BACKDROP)!! + val imageUrl = + if (item.type == BaseItemKind.GENRE) { + item.imageUrlOverride + } else { + imageUrlService.getItemImageUrl(item, ImageType.BACKDROP)!! + } submit(item.id.toString(), imageUrl) } From d3448771c8cad646f7656073695028b4aa83e37b Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 29 Jan 2026 19:35:42 -0500 Subject: [PATCH 35/53] More consistent titles --- .../main/settings/HomeLibraryRowTypeList.kt | 4 +- .../ui/main/settings/HomeRowSettings.kt | 7 +--- .../ui/main/settings/HomeSettingsAddRow.kt | 42 ++----------------- .../main/settings/HomeSettingsFavoriteList.kt | 4 +- .../ui/main/settings/HomeSettingsGlobal.kt | 4 +- .../ui/main/settings/HomeSettingsRowList.kt | 29 +++++++------ app/src/main/res/values/strings.xml | 1 + 7 files changed, 27 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeLibraryRowTypeList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeLibraryRowTypeList.kt index 421bc9bfe6..ea4ba9e214 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeLibraryRowTypeList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeLibraryRowTypeList.kt @@ -32,9 +32,7 @@ fun HomeLibraryRowTypeList( ) { LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } Column(modifier = modifier) { - Text( - text = "Add row for ${library.name}", - ) + TitleText(stringResource(R.string.add_row_for, library.name)) LazyColumn( contentPadding = PaddingValues(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp), diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt index b31245e8c5..adcb312447 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt @@ -13,7 +13,6 @@ import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.unit.dp 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.data.model.HomeRowViewOptions @@ -45,11 +44,7 @@ fun HomeRowSettings( val firstFocus = remember { FocusRequester() } LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } Column(modifier = modifier) { - Text( - text = title, - style = MaterialTheme.typography.titleLarge, - color = MaterialTheme.colorScheme.onSurface, - ) + TitleText(title) LazyColumn { itemsIndexed(options) { index, pref -> pref as AppPreference diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt index d805c4beb3..09f14bfc0b 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt @@ -5,8 +5,6 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.material3.HorizontalDivider @@ -17,9 +15,7 @@ import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester 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.MaterialTheme import androidx.tv.material3.Text import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.ui.ifElse @@ -35,9 +31,7 @@ fun HomeSettingsAddRow( ) { // LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } Column(modifier = modifier) { - Text( - text = "Add row for...", - ) + TitleText(stringResource(R.string.add_row)) LazyColumn( contentPadding = PaddingValues(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp), @@ -46,18 +40,6 @@ fun HomeSettingsAddRow( .fillMaxHeight() .focusRestorer(firstFocus), ) { - item { - Text( - text = stringResource(R.string.continue_watching), - style = MaterialTheme.typography.titleMedium, - color = MaterialTheme.colorScheme.onSurface, - textAlign = TextAlign.Start, - modifier = - Modifier - .fillMaxWidth() - .padding(top = 8.dp, bottom = 4.dp), - ) - } itemsIndexed( listOf( MetaRowType.CONTINUE_WATCHING, @@ -75,17 +57,8 @@ fun HomeSettingsAddRow( ) } item { + TitleText(stringResource(R.string.library)) HorizontalDivider() - Text( - text = stringResource(R.string.library), - style = MaterialTheme.typography.titleMedium, - color = MaterialTheme.colorScheme.onSurface, - textAlign = TextAlign.Start, - modifier = - Modifier - .fillMaxWidth() - .padding(top = 8.dp, bottom = 4.dp), - ) } itemsIndexed(libraries) { index, library -> HomeSettingsListItem( @@ -98,17 +71,8 @@ fun HomeSettingsAddRow( ) } item { + TitleText(stringResource(R.string.more)) HorizontalDivider() - Text( - text = stringResource(R.string.more), - style = MaterialTheme.typography.titleMedium, - color = MaterialTheme.colorScheme.onSurface, - textAlign = TextAlign.Start, - modifier = - Modifier - .fillMaxWidth() - .padding(top = 8.dp, bottom = 4.dp), - ) } item { HomeSettingsListItem( diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt index 7e78e73936..3dbea06494 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt @@ -29,8 +29,8 @@ fun HomeSettingsFavoriteList( ) { LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } Column(modifier = modifier) { - Text( - text = "Add favorites row...", + TitleText( + stringResource(R.string.add_row_for, stringResource(R.string.favorites)), ) LazyColumn( contentPadding = PaddingValues(8.dp), diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt index 3c619e4e7a..f9a5777713 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt @@ -56,7 +56,7 @@ fun HomeSettingsGlobal( selected = false, headlineContent = { Text( - text = "Increase card sizes", + text = "Increase all card size", ) }, leadingContent = { @@ -74,7 +74,7 @@ fun HomeSettingsGlobal( selected = false, headlineContent = { Text( - text = "Decrease card sizes", + text = "Decrease all card size", ) }, leadingContent = { diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt index 3a1da2fd1a..f0fc666159 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt @@ -18,6 +18,7 @@ import androidx.compose.material.icons.filled.Settings import androidx.compose.material3.HorizontalDivider import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.NonRestartableComposable import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope @@ -72,12 +73,7 @@ fun HomeSettingsRowList( LaunchedEffect(Unit) { focusRequesters.getOrNull(position)?.tryRequestFocus() } Column(modifier = modifier) { - Text( - text = stringResource(R.string.customize_home), - style = MaterialTheme.typography.titleLarge, - textAlign = TextAlign.Center, - modifier = Modifier.fillMaxWidth(), - ) + TitleText(stringResource(R.string.customize_home)) LazyColumn( state = listState, verticalArrangement = Arrangement.spacedBy(8.dp), @@ -129,12 +125,7 @@ fun HomeSettingsRowList( ) } item { - Text( - text = stringResource(R.string.home_rows), - style = MaterialTheme.typography.titleLarge, - textAlign = TextAlign.Center, - modifier = Modifier.fillMaxWidth(), - ) + TitleText(stringResource(R.string.home_rows)) HorizontalDivider() } itemsIndexed(state.rows, key = { _, row -> row.id }) { index, row -> @@ -248,3 +239,17 @@ fun HomeRowConfigContent( } } } + +@Composable +@NonRestartableComposable +fun TitleText( + title: String, + modifier: Modifier = Modifier, +) { + Text( + text = title, + style = MaterialTheme.typography.titleLarge, + textAlign = TextAlign.Center, + modifier = modifier.fillMaxWidth(), + ) +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f81e123b68..103b452966 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -473,6 +473,7 @@ Save to server Load from web client Use series image + Add row for %1$s Disabled From 8437ddb51d876a3a5d509f5fee8da7bf65678351 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 29 Jan 2026 19:47:10 -0500 Subject: [PATCH 36/53] Load from web client --- .../ui/main/settings/HomeSettingsPage.kt | 30 +++++++++++++------ .../ui/main/settings/HomeSettingsViewModel.kt | 25 ++++++++++++++++ app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index cd61e39122..9b5b6c8103 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -1,5 +1,6 @@ package com.github.damontecres.wholphin.ui.main.settings +import androidx.annotation.StringRes import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -48,7 +49,7 @@ fun HomeSettingsPage( val scope = rememberCoroutineScope() val listState = rememberLazyListState() val backStack = rememberNavBackStack(HomeSettingsDestination.RowList) - var showConfirmDialog by remember { mutableStateOf<(() -> Unit)?>(null) } + var showConfirmDialog by remember { mutableStateOf(null) } val state by viewModel.state.collectAsState() // TODO discover rows @@ -180,16 +181,22 @@ fun HomeSettingsPage( HomeSettingsGlobal( onClickResize = { viewModel.resizeCards(it) }, onClickSave = { - showConfirmDialog = { - viewModel.saveToRemote() - } + showConfirmDialog = + ShowConfirm(R.string.overwrite_server_settings) { + viewModel.saveToRemote() + } }, onClickLoad = { - showConfirmDialog = { - viewModel.loadFromRemote() - } + showConfirmDialog = + ShowConfirm(R.string.overwrite_local_settings) { + viewModel.loadFromRemote() + } }, onClickLoadWeb = { + showConfirmDialog = + ShowConfirm(R.string.overwrite_local_settings) { + viewModel.loadFromRemoteWeb() + } }, modifier = destModifier, ) @@ -215,10 +222,10 @@ fun HomeSettingsPage( .weight(1f), ) } - showConfirmDialog?.let { onConfirm -> + showConfirmDialog?.let { (body, onConfirm) -> ConfirmDialog( title = stringResource(R.string.confirm), - body = "Overwrite?", + body = stringResource(body), onCancel = { showConfirmDialog = null }, onConfirm = { onConfirm.invoke() @@ -227,3 +234,8 @@ fun HomeSettingsPage( ) } } + +data class ShowConfirm( + @param:StringRes val body: Int, + val onConfirm: () -> Unit, +) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 12db733237..62aa4eba42 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -401,6 +401,31 @@ class HomeSettingsViewModel } } + fun loadFromRemoteWeb() { + viewModelScope.launchIO { + serverRepository.currentUser.value?.let { user -> + Timber.d("Loading home settings from web") + try { + _state.update { it.copy(loading = LoadingState.Loading) } + val result = homeSettingsService.parseFromWebConfig(user.id) + if (result != null) { + Timber.v("Got web settings") + _state.update { + it.copy(rows = result.rows) + } + } else { + Timber.v("No web settings") + showToast(context, "No server-side web settings found") + } + fetchRowData() + } catch (ex: Exception) { + Timber.e(ex) + showToast(context, "Error: ${ex.localizedMessage}") + } + } + } + } + fun saveToLocal() { // This uses injected ioScope so that it will still run when the page is closing ioScope.launchIO { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 103b452966..8b80a127e6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -474,6 +474,8 @@ Load from web client Use series image Add row for %1$s + Overwrite settings on server? + Overwrite local settings? Disabled From bec833b0e8df4ba55454994bbe92a5ebf3059a68 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Fri, 30 Jan 2026 10:30:39 -0500 Subject: [PATCH 37/53] Move code into coroutines --- .../ui/main/settings/HomeSettingsViewModel.kt | 78 ++++++++++--------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 62aa4eba42..0e3e2c7e9f 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -176,13 +176,15 @@ class HomeSettingsViewModel } fun deleteRow(index: Int) { - updateState { - val rows = it.rows.toMutableList().apply { removeAt(index) } - val rowData = it.rowData.toMutableList().apply { removeAt(index) } - it.copy( - rows = rows, - rowData = rowData, - ) + viewModelScope.launchIO { + updateState { + val rows = it.rows.toMutableList().apply { removeAt(index) } + val rowData = it.rowData.toMutableList().apply { removeAt(index) } + it.copy( + rows = rows, + rowData = rowData, + ) + } } } @@ -341,17 +343,19 @@ class HomeSettingsViewModel } fun updateViewOptionsForAll(viewOptions: HomeRowViewOptions) { - updateState { - it.copy( - rowData = - it.rowData.toMutableList().map { row -> - if (row is HomeRowLoadingState.Success) { - row.copy(viewOptions = viewOptions) - } else { - row - } - }, - ) + viewModelScope.launchIO { + updateState { + it.copy( + rowData = + it.rowData.toMutableList().map { row -> + if (row is HomeRowLoadingState.Success) { + row.copy(viewOptions = viewOptions) + } else { + row + } + }, + ) + } } } @@ -456,24 +460,26 @@ class HomeSettingsViewModel } fun resizeCards(relative: Int) { - updateState { - val newRows = - it.rows.toMutableList().map { row -> - val vo = row.config.viewOptions - val newVo = vo.copy(heightDp = vo.heightDp + (4 * relative)) - row.copy(config = row.config.updateViewOptions(newVo)) - } - it.copy( - rows = newRows, - rowData = - it.rowData.toMutableList().mapIndexed { index, row -> - if (row is HomeRowLoadingState.Success) { - row.copy(viewOptions = newRows[index].config.viewOptions) - } else { - row - } - }, - ) + viewModelScope.launchIO { + updateState { + val newRows = + it.rows.toMutableList().map { row -> + val vo = row.config.viewOptions + val newVo = vo.copy(heightDp = vo.heightDp + (4 * relative)) + row.copy(config = row.config.updateViewOptions(newVo)) + } + it.copy( + rows = newRows, + rowData = + it.rowData.toMutableList().mapIndexed { index, row -> + if (row is HomeRowLoadingState.Success) { + row.copy(viewOptions = newRows[index].config.viewOptions) + } else { + row + } + }, + ) + } } } } From 7345b0406193601bf357b0005a8f8eb2a3cb9711 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Fri, 30 Jan 2026 17:52:41 -0500 Subject: [PATCH 38/53] Fix crash --- .../damontecres/wholphin/MainActivity.kt | 4 +-- .../wholphin/services/HomeSettingsService.kt | 32 +++++++++++-------- .../ui/main/settings/HomeSettingsViewModel.kt | 10 ++++-- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt b/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt index be7862dee7..0f8b7ee45c 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/MainActivity.kt @@ -265,9 +265,7 @@ class MainActivity : AppCompatActivity() { server = current.server, startDestination = requestedDestination - // TODO undo after testing - // ?: Destination.Home(), - ?: Destination.HomeSettings, + ?: Destination.Home(), navigationManager = navigationManager, preferences = preferences, modifier = Modifier.fillMaxSize(), diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index 4e82ba0a9e..6cc0a197bd 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -199,29 +199,33 @@ class HomeSettingsService // User local then server/remote otherwise create a default val settings = try { - loadFromLocal(userId) + val local = loadFromLocal(userId) + Timber.v("Found local? %s", local != null) + local } catch (ex: Exception) { Timber.w(ex, "Error loading local settings") // TODO show toast? null } ?: try { - loadFromServer(userId) + val remote = loadFromServer(userId) + Timber.v("Found remote? %s", remote != null) + remote } catch (ex: Exception) { Timber.w(ex, "Error loading remote settings") null } - val resolvedSettings = parseFromWebConfig(userId)!! - if (settings != null) { - Timber.v("Found settings") - // Resolve - val resolvedRows = - settings.rows.mapIndexed { index, config -> - resolve(index, config) - } - HomePageResolvedSettings(resolvedRows) - } else { - createDefault(userId) - } + val resolvedSettings = + if (settings != null) { + Timber.v("Found settings") + // Resolve + val resolvedRows = + settings.rows.mapIndexed { index, config -> + resolve(index, config) + } + HomePageResolvedSettings(resolvedRows) + } else { + createDefault(userId) + } currentSettings.update { resolvedSettings } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 0e3e2c7e9f..e2fc85f209 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -47,6 +47,7 @@ import org.jellyfin.sdk.model.serializer.UUIDSerializer import timber.log.Timber import java.util.UUID import javax.inject.Inject +import kotlin.properties.Delegates @HiltViewModel class HomeSettingsViewModel @@ -64,6 +65,8 @@ class HomeSettingsViewModel private val _state = MutableStateFlow(HomePageSettingsState.EMPTY) val state: StateFlow = _state + private var idCounter by Delegates.notNull() + val discoverEnabled = seerrServerRepository.active init { @@ -82,6 +85,7 @@ class HomeSettingsViewModel val currentSettings = homeSettingsService.currentSettings.first { it != HomePageResolvedSettings.EMPTY } Timber.v("currentSettings=%s", currentSettings) + idCounter = currentSettings.rows.maxOfOrNull { it.id }?.plus(1) ?: 0 _state.update { it.copy( libraries = libraries, @@ -190,7 +194,7 @@ class HomeSettingsViewModel fun addRow(type: MetaRowType): Job = viewModelScope.launchIO { - val id = state.value.rows.size + val id = idCounter++ val newRow = when (type) { MetaRowType.CONTINUE_WATCHING -> { @@ -239,7 +243,7 @@ class HomeSettingsViewModel rowType: LibraryRowType, ): Job = viewModelScope.launchIO { - val id = state.value.rows.size + val id = idCounter++ val newRow = when (rowType) { LibraryRowType.RECENTLY_ADDED -> { @@ -288,7 +292,7 @@ class HomeSettingsViewModel fun addFavoriteRow(type: BaseItemKind): Job = viewModelScope.launchIO { Timber.v("Adding favorite row for $type") - val id = state.value.rows.size + val id = idCounter++ val newRow = HomeRowConfigDisplay( id = id, From f786ec647e572fba0408b4934899145ce0efd38c Mon Sep 17 00:00:00 2001 From: Damontecres Date: Fri, 30 Jan 2026 18:07:09 -0500 Subject: [PATCH 39/53] Fix tests --- .../github/damontecres/wholphin/test/TestHomeRowSamples.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt b/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt index ab4d170ac5..798eaf309f 100644 --- a/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt +++ b/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt @@ -71,6 +71,9 @@ class TestHomeRowSamples { ), viewOptions = HomeRowViewOptions(), ), + HomeRowConfig.Favorite(kind = BaseItemKind.SERIES), + HomeRowConfig.Recordings(), + HomeRowConfig.TvPrograms(), ) } @@ -88,6 +91,9 @@ class TestHomeRowSamples { is HomeRowConfig.RecentlyReleased -> foundTypes.add(it::class) is HomeRowConfig.ByParent -> foundTypes.add(it::class) is HomeRowConfig.GetItems -> foundTypes.add(it::class) + is HomeRowConfig.Favorite -> foundTypes.add(it::class) + is HomeRowConfig.Recordings -> foundTypes.add(it::class) + is HomeRowConfig.TvPrograms -> foundTypes.add(it::class) } } Assert.assertEquals(HomeRowConfig::class.sealedSubclasses.size, foundTypes.size) From 9a86e854e9ca5a719439bc3ca7312dc45a41d572 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Sun, 1 Feb 2026 17:33:46 -0500 Subject: [PATCH 40/53] Better support for using thumbnails --- .../wholphin/data/model/HomeRowConfig.kt | 3 + .../wholphin/preferences/AppPreference.kt | 2 - .../damontecres/wholphin/ui/main/HomePage.kt | 30 ++- .../ui/main/settings/HomeRowSettings.kt | 171 +++++++++++++----- .../ui/main/settings/HomeSettingsPage.kt | 14 +- .../ui/preferences/PreferenceUtils.kt | 5 +- .../ui/preferences/PreferencesContent.kt | 4 - app/src/main/res/values/strings.xml | 1 + 8 files changed, 174 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index 36c2838807..03c662b7c1 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -199,4 +199,7 @@ data class HomeRowViewOptions( val imageType: ViewOptionImageType = ViewOptionImageType.PRIMARY, val showTitles: Boolean = false, val useSeries: Boolean = true, + val episodeContentScale: PrefContentScale = PrefContentScale.FIT, + val episodeAspectRatio: AspectRatio = AspectRatio.TALL, + val episodeImageType: ViewOptionImageType = ViewOptionImageType.PRIMARY, ) diff --git a/app/src/main/java/com/github/damontecres/wholphin/preferences/AppPreference.kt b/app/src/main/java/com/github/damontecres/wholphin/preferences/AppPreference.kt index cc56141182..28903af39e 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/preferences/AppPreference.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/preferences/AppPreference.kt @@ -976,8 +976,6 @@ val basicPreferences = ), ) -val uiPreferences = listOf() - private val ExoPlayerSettings = listOf( AppPreference.FfmpegPreference, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt index db7f8eb88e..d3d1a639bf 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt @@ -371,12 +371,36 @@ fun HomePageContent( } else -> { + val imageType = + remember(item, viewOptions) { + if (item?.type == BaseItemKind.EPISODE) { + viewOptions.episodeImageType.imageType + } else { + viewOptions.imageType.imageType + } + } + val ratio = + remember(item, viewOptions) { + if (item?.type == BaseItemKind.EPISODE) { + viewOptions.episodeAspectRatio.ratio + } else { + viewOptions.aspectRatio.ratio + } + } + val scale = + remember(item, viewOptions) { + if (item?.type == BaseItemKind.EPISODE) { + viewOptions.episodeContentScale.scale + } else { + viewOptions.contentScale.scale + } + } BannerCard( name = item?.data?.seriesName ?: item?.name, item = item, - aspectRatio = viewOptions.aspectRatio.ratio, - imageType = viewOptions.imageType.imageType, - imageContentScale = viewOptions.contentScale.scale, + aspectRatio = ratio, + imageType = imageType, + imageContentScale = scale, cornerText = item?.ui?.episdodeUnplayedCornerText, played = item?.data?.userData?.played ?: false, favorite = item?.favorite ?: false, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt index adcb312447..68f65d1abb 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt @@ -11,6 +11,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.tv.material3.MaterialTheme import androidx.tv.material3.surfaceColorAtElevation @@ -25,54 +26,60 @@ import com.github.damontecres.wholphin.preferences.PrefContentScale import com.github.damontecres.wholphin.ui.AspectRatio import com.github.damontecres.wholphin.ui.Cards import com.github.damontecres.wholphin.ui.components.ViewOptionImageType -import com.github.damontecres.wholphin.ui.components.ViewOptions import com.github.damontecres.wholphin.ui.ifElse import com.github.damontecres.wholphin.ui.preferences.ComposablePreference +import com.github.damontecres.wholphin.ui.preferences.PreferenceGroup import com.github.damontecres.wholphin.ui.tryRequestFocus @Composable fun HomeRowSettings( title: String, + preferenceOptions: List>, viewOptions: HomeRowViewOptions, onViewOptionsChange: (HomeRowViewOptions) -> Unit, onApplyApplyAll: () -> Unit, - userGenreSettings: Boolean, modifier: Modifier = Modifier, defaultViewOptions: HomeRowViewOptions = HomeRowViewOptions(), ) { - val options = if (userGenreSettings) Options.GENRE_OPTIONS else Options.OPTIONS val firstFocus = remember { FocusRequester() } LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } Column(modifier = modifier) { TitleText(title) LazyColumn { - itemsIndexed(options) { index, pref -> - pref as AppPreference - val interactionSource = remember { MutableInteractionSource() } - val value = pref.getter.invoke(viewOptions) - ComposablePreference( - preference = pref, - value = value, - onNavigate = {}, - onValueChange = { newValue -> - onViewOptionsChange.invoke(pref.setter(viewOptions, newValue)) - }, - interactionSource = interactionSource, - onClickPreference = { pref -> - if (pref == Options.ViewOptionsReset) { - onViewOptionsChange.invoke(defaultViewOptions) - } else if (pref == Options.ViewOptionsApplyAll) { - onApplyApplyAll.invoke() - } - }, - modifier = - Modifier - .background( - MaterialTheme.colorScheme.surfaceColorAtElevation( - 5.dp, - ), - ).ifElse(index == 0, Modifier.focusRequester(firstFocus)), - ) + preferenceOptions.forEachIndexed { groupIndex, prefGroup -> + if (preferenceOptions.size > 1) { + item { + TitleText(stringResource(prefGroup.title)) + } + } + itemsIndexed(prefGroup.preferences) { index, pref -> + pref as AppPreference + val interactionSource = remember { MutableInteractionSource() } + val value = pref.getter.invoke(viewOptions) + ComposablePreference( + preference = pref, + value = value, + onNavigate = {}, + onValueChange = { newValue -> + onViewOptionsChange.invoke(pref.setter(viewOptions, newValue)) + }, + interactionSource = interactionSource, + onClickPreference = { pref -> + if (pref == Options.ViewOptionsReset) { + onViewOptionsChange.invoke(defaultViewOptions) + } else if (pref == Options.ViewOptionsApplyAll) { + onApplyApplyAll.invoke() + } + }, + modifier = + Modifier + .background( + MaterialTheme.colorScheme.surfaceColorAtElevation( + 5.dp, + ), + ).ifElse(index == 0, Modifier.focusRequester(firstFocus)), + ) + } } } } @@ -157,33 +164,111 @@ internal object Options { ) val ViewOptionsApplyAll = - AppClickablePreference( + AppClickablePreference( title = R.string.apply_all_rows, ) val ViewOptionsReset = - AppClickablePreference( + AppClickablePreference( title = R.string.reset, ) + val ViewOptionsEpisodeContentScale = + AppChoicePreference( + title = R.string.global_content_scale, + defaultValue = PrefContentScale.FIT, + displayValues = R.array.content_scale, + getter = { it.contentScale }, + setter = { viewOptions, value -> viewOptions.copy(episodeContentScale = value) }, + indexToValue = { PrefContentScale.forNumber(it) }, + valueToIndex = { it.number }, + ) + + val ViewOptionsEpisodeAspectRatio = + AppChoicePreference( + title = R.string.aspect_ratio, + defaultValue = AspectRatio.TALL, + displayValues = R.array.aspect_ratios, + getter = { it.aspectRatio }, + setter = { viewOptions, value -> viewOptions.copy(episodeAspectRatio = value) }, + indexToValue = { AspectRatio.entries[it] }, + valueToIndex = { it.ordinal }, + ) + + val ViewOptionsEpisodeImageType = + AppChoicePreference( + title = R.string.image_type, + defaultValue = ViewOptionImageType.PRIMARY, + displayValues = R.array.image_types, + getter = { it.imageType }, + setter = { viewOptions, value -> + val aspectRatio = + when (value) { + ViewOptionImageType.PRIMARY -> AspectRatio.TALL + ViewOptionImageType.THUMB -> AspectRatio.WIDE + } + viewOptions.copy(episodeImageType = value, episodeAspectRatio = aspectRatio) + }, + indexToValue = { ViewOptionImageType.entries[it] }, + valueToIndex = { it.ordinal }, + ) + val OPTIONS = listOf( - ViewOptionsImageType, - ViewOptionsAspectRatio, - // TODO + PreferenceGroup( + title = R.string.general, + preferences = + listOf( + ViewOptionsImageType, + ViewOptionsAspectRatio, + // TODO // ViewOptionsShowTitles, - ViewOptionsUseSeries, - ViewOptionsCardHeight, - ViewOptionsSpacing, - ViewOptionsContentScale, + ViewOptionsUseSeries, + ViewOptionsCardHeight, + ViewOptionsSpacing, + ViewOptionsContentScale, // ViewOptionsApplyAll, - ViewOptionsReset, + ViewOptionsReset, + ), + ), + ) + + val OPTIONS_EPISODES = + listOf( + PreferenceGroup( + title = R.string.general, + preferences = + listOf( + ViewOptionsCardHeight, + ViewOptionsSpacing, + ViewOptionsImageType, + ViewOptionsAspectRatio, + ViewOptionsUseSeries, + ViewOptionsContentScale, + ViewOptionsReset, + ), + ), + PreferenceGroup( + title = R.string.for_episodes, + preferences = + listOf( + ViewOptionsEpisodeImageType, + ViewOptionsEpisodeContentScale, + ViewOptionsEpisodeAspectRatio, + ), + ), ) val GENRE_OPTIONS = listOf( - ViewOptionsCardHeight, - ViewOptionsSpacing, - ViewOptionsReset, + PreferenceGroup( + title = R.string.general, + preferences = + listOf( + ViewOptionsCardHeight, + ViewOptionsSpacing, + ViewOptionsReset, + ), + ), ) } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index 9b5b6c8103..b34cb4a8d0 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -151,8 +151,21 @@ fun HomeSettingsPage( val row = state.rows .first { it.id == dest.rowId } + val preferenceOptions = + remember(row.config) { + when (row.config) { + is HomeRowConfig.ContinueWatching, + is HomeRowConfig.ContinueWatchingCombined, + -> Options.OPTIONS_EPISODES + + is HomeRowConfig.Genres -> Options.GENRE_OPTIONS + + else -> Options.OPTIONS + } + } HomeRowSettings( title = row.title, + preferenceOptions = preferenceOptions, viewOptions = row.config.viewOptions, onViewOptionsChange = { viewModel.updateViewOptions(dest.rowId, it) @@ -160,7 +173,6 @@ fun HomeSettingsPage( onApplyApplyAll = { viewModel.updateViewOptionsForAll(row.config.viewOptions) }, - userGenreSettings = row.config is HomeRowConfig.Genres, modifier = destModifier, ) } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/preferences/PreferenceUtils.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/preferences/PreferenceUtils.kt index f84d3b89b5..091dd4755d 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/preferences/PreferenceUtils.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/preferences/PreferenceUtils.kt @@ -8,9 +8,9 @@ import kotlinx.serialization.Serializable /** * A group of preferences */ -data class PreferenceGroup( +data class PreferenceGroup( @param:StringRes val title: Int, - val preferences: List>, + val preferences: List>, val conditionalPreferences: List = listOf(), ) @@ -34,7 +34,6 @@ sealed interface PreferenceValidation { enum class PreferenceScreenOption { BASIC, ADVANCED, - USER_INTERFACE, SUBTITLES, EXO_PLAYER, MPV, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/preferences/PreferencesContent.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/preferences/PreferencesContent.kt index 8fedf3b6b1..63c5a9b1d1 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/preferences/PreferencesContent.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/preferences/PreferencesContent.kt @@ -50,7 +50,6 @@ import com.github.damontecres.wholphin.preferences.MpvPreferences import com.github.damontecres.wholphin.preferences.PlayerBackend import com.github.damontecres.wholphin.preferences.advancedPreferences import com.github.damontecres.wholphin.preferences.basicPreferences -import com.github.damontecres.wholphin.preferences.uiPreferences import com.github.damontecres.wholphin.preferences.updatePlaybackPreferences import com.github.damontecres.wholphin.services.UpdateChecker import com.github.damontecres.wholphin.ui.components.ConfirmDialog @@ -125,7 +124,6 @@ fun PreferencesContent( when (preferenceScreenOption) { PreferenceScreenOption.BASIC -> basicPreferences PreferenceScreenOption.ADVANCED -> advancedPreferences - PreferenceScreenOption.USER_INTERFACE -> uiPreferences PreferenceScreenOption.SUBTITLES -> SubtitleSettings.preferences PreferenceScreenOption.EXO_PLAYER -> ExoPlayerPreferences PreferenceScreenOption.MPV -> MpvPreferences @@ -134,7 +132,6 @@ fun PreferencesContent( when (preferenceScreenOption) { PreferenceScreenOption.BASIC -> R.string.settings PreferenceScreenOption.ADVANCED -> R.string.advanced_settings - PreferenceScreenOption.USER_INTERFACE -> R.string.ui_interface PreferenceScreenOption.SUBTITLES -> R.string.subtitle_style PreferenceScreenOption.EXO_PLAYER -> R.string.exoplayer_options PreferenceScreenOption.MPV -> R.string.mpv_options @@ -526,7 +523,6 @@ fun PreferencesPage( when (preferenceScreenOption) { PreferenceScreenOption.BASIC, PreferenceScreenOption.ADVANCED, - PreferenceScreenOption.USER_INTERFACE, PreferenceScreenOption.EXO_PLAYER, PreferenceScreenOption.MPV, -> { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8b80a127e6..e2b050c8ba 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -476,6 +476,7 @@ Add row for %1$s Overwrite settings on server? Overwrite local settings? + For episodes Disabled From b31c0044fc6c956c390a566bd9fd03ec49ae5052 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Wed, 4 Feb 2026 21:16:24 -0500 Subject: [PATCH 41/53] Add option for suggestions row for supported library types --- .../wholphin/data/model/HomeRowConfig.kt | 12 +++++ .../wholphin/services/HomeSettingsService.kt | 47 +++++++++++++++++++ .../wholphin/services/SuggestionsWorker.kt | 14 ++++-- .../main/settings/HomeLibraryRowTypeList.kt | 14 +++++- .../ui/main/settings/HomeSettingsViewModel.kt | 20 ++++++-- app/src/main/res/values/strings.xml | 1 + 6 files changed, 99 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index 03c662b7c1..b195c28dcc 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -136,6 +136,18 @@ sealed interface HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): TvPrograms = this.copy(viewOptions = viewOptions) } + /** + * Fetch suggestions from [com.github.damontecres.wholphin.services.SuggestionService] for the given parent ID + */ + @Serializable + @SerialName("Suggestions") + data class Suggestions( + val parentId: UUID, + override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(), + ) : HomeRowConfig { + override fun updateViewOptions(viewOptions: HomeRowViewOptions): Suggestions = this.copy(viewOptions = viewOptions) + } + /** * Fetch by parent ID such as a library, collection, or playlist with optional simple sorting */ diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index 6cc0a197bd..24951110db 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -23,6 +23,7 @@ import com.github.damontecres.wholphin.util.supportedHomeCollectionTypes import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.update import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.Json @@ -64,6 +65,7 @@ class HomeSettingsService private val navDrawerItemRepository: NavDrawerItemRepository, private val latestNextUpService: LatestNextUpService, private val imageUrlService: ImageUrlService, + private val suggestionService: SuggestionService, ) { @OptIn(ExperimentalSerializationApi::class) val jsonParser = @@ -504,6 +506,18 @@ class HomeSettingsService config, ) } + + is HomeRowConfig.Suggestions -> { + val name = + api.userLibraryApi + .getItem(itemId = config.parentId) + .content.name ?: "" + HomeRowConfigDisplay( + id = id, + title = context.getString(R.string.suggestions_for, name), + config, + ) + } } /** @@ -829,6 +843,39 @@ class HomeSettingsService ) } } + + is HomeRowConfig.Suggestions -> { + val library = + api.userLibraryApi + .getItem(itemId = row.parentId) + .content + val title = context.getString(R.string.suggestions_for, library.name ?: "") + val itemKind = SuggestionsWorker.getTypeForCollection(library.collectionType) + val suggestions = + itemKind?.let { + suggestionService + .getSuggestionsFlow(row.parentId, itemKind) + .firstOrNull() + } + if (suggestions != null && suggestions is SuggestionsResource.Success) { + Success( + title, + suggestions.items, + row.viewOptions, + ) + } else if (suggestions is SuggestionsResource.Empty) { + Success( + title, + listOf(), + row.viewOptions, + ) + } else { + HomeRowLoadingState.Error( + title, + message = "Unsupported type ${library.collectionType}", + ) + } + } } companion object { diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/SuggestionsWorker.kt b/app/src/main/java/com/github/damontecres/wholphin/services/SuggestionsWorker.kt index 70943f8378..5222929e84 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/SuggestionsWorker.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/SuggestionsWorker.kt @@ -82,11 +82,8 @@ class SuggestionsWorker views .mapNotNull { view -> val itemKind = - when (view.collectionType) { - CollectionType.MOVIES -> BaseItemKind.MOVIE - CollectionType.TVSHOWS -> BaseItemKind.SERIES - else -> return@mapNotNull null - } + getTypeForCollection(view.collectionType) + ?: return@mapNotNull null async(Dispatchers.IO) { runCatching { Timber.v("Fetching suggestions for view %s", view.id) @@ -226,5 +223,12 @@ class SuggestionsWorker const val PARAM_USER_ID = "userId" const val PARAM_SERVER_ID = "serverId" private const val FRESH_CONTENT_RATIO = 0.4 + + fun getTypeForCollection(collectionType: CollectionType?): BaseItemKind? = + when (collectionType) { + CollectionType.MOVIES -> BaseItemKind.MOVIE + CollectionType.TVSHOWS -> BaseItemKind.SERIES + else -> null + } } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeLibraryRowTypeList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeLibraryRowTypeList.kt index ea4ba9e214..c680e07776 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeLibraryRowTypeList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeLibraryRowTypeList.kt @@ -20,6 +20,7 @@ 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.services.SuggestionsWorker import com.github.damontecres.wholphin.ui.ifElse import com.github.damontecres.wholphin.ui.tryRequestFocus @@ -30,6 +31,7 @@ fun HomeLibraryRowTypeList( modifier: Modifier, firstFocus: FocusRequester = remember { FocusRequester() }, ) { + val items = remember(library) { getSupportedRowTypes(library) } LaunchedEffect(Unit) { firstFocus.tryRequestFocus() } Column(modifier = modifier) { TitleText(stringResource(R.string.add_row_for, library.name)) @@ -41,7 +43,7 @@ fun HomeLibraryRowTypeList( .fillMaxHeight() .focusRestorer(firstFocus), ) { - itemsIndexed(LibraryRowType.entries) { index, rowType -> + itemsIndexed(items) { index, rowType -> ListItem( selected = false, headlineContent = { @@ -60,10 +62,20 @@ fun HomeLibraryRowTypeList( } } +fun getSupportedRowTypes(library: Library): List { + val itemKind = SuggestionsWorker.getTypeForCollection(library.collectionType) + return if (itemKind != null) { + LibraryRowType.entries + } else { + LibraryRowType.entries.toMutableList().apply { remove(LibraryRowType.SUGGESTIONS) } + } +} + enum class LibraryRowType( @param:StringRes val stringId: Int, ) { RECENTLY_ADDED(R.string.recently_added), RECENTLY_RELEASED(R.string.recently_released), + SUGGESTIONS(R.string.suggestions), GENRES(R.string.genres), } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index e2fc85f209..6ebbbf446f 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -13,7 +13,11 @@ import com.github.damontecres.wholphin.data.model.HomePageSettings import com.github.damontecres.wholphin.data.model.HomeRowConfig import com.github.damontecres.wholphin.data.model.HomeRowConfig.ContinueWatching import com.github.damontecres.wholphin.data.model.HomeRowConfig.ContinueWatchingCombined +import com.github.damontecres.wholphin.data.model.HomeRowConfig.Genres import com.github.damontecres.wholphin.data.model.HomeRowConfig.NextUp +import com.github.damontecres.wholphin.data.model.HomeRowConfig.RecentlyAdded +import com.github.damontecres.wholphin.data.model.HomeRowConfig.RecentlyReleased +import com.github.damontecres.wholphin.data.model.HomeRowConfig.Suggestions import com.github.damontecres.wholphin.data.model.HomeRowViewOptions import com.github.damontecres.wholphin.services.BackdropService import com.github.damontecres.wholphin.services.HomePageResolvedSettings @@ -252,7 +256,7 @@ class HomeSettingsViewModel HomeRowConfigDisplay( id = id, title = title, - config = HomeRowConfig.RecentlyAdded(library.itemId), + config = RecentlyAdded(library.itemId), ) } @@ -267,7 +271,7 @@ class HomeSettingsViewModel HomeRowConfigDisplay( id = id, title = title, - config = HomeRowConfig.RecentlyReleased(library.itemId), + config = RecentlyReleased(library.itemId), ) } @@ -276,7 +280,17 @@ class HomeSettingsViewModel HomeRowConfigDisplay( id = id, title = title, - config = HomeRowConfig.Genres(library.itemId), + config = Genres(library.itemId), + ) + } + + LibraryRowType.SUGGESTIONS -> { + val title = + library.name.let { context.getString(R.string.suggestions_for, it) } + HomeRowConfigDisplay( + id = id, + title = title, + config = Suggestions(library.itemId), ) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fd5ceed1e9..f4509878f2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -500,6 +500,7 @@ Overwrite settings on server? Overwrite local settings? For episodes + Suggestions for %1$s Disabled From a8352e7c0d1542fc4c6af0dc480d3b5e9c7e265a Mon Sep 17 00:00:00 2001 From: Damontecres Date: Wed, 4 Feb 2026 21:52:47 -0500 Subject: [PATCH 42/53] Match style to regular preferences --- .../ui/main/settings/HomeRowSettings.kt | 25 ++++++------ .../ui/main/settings/HomeSettingsAddRow.kt | 17 ++------ .../main/settings/HomeSettingsFavoriteList.kt | 7 +--- .../ui/main/settings/HomeSettingsGlobal.kt | 30 +++----------- .../ui/main/settings/HomeSettingsListItem.kt | 7 +++- .../ui/main/settings/HomeSettingsPage.kt | 4 +- .../ui/main/settings/HomeSettingsRowList.kt | 39 +++++++------------ app/src/main/res/values/strings.xml | 2 + 8 files changed, 47 insertions(+), 84 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt index 68f65d1abb..5817e7cc8e 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt @@ -1,6 +1,5 @@ package com.github.damontecres.wholphin.ui.main.settings -import androidx.compose.foundation.background import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Column import androidx.compose.foundation.lazy.LazyColumn @@ -12,9 +11,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.res.stringResource -import androidx.compose.ui.unit.dp -import androidx.tv.material3.MaterialTheme -import androidx.tv.material3.surfaceColorAtElevation import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.model.HomeRowViewOptions import com.github.damontecres.wholphin.preferences.AppChoicePreference @@ -73,11 +69,10 @@ fun HomeRowSettings( }, modifier = Modifier - .background( - MaterialTheme.colorScheme.surfaceColorAtElevation( - 5.dp, - ), - ).ifElse(index == 0, Modifier.focusRequester(firstFocus)), + .ifElse( + groupIndex == 0 && index == 0, + Modifier.focusRequester(firstFocus), + ), ) } } @@ -243,18 +238,24 @@ internal object Options { ViewOptionsSpacing, ViewOptionsImageType, ViewOptionsAspectRatio, - ViewOptionsUseSeries, ViewOptionsContentScale, - ViewOptionsReset, ), ), PreferenceGroup( title = R.string.for_episodes, preferences = listOf( + ViewOptionsUseSeries, ViewOptionsEpisodeImageType, - ViewOptionsEpisodeContentScale, ViewOptionsEpisodeAspectRatio, + ViewOptionsEpisodeContentScale, + ), + ), + PreferenceGroup( + title = R.string.more, + preferences = + listOf( + ViewOptionsReset, ), ), ) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt index 09f14bfc0b..ab48de3080 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsAddRow.kt @@ -16,7 +16,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.Text import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.ui.ifElse @@ -49,9 +48,7 @@ fun HomeSettingsAddRow( ) { index, type -> HomeSettingsListItem( selected = false, - headlineContent = { - Text(stringResource(type.stringId)) - }, + headlineText = stringResource(type.stringId), onClick = { onClickMeta.invoke(type) }, modifier = Modifier.ifElse(index == 0, Modifier.focusRequester(firstFocus)), ) @@ -63,9 +60,7 @@ fun HomeSettingsAddRow( itemsIndexed(libraries) { index, library -> HomeSettingsListItem( selected = false, - headlineContent = { - Text(library.name) - }, + headlineText = library.name, onClick = { onClick.invoke(library) }, modifier = Modifier, // .ifElse(index == 0, Modifier.focusRequester(firstFocus)), ) @@ -77,9 +72,7 @@ fun HomeSettingsAddRow( item { HomeSettingsListItem( selected = false, - headlineContent = { - Text(stringResource(MetaRowType.FAVORITES.stringId)) - }, + headlineText = stringResource(MetaRowType.FAVORITES.stringId), onClick = { onClickMeta.invoke(MetaRowType.FAVORITES) }, modifier = Modifier, ) @@ -88,9 +81,7 @@ fun HomeSettingsAddRow( item { HomeSettingsListItem( selected = false, - headlineContent = { - Text(stringResource(MetaRowType.DISCOVER.stringId)) - }, + headlineText = stringResource(MetaRowType.DISCOVER.stringId), onClick = { onClickMeta.invoke(MetaRowType.DISCOVER) }, modifier = Modifier, ) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt index 3dbea06494..3bac590af4 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsFavoriteList.kt @@ -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.Text import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.ui.ifElse import com.github.damontecres.wholphin.ui.tryRequestFocus @@ -43,11 +42,7 @@ fun HomeSettingsFavoriteList( itemsIndexed(favoriteOptionsList) { index, type -> HomeSettingsListItem( selected = false, - headlineContent = { - Text( - text = stringResource(favoriteOptions[type]!!), - ) - }, + headlineText = stringResource(favoriteOptions[type]!!), onClick = { onClick.invoke(type) }, modifier = Modifier.ifElse(index == 0, Modifier.focusRequester(firstFocus)), ) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt index f9a5777713..9e711b9f2d 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt @@ -54,11 +54,7 @@ fun HomeSettingsGlobal( item { HomeSettingsListItem( selected = false, - headlineContent = { - Text( - text = "Increase all card size", - ) - }, + headlineText = stringResource(R.string.increase_all_cards_size), leadingContent = { Icon( imageVector = Icons.Default.KeyboardArrowUp, @@ -72,11 +68,7 @@ fun HomeSettingsGlobal( item { HomeSettingsListItem( selected = false, - headlineContent = { - Text( - text = "Decrease all card size", - ) - }, + headlineText = stringResource(R.string.decrease_all_cards_size), leadingContent = { Icon( imageVector = Icons.Default.KeyboardArrowDown, @@ -91,11 +83,7 @@ fun HomeSettingsGlobal( item { HomeSettingsListItem( selected = false, - headlineContent = { - Text( - text = stringResource(R.string.save_to_server), - ) - }, + headlineText = stringResource(R.string.save_to_server), leadingContent = { Text( text = stringResource(R.string.fa_cloud_arrow_up), @@ -109,11 +97,7 @@ fun HomeSettingsGlobal( item { HomeSettingsListItem( selected = false, - headlineContent = { - Text( - text = stringResource(R.string.load_from_server), - ) - }, + headlineText = stringResource(R.string.load_from_server), leadingContent = { Text( text = stringResource(R.string.fa_cloud_arrow_down), @@ -127,11 +111,7 @@ fun HomeSettingsGlobal( item { HomeSettingsListItem( selected = false, - headlineContent = { - Text( - text = stringResource(R.string.load_from_web_client), - ) - }, + headlineText = stringResource(R.string.load_from_web_client), leadingContent = { Text( text = stringResource(R.string.fa_download), diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsListItem.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsListItem.kt index c9ea14d6a8..4f265dbba3 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsListItem.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsListItem.kt @@ -14,13 +14,14 @@ import androidx.tv.material3.ListItemDefaults import androidx.tv.material3.ListItemGlow import androidx.tv.material3.ListItemScale import androidx.tv.material3.ListItemShape +import com.github.damontecres.wholphin.ui.preferences.PreferenceTitle @Composable @NonRestartableComposable fun HomeSettingsListItem( selected: Boolean, onClick: () -> Unit, - headlineContent: @Composable () -> Unit, + headlineText: String, modifier: Modifier = Modifier, enabled: Boolean = true, onLongClick: (() -> Unit)? = null, @@ -38,7 +39,9 @@ fun HomeSettingsListItem( ) = ListItem( selected = selected, onClick = onClick, - headlineContent = headlineContent, + headlineContent = { + PreferenceTitle(headlineText) + }, modifier = modifier, enabled = enabled, onLongClick = onLongClick, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index b34cb4a8d0..10808d8157 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -39,7 +39,7 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.launch import timber.log.Timber -val settingsWidth = 300.dp +val settingsWidth = 360.dp @Composable fun HomeSettingsPage( @@ -90,7 +90,7 @@ fun HomeSettingsPage( val destModifier = Modifier .fillMaxSize() - .padding(4.dp) + .padding(8.dp) when (dest) { HomeSettingsDestination.RowList -> { HomeSettingsRowList( diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt index f0fc666159..54a4f60508 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed @@ -32,7 +33,6 @@ import androidx.compose.ui.focus.focusRestorer import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.tv.material3.Icon import androidx.tv.material3.MaterialTheme @@ -59,7 +59,6 @@ fun HomeSettingsRowList( onClickMove: (MoveDirection, Int) -> Unit, onClickDelete: (Int) -> Unit, modifier: Modifier, - firstFocus: FocusRequester = remember { FocusRequester() }, ) { val focusManager = LocalFocusManager.current val scope = rememberCoroutineScope() @@ -71,7 +70,9 @@ fun HomeSettingsRowList( var position by rememberInt(0) - LaunchedEffect(Unit) { focusRequesters.getOrNull(position)?.tryRequestFocus() } + LaunchedEffect(Unit) { + focusRequesters.getOrNull(position)?.tryRequestFocus() + } Column(modifier = modifier) { TitleText(stringResource(R.string.customize_home)) LazyColumn( @@ -80,16 +81,12 @@ fun HomeSettingsRowList( modifier = modifier .fillMaxHeight() - .focusRestorer(firstFocus), + .focusRestorer(focusRequesters[0]), ) { item { HomeSettingsListItem( selected = false, - headlineContent = { - Text( - text = stringResource(R.string.add_row), - ) - }, + headlineText = stringResource(R.string.add_row), leadingContent = { Icon( imageVector = Icons.Default.Add, @@ -106,11 +103,7 @@ fun HomeSettingsRowList( item { HomeSettingsListItem( selected = false, - headlineContent = { - Text( - text = stringResource(R.string.settings), - ) - }, + headlineText = stringResource(R.string.settings), leadingContent = { Icon( imageVector = Icons.Default.Settings, @@ -193,13 +186,7 @@ fun HomeRowConfigContent( ) { HomeSettingsListItem( selected = false, - headlineContent = { - Text( - text = config.title, - overflow = TextOverflow.Ellipsis, - modifier = Modifier, - ) - }, + headlineText = config.title, onClick = onClick, modifier = Modifier.weight(1f), ) @@ -248,8 +235,12 @@ fun TitleText( ) { Text( text = title, - style = MaterialTheme.typography.titleLarge, - textAlign = TextAlign.Center, - modifier = modifier.fillMaxWidth(), + style = MaterialTheme.typography.titleMedium, + color = MaterialTheme.colorScheme.onSurface, + textAlign = TextAlign.Start, + modifier = + modifier + .fillMaxWidth() + .padding(top = 8.dp, bottom = 4.dp), ) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f4509878f2..08142f529c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -501,6 +501,8 @@ Overwrite local settings? For episodes Suggestions for %1$s + Increase all cards size + Decrease all cards size Disabled From 3f4ec245697907d911863d58f9c1eeef0a2b2bac Mon Sep 17 00:00:00 2001 From: Damontecres Date: Wed, 4 Feb 2026 22:31:17 -0500 Subject: [PATCH 43/53] Fix tests --- .../com/github/damontecres/wholphin/test/TestHomeRowSamples.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt b/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt index 798eaf309f..3aedb3ba95 100644 --- a/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt +++ b/app/src/test/java/com/github/damontecres/wholphin/test/TestHomeRowSamples.kt @@ -74,6 +74,7 @@ class TestHomeRowSamples { HomeRowConfig.Favorite(kind = BaseItemKind.SERIES), HomeRowConfig.Recordings(), HomeRowConfig.TvPrograms(), + HomeRowConfig.Suggestions(parentId = UUID.randomUUID()), ) } @@ -94,6 +95,7 @@ class TestHomeRowSamples { is HomeRowConfig.Favorite -> foundTypes.add(it::class) is HomeRowConfig.Recordings -> foundTypes.add(it::class) is HomeRowConfig.TvPrograms -> foundTypes.add(it::class) + is HomeRowConfig.Suggestions -> foundTypes.add(it::class) } } Assert.assertEquals(HomeRowConfig::class.sealedSubclasses.size, foundTypes.size) @@ -123,6 +125,7 @@ class TestHomeRowSamples { navDrawerItemRepository = mockk(), latestNextUpService = mockk(), imageUrlService = mockk(), + suggestionService = mockk(), ) val str = """{ From 70ad1ecdbfb9a131acf26641144a60031f617fe9 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 5 Feb 2026 12:15:29 -0500 Subject: [PATCH 44/53] Refresh watching rows first --- .../wholphin/ui/main/HomeViewModel.kt | 84 +++++++++++-------- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt index f51db306b9..efaeb087c0 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomeViewModel.kt @@ -6,6 +6,7 @@ import androidx.lifecycle.viewModelScope import com.github.damontecres.wholphin.data.NavDrawerItemRepository import com.github.damontecres.wholphin.data.ServerRepository import com.github.damontecres.wholphin.data.model.BaseItem +import com.github.damontecres.wholphin.data.model.HomeRowConfig import com.github.damontecres.wholphin.services.BackdropService import com.github.damontecres.wholphin.services.DatePlayedService import com.github.damontecres.wholphin.services.FavoriteWatchManager @@ -56,7 +57,7 @@ class HomeViewModel init { datePlayedService.invalidateAll() - init() +// init() } fun init() { @@ -86,45 +87,54 @@ class HomeViewModel state.loadingState == LoadingState.Success && state.settings == settings val semaphore = Semaphore(4) - val loadingRows = - if (refresh) { - state.homeRows - } else { - mutableListOf() - } - val deferred = - settings.rows.mapIndexed { index, row -> - if (refresh) { - (loadingRows as MutableList).add(HomeRowLoadingState.Loading(row.title)) - } - viewModelScope.async(Dispatchers.IO) { - semaphore.withPermit { - Timber.v("Fetching row: %s", row) - try { - homeSettingsService.fetchDataForRow( - row = row.config, - scope = viewModelScope, - prefs = prefs, - userDto = userDto, - libraries = libraries, - limit = prefs.maxItemsPerRow, - ) - } catch (ex: Exception) { - Timber.e(ex, "Error on row %s", row) - HomeRowLoadingState.Error(row.title, exception = ex) + val watchingRowIndexes = + settings.rows + .mapIndexedNotNull { index, row -> + if (isWatchingRow(row.config)) index else null + } + val deferred = + settings.rows + // Load the watching rows first + .sortedByDescending { isWatchingRow(it.config) } + .map { row -> + viewModelScope.async(Dispatchers.IO) { + semaphore.withPermit { + Timber.v("Fetching row: %s", row) + try { + homeSettingsService.fetchDataForRow( + row = row.config, + scope = viewModelScope, + prefs = prefs, + userDto = userDto, + libraries = libraries, + limit = prefs.maxItemsPerRow, + ) + } catch (ex: Exception) { + Timber.e(ex, "Error on row %s", row) + HomeRowLoadingState.Error(row.title, exception = ex) + } } } } - } - if (refresh) { - deferred.firstOrNull()?.await()?.let { - (loadingRows as MutableList)[0] = it - } + + if (refresh && state.homeRows.isNotEmpty() && watchingRowIndexes.isNotEmpty()) { + // Replace watching rows first + Timber.v("Refreshing rows: %s", watchingRowIndexes) + val rows = + deferred + .filterIndexed { index, _ -> index in watchingRowIndexes } + .awaitAll() _state.update { + val newRows = + it.homeRows.toMutableList().apply { + rows.forEachIndexed { index, row -> + set(watchingRowIndexes[index], row) + } + } it.copy( loadingState = LoadingState.Success, - homeRows = loadingRows, + homeRows = newRows, ) } } @@ -194,3 +204,11 @@ data class HomeState( ) } } + +/** + * Whether a row is a "is watching" type + */ +private fun isWatchingRow(row: HomeRowConfig) = + row is HomeRowConfig.ContinueWatching || + row is HomeRowConfig.NextUp || + row is HomeRowConfig.ContinueWatchingCombined From 99b15f20c0c666e6743a3fb61994f83d56c91b63 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 5 Feb 2026 12:32:04 -0500 Subject: [PATCH 45/53] Add option to quickly change to thumb images --- .../ui/main/settings/HomeRowSettings.kt | 48 +++++++++++++++---- app/src/main/res/values/strings.xml | 1 + 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt index 5817e7cc8e..b9c58a1506 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt @@ -61,10 +61,27 @@ fun HomeRowSettings( }, interactionSource = interactionSource, onClickPreference = { pref -> - if (pref == Options.ViewOptionsReset) { - onViewOptionsChange.invoke(defaultViewOptions) - } else if (pref == Options.ViewOptionsApplyAll) { - onApplyApplyAll.invoke() + when (pref) { + Options.ViewOptionsReset -> { + onViewOptionsChange.invoke(defaultViewOptions) + } + + Options.ViewOptionsApplyAll -> { + onApplyApplyAll.invoke() + } + + Options.ViewOptionsUseThumb -> { + onViewOptionsChange.invoke( + HomeRowViewOptions( + heightDp = Cards.HEIGHT_EPISODE, + spacing = 20, + imageType = ViewOptionImageType.THUMB, + aspectRatio = AspectRatio.WIDE, + episodeImageType = ViewOptionImageType.THUMB, + episodeAspectRatio = AspectRatio.WIDE, + ), + ) + } } }, modifier = @@ -168,6 +185,11 @@ internal object Options { title = R.string.reset, ) + val ViewOptionsUseThumb = + AppClickablePreference( + title = R.string.use_thumb_images, + ) + val ViewOptionsEpisodeContentScale = AppChoicePreference( title = R.string.global_content_scale, @@ -184,7 +206,7 @@ internal object Options { title = R.string.aspect_ratio, defaultValue = AspectRatio.TALL, displayValues = R.array.aspect_ratios, - getter = { it.aspectRatio }, + getter = { it.episodeAspectRatio }, setter = { viewOptions, value -> viewOptions.copy(episodeAspectRatio = value) }, indexToValue = { AspectRatio.entries[it] }, valueToIndex = { it.ordinal }, @@ -214,15 +236,22 @@ internal object Options { title = R.string.general, preferences = listOf( + ViewOptionsCardHeight, + ViewOptionsSpacing, ViewOptionsImageType, ViewOptionsAspectRatio, + ViewOptionsContentScale, // TODO // ViewOptionsShowTitles, ViewOptionsUseSeries, - ViewOptionsCardHeight, - ViewOptionsSpacing, - ViewOptionsContentScale, -// ViewOptionsApplyAll, + ), + ), + PreferenceGroup( + title = R.string.more, + preferences = + listOf( +// ViewOptionsApplyAll, + ViewOptionsUseThumb, ViewOptionsReset, ), ), @@ -255,6 +284,7 @@ internal object Options { title = R.string.more, preferences = listOf( + ViewOptionsUseThumb, ViewOptionsReset, ), ), diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 08142f529c..d93619b657 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -503,6 +503,7 @@ Suggestions for %1$s Increase all cards size Decrease all cards size + Use thumb images Disabled From 1828e94fae1e9f1a12328028a74ef0918140272c Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 5 Feb 2026 12:57:34 -0500 Subject: [PATCH 46/53] Option to show title below cards --- .../wholphin/ui/cards/BannerCard.kt | 85 ++++++++ .../wholphin/ui/cards/SeasonCard.kt | 36 +-- .../damontecres/wholphin/ui/main/HomePage.kt | 205 +++++++++++------- .../ui/main/settings/HomeRowSettings.kt | 4 +- 4 files changed, 230 insertions(+), 100 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/cards/BannerCard.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/cards/BannerCard.kt index 5999a2696d..5a0985c692 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/cards/BannerCard.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/cards/BannerCard.kt @@ -1,15 +1,19 @@ package com.github.damontecres.wholphin.ui.cards +import androidx.compose.animation.core.animateDpAsState import androidx.compose.foundation.background import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsFocusedAsState import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -24,6 +28,7 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp @@ -41,6 +46,7 @@ import com.github.damontecres.wholphin.ui.AspectRatios import com.github.damontecres.wholphin.ui.Cards import com.github.damontecres.wholphin.ui.FontAwesome import com.github.damontecres.wholphin.ui.LocalImageUrlService +import com.github.damontecres.wholphin.ui.enableMarquee import org.jellyfin.sdk.model.api.ImageType /** @@ -184,3 +190,82 @@ fun BannerCard( } } } + +@Composable +fun BannerCardWithTitle( + title: String?, + subtitle: String?, + item: BaseItem?, + onClick: () -> Unit, + onLongClick: () -> Unit, + modifier: Modifier = Modifier, + cornerText: String? = null, + played: Boolean = false, + favorite: Boolean = false, + playPercent: Double = 0.0, + cardHeight: Dp = 120.dp, + aspectRatio: Float = AspectRatios.WIDE, + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + imageType: ImageType = ImageType.PRIMARY, + imageContentScale: ContentScale = ContentScale.FillBounds, +) { + val focused by interactionSource.collectIsFocusedAsState() + val spaceBetween by animateDpAsState(if (focused) 12.dp else 4.dp) + val spaceBelow by animateDpAsState(if (focused) 4.dp else 12.dp) + val focusedAfterDelay by rememberFocusedAfterDelay(interactionSource) + val aspectRationToUse = aspectRatio.coerceAtLeast(AspectRatios.MIN) + val width = cardHeight * aspectRationToUse + Column( + verticalArrangement = Arrangement.spacedBy(spaceBetween), + modifier = modifier.width(width), + ) { + BannerCard( + name = null, + item = item, + onClick = onClick, + onLongClick = onLongClick, + modifier = Modifier, + cornerText = cornerText, + played = played, + favorite = favorite, + playPercent = playPercent, + cardHeight = cardHeight, + aspectRatio = aspectRatio, + interactionSource = interactionSource, + imageType = imageType, + imageContentScale = imageContentScale, + ) + Column( + verticalArrangement = Arrangement.spacedBy(0.dp), + modifier = + Modifier + .padding(bottom = spaceBelow) + .fillMaxWidth(), + ) { + Text( + text = title ?: "", + style = MaterialTheme.typography.bodyLarge, + fontWeight = FontWeight.SemiBold, + maxLines = 1, + textAlign = TextAlign.Center, + modifier = + Modifier + .fillMaxWidth() + .padding(horizontal = 4.dp) + .enableMarquee(focusedAfterDelay), + ) + Text( + text = subtitle ?: "", + style = MaterialTheme.typography.bodyMedium, + fontWeight = FontWeight.Normal, + maxLines = 1, + textAlign = TextAlign.Center, + modifier = + Modifier + .fillMaxWidth() + .padding(horizontal = 4.dp) + .enableMarquee(focusedAfterDelay), + ) + } + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/cards/SeasonCard.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/cards/SeasonCard.kt index e3e6059e96..c2cbd435b8 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/cards/SeasonCard.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/cards/SeasonCard.kt @@ -16,7 +16,6 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalDensity @@ -126,21 +125,7 @@ fun SeasonCard( val focused by interactionSource.collectIsFocusedAsState() val spaceBetween by animateDpAsState(if (focused) 12.dp else 4.dp) val spaceBelow by animateDpAsState(if (focused) 4.dp else 12.dp) - var focusedAfterDelay by remember { mutableStateOf(false) } - - val hideOverlayDelay = 500L - if (focused) { - LaunchedEffect(Unit) { - delay(hideOverlayDelay) - if (focused) { - focusedAfterDelay = true - } else { - focusedAfterDelay = false - } - } - } else { - focusedAfterDelay = false - } + val focusedAfterDelay by rememberFocusedAfterDelay(interactionSource) val aspectRationToUse = aspectRatio.coerceAtLeast(AspectRatios.MIN) val width = imageHeight * aspectRationToUse val height = imageWidth * (1f / aspectRationToUse) @@ -212,3 +197,22 @@ fun SeasonCard( } } } + +/** + * Returns a [androidx.compose.runtime.State] which represents if the item has been focused for a while + */ +@Composable +fun rememberFocusedAfterDelay(interactionSource: MutableInteractionSource): androidx.compose.runtime.State { + val focused by interactionSource.collectIsFocusedAsState() + val state = remember { mutableStateOf(false) } + + LaunchedEffect(focused) { + if (!focused) { + state.value = false + return@LaunchedEffect + } + delay(500L) + state.value = true + } + return state +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt index 44269360b4..f139eef6c8 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt @@ -46,9 +46,11 @@ import androidx.tv.material3.MaterialTheme import androidx.tv.material3.Text import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.model.BaseItem +import com.github.damontecres.wholphin.data.model.HomeRowViewOptions import com.github.damontecres.wholphin.preferences.UserPreferences import com.github.damontecres.wholphin.ui.Cards import com.github.damontecres.wholphin.ui.cards.BannerCard +import com.github.damontecres.wholphin.ui.cards.BannerCardWithTitle import com.github.damontecres.wholphin.ui.cards.GenreCard import com.github.damontecres.wholphin.ui.cards.ItemRow import com.github.damontecres.wholphin.ui.components.CircularProgress @@ -330,91 +332,41 @@ fun HomePageContent( .animateItem(), horizontalPadding = viewOptions.spacing.dp, cardContent = { index, item, cardModifier, onClick, onLongClick -> - val mod = - cardModifier - .onFocusChanged { - if (it.isFocused) { - position = RowColumn(rowIndex, index) - } - if (it.isFocused && onFocusPosition != null) { - val nonEmptyRowBefore = - homeRows - .subList(0, rowIndex) - .count { - it is HomeRowLoadingState.Success && it.items.isEmpty() - } - onFocusPosition.invoke( - RowColumn( - rowIndex - nonEmptyRowBefore, - index, - ), - ) - } - }.onKeyEvent { - if (isPlayKeyUp(it) && item?.type?.playable == true) { - Timber.v("Clicked play on ${item.id}") - onClickPlay.invoke(position, item) - return@onKeyEvent true - } - return@onKeyEvent false - } - when (item?.type) { - BaseItemKind.GENRE -> { - GenreCard( - genreId = item.id, - name = item.name, - imageUrl = item.imageUrlOverride, - onClick = onClick, - onLongClick = onLongClick, - modifier = mod.height(viewOptions.heightDp.dp), - ) - } - - else -> { - val imageType = - remember(item, viewOptions) { - if (item?.type == BaseItemKind.EPISODE) { - viewOptions.episodeImageType.imageType - } else { - viewOptions.imageType.imageType + HomePageCardContent( + index = index, + item = item, + onClick = onClick, + onLongClick = onLongClick, + viewOptions = viewOptions, + modifier = + cardModifier + .onFocusChanged { + if (it.isFocused) { + position = RowColumn(rowIndex, index) } - } - val ratio = - remember(item, viewOptions) { - if (item?.type == BaseItemKind.EPISODE) { - viewOptions.episodeAspectRatio.ratio - } else { - viewOptions.aspectRatio.ratio + if (it.isFocused && onFocusPosition != null) { + val nonEmptyRowBefore = + homeRows + .subList(0, rowIndex) + .count { + it is HomeRowLoadingState.Success && it.items.isEmpty() + } + onFocusPosition.invoke( + RowColumn( + rowIndex - nonEmptyRowBefore, + index, + ), + ) } - } - val scale = - remember(item, viewOptions) { - if (item?.type == BaseItemKind.EPISODE) { - viewOptions.episodeContentScale.scale - } else { - viewOptions.contentScale.scale + }.onKeyEvent { + if (isPlayKeyUp(it) && item?.type?.playable == true) { + Timber.v("Clicked play on ${item.id}") + onClickPlay.invoke(position, item) + return@onKeyEvent true } - } - BannerCard( - name = item?.data?.seriesName ?: item?.name, - item = item, - aspectRatio = ratio, - imageType = imageType, - imageContentScale = scale, - cornerText = item?.ui?.episdodeUnplayedCornerText, - played = item?.data?.userData?.played ?: false, - favorite = item?.favorite ?: false, - playPercent = - item?.data?.userData?.playedPercentage - ?: 0.0, - onClick = onClick, - onLongClick = onLongClick, - modifier = mod, - interactionSource = null, - cardHeight = viewOptions.heightDp.dp, - ) - } - } + return@onKeyEvent false + }, + ) }, ) } @@ -516,3 +468,92 @@ fun HomePageHeader( } } } + +@Composable +fun HomePageCardContent( + index: Int, + item: BaseItem?, + onClick: () -> Unit, + onLongClick: () -> Unit, + viewOptions: HomeRowViewOptions, + modifier: Modifier, +) { + when (item?.type) { + BaseItemKind.GENRE -> { + GenreCard( + genreId = item.id, + name = item.name, + imageUrl = item.imageUrlOverride, + onClick = onClick, + onLongClick = onLongClick, + modifier = modifier.height(viewOptions.heightDp.dp), + ) + } + + else -> { + val imageType = + remember(item, viewOptions) { + if (item?.type == BaseItemKind.EPISODE) { + viewOptions.episodeImageType.imageType + } else { + viewOptions.imageType.imageType + } + } + val ratio = + remember(item, viewOptions) { + if (item?.type == BaseItemKind.EPISODE) { + viewOptions.episodeAspectRatio.ratio + } else { + viewOptions.aspectRatio.ratio + } + } + val scale = + remember(item, viewOptions) { + if (item?.type == BaseItemKind.EPISODE) { + viewOptions.episodeContentScale.scale + } else { + viewOptions.contentScale.scale + } + } + if (viewOptions.showTitles) { + BannerCardWithTitle( + title = item?.title, + subtitle = item?.subtitle, + item = item, + aspectRatio = ratio, + imageType = imageType, + imageContentScale = scale, + cornerText = item?.ui?.episdodeUnplayedCornerText, + played = item?.data?.userData?.played ?: false, + favorite = item?.favorite ?: false, + playPercent = + item?.data?.userData?.playedPercentage + ?: 0.0, + onClick = onClick, + onLongClick = onLongClick, + modifier = modifier, + cardHeight = viewOptions.heightDp.dp, + ) + } else { + BannerCard( + name = item?.data?.seriesName ?: item?.name, + item = item, + aspectRatio = ratio, + imageType = imageType, + imageContentScale = scale, + cornerText = item?.ui?.episdodeUnplayedCornerText, + played = item?.data?.userData?.played ?: false, + favorite = item?.favorite ?: false, + playPercent = + item?.data?.userData?.playedPercentage + ?: 0.0, + onClick = onClick, + onLongClick = onLongClick, + modifier = modifier, + interactionSource = null, + cardHeight = viewOptions.heightDp.dp, + ) + } + } + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt index b9c58a1506..f4d396544a 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt @@ -238,11 +238,10 @@ internal object Options { listOf( ViewOptionsCardHeight, ViewOptionsSpacing, + ViewOptionsShowTitles, ViewOptionsImageType, ViewOptionsAspectRatio, ViewOptionsContentScale, - // TODO -// ViewOptionsShowTitles, ViewOptionsUseSeries, ), ), @@ -265,6 +264,7 @@ internal object Options { listOf( ViewOptionsCardHeight, ViewOptionsSpacing, + ViewOptionsShowTitles, ViewOptionsImageType, ViewOptionsAspectRatio, ViewOptionsContentScale, From 682b81d9361d176c1bdff972eec092e7ab01dcc6 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 5 Feb 2026 13:20:34 -0500 Subject: [PATCH 47/53] Add global reset to default --- .../wholphin/services/HomeSettingsService.kt | 4 ++-- .../wholphin/ui/main/settings/HomeRowSettings.kt | 4 +++- .../ui/main/settings/HomeSettingsGlobal.kt | 15 +++++++++++++++ .../wholphin/ui/main/settings/HomeSettingsPage.kt | 6 ++++++ .../ui/main/settings/HomeSettingsViewModel.kt | 11 +++++++++++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index 24951110db..412166bfdd 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -226,7 +226,7 @@ class HomeSettingsService } HomePageResolvedSettings(resolvedRows) } else { - createDefault(userId) + createDefault() } currentSettings.update { resolvedSettings } @@ -235,7 +235,7 @@ class HomeSettingsService /** * Create a default [HomePageResolvedSettings] using the available libraries */ - private suspend fun createDefault(userId: UUID): HomePageResolvedSettings { + suspend fun createDefault(): HomePageResolvedSettings { Timber.v("Creating default settings") val navDrawerItems = navDrawerItemRepository.getNavDrawerItems() val libraries = diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt index f4d396544a..9e861c617b 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowSettings.kt @@ -72,13 +72,15 @@ fun HomeRowSettings( Options.ViewOptionsUseThumb -> { onViewOptionsChange.invoke( - HomeRowViewOptions( + viewOptions.copy( heightDp = Cards.HEIGHT_EPISODE, spacing = 20, imageType = ViewOptionImageType.THUMB, aspectRatio = AspectRatio.WIDE, + contentScale = PrefContentScale.FIT, episodeImageType = ViewOptionImageType.THUMB, episodeAspectRatio = AspectRatio.WIDE, + episodeContentScale = PrefContentScale.FIT, ), ) } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt index 9e711b9f2d..ff61c61696 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt @@ -32,6 +32,7 @@ fun HomeSettingsGlobal( onClickSave: () -> Unit, onClickLoad: () -> Unit, onClickLoadWeb: () -> Unit, + onClickReset: () -> Unit, modifier: Modifier = Modifier, ) { val firstFocus: FocusRequester = remember { FocusRequester() } @@ -122,6 +123,20 @@ fun HomeSettingsGlobal( modifier = Modifier, ) } + item { + HomeSettingsListItem( + selected = false, + headlineText = stringResource(R.string.reset), + leadingContent = { + Text( + text = stringResource(R.string.fa_arrows_rotate), + fontFamily = FontAwesome, + ) + }, + onClick = onClickReset, + modifier = Modifier, + ) + } } } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index 10808d8157..e66de86084 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -210,6 +210,12 @@ fun HomeSettingsPage( viewModel.loadFromRemoteWeb() } }, + onClickReset = { + showConfirmDialog = + ShowConfirm(R.string.overwrite_local_settings) { + viewModel.resetToDefault() + } + }, modifier = destModifier, ) } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 6ebbbf446f..34f6285105 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -500,6 +500,17 @@ class HomeSettingsViewModel } } } + + fun resetToDefault() { + viewModelScope.launchIO { + _state.update { it.copy(loading = LoadingState.Loading) } + val result = homeSettingsService.createDefault() + _state.update { + it.copy(rows = result.rows) + } + fetchRowData() + } + } } data class HomePageSettingsState( From c844395acdb5a93573264e1cfb6d55dbb98927c3 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 5 Feb 2026 14:33:54 -0500 Subject: [PATCH 48/53] Move home page specific settings --- .../wholphin/data/model/HomeRowConfig.kt | 16 ++++++---- .../wholphin/preferences/AppPreference.kt | 4 +-- .../services/tvprovider/TvProviderWorker.kt | 8 +---- .../ui/main/settings/HomeSettingsGlobal.kt | 32 ++++++++++++++++++- .../ui/main/settings/HomeSettingsPage.kt | 22 +++++++++++++ .../ui/main/settings/HomeSettingsViewModel.kt | 3 ++ app/src/main/res/values/strings.xml | 4 +-- 7 files changed, 70 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index b195c28dcc..53e58397a0 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -85,11 +85,7 @@ sealed interface HomeRowConfig { @SerialName("Genres") data class Genres( val parentId: UUID, - override val viewOptions: HomeRowViewOptions = - HomeRowViewOptions( - heightDp = Cards.HEIGHT_EPISODE, - aspectRatio = AspectRatio.WIDE, - ), + override val viewOptions: HomeRowViewOptions = HomeRowViewOptions.genreDefault, ) : HomeRowConfig { override fun updateViewOptions(viewOptions: HomeRowViewOptions): Genres = this.copy(viewOptions = viewOptions) } @@ -214,4 +210,12 @@ data class HomeRowViewOptions( val episodeContentScale: PrefContentScale = PrefContentScale.FIT, val episodeAspectRatio: AspectRatio = AspectRatio.TALL, val episodeImageType: ViewOptionImageType = ViewOptionImageType.PRIMARY, -) +) { + companion object { + val genreDefault = + HomeRowViewOptions( + heightDp = Cards.HEIGHT_EPISODE, + aspectRatio = AspectRatio.WIDE, + ) + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/preferences/AppPreference.kt b/app/src/main/java/com/github/damontecres/wholphin/preferences/AppPreference.kt index 2b6b7064c0..183fb2610b 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/preferences/AppPreference.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/preferences/AppPreference.kt @@ -959,9 +959,6 @@ val basicPreferences = preferences = listOf( AppPreference.SignInAuto, - AppPreference.HomePageItems, - AppPreference.CombineContinueNext, - AppPreference.RewatchNextUp, AppPreference.PlayThemeMusic, AppPreference.RememberSelectedTab, AppPreference.SubtitleStyle, @@ -1058,6 +1055,7 @@ val advancedPreferences = preferences = listOf( AppPreference.ShowClock, + AppPreference.CombineContinueNext, // Temporarily disabled, see https://github.com/damontecres/Wholphin/pull/127#issuecomment-3478058418 // AppPreference.NavDrawerSwitchOnFocus, AppPreference.ControllerTimeout, diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/tvprovider/TvProviderWorker.kt b/app/src/main/java/com/github/damontecres/wholphin/services/tvprovider/TvProviderWorker.kt index 134e49037c..1a4dd99ee2 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/tvprovider/TvProviderWorker.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/tvprovider/TvProviderWorker.kt @@ -80,7 +80,6 @@ class TvProviderWorker getPotentialItems( userId, prefs.homePagePreferences.enableRewatchingNextUp, - prefs.homePagePreferences.combineContinueNext, ) val potentialItemsToAddIds = potentialItemsToAdd.map { it.id.toString() } @@ -144,7 +143,6 @@ class TvProviderWorker private suspend fun getPotentialItems( userId: UUID, enableRewatching: Boolean, - combineContinueNext: Boolean, ): List { val resumeItems = latestNextUpService.getResume(userId, 10, true) val seriesIds = resumeItems.mapNotNull { it.data.seriesId } @@ -152,11 +150,7 @@ class TvProviderWorker latestNextUpService .getNextUp(userId, 10, enableRewatching, false) .filter { it.data.seriesId != null && it.data.seriesId !in seriesIds } - return if (combineContinueNext) { - latestNextUpService.buildCombined(resumeItems, nextUpItems) - } else { - resumeItems + nextUpItems - } + return latestNextUpService.buildCombined(resumeItems, nextUpItems) } private suspend fun getCurrentTvChannelNextUp(): List = diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt index ff61c61696..1ad803ff0e 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsGlobal.kt @@ -23,11 +23,16 @@ import androidx.tv.material3.Icon import androidx.tv.material3.MaterialTheme import androidx.tv.material3.Text import com.github.damontecres.wholphin.R +import com.github.damontecres.wholphin.preferences.AppPreference +import com.github.damontecres.wholphin.preferences.AppPreferences import com.github.damontecres.wholphin.ui.FontAwesome +import com.github.damontecres.wholphin.ui.preferences.ComposablePreference import com.github.damontecres.wholphin.ui.tryRequestFocus @Composable fun HomeSettingsGlobal( + preferences: AppPreferences, + onPreferenceChange: (AppPreferences) -> Unit, onClickResize: (Int) -> Unit, onClickSave: () -> Unit, onClickLoad: () -> Unit, @@ -52,6 +57,31 @@ fun HomeSettingsGlobal( .fillMaxHeight() .focusRestorer(firstFocus), ) { + item { + ComposablePreference( + preference = AppPreference.HomePageItems, + value = AppPreference.HomePageItems.getter.invoke(preferences), + onValueChange = { + val newPrefs = AppPreference.HomePageItems.setter.invoke(preferences, it) + onPreferenceChange.invoke(newPrefs) + }, + onNavigate = {}, + modifier = Modifier.focusRequester(firstFocus), + ) + } + item { + ComposablePreference( + preference = AppPreference.RewatchNextUp, + value = AppPreference.RewatchNextUp.getter.invoke(preferences), + onValueChange = { + val newPrefs = AppPreference.RewatchNextUp.setter.invoke(preferences, it) + onPreferenceChange.invoke(newPrefs) + }, + onNavigate = {}, + modifier = Modifier, + ) + } + item { HorizontalDivider() } item { HomeSettingsListItem( selected = false, @@ -63,7 +93,7 @@ fun HomeSettingsGlobal( ) }, onClick = { onClickResize.invoke(1) }, - modifier = Modifier.focusRequester(firstFocus), + modifier = Modifier, ) } item { diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index e66de86084..9c061ba995 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -30,7 +30,10 @@ import androidx.tv.material3.MaterialTheme import androidx.tv.material3.surfaceColorAtElevation import com.github.damontecres.wholphin.R import com.github.damontecres.wholphin.data.model.HomeRowConfig +import com.github.damontecres.wholphin.data.model.HomeRowViewOptions +import com.github.damontecres.wholphin.preferences.AppPreferences import com.github.damontecres.wholphin.ui.components.ConfirmDialog +import com.github.damontecres.wholphin.ui.launchIO 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 @@ -163,10 +166,18 @@ fun HomeSettingsPage( else -> Options.OPTIONS } } + val defaultViewOptions = + remember(row.config) { + when (row.config) { + is HomeRowConfig.Genres -> HomeRowViewOptions.genreDefault + else -> HomeRowViewOptions() + } + } HomeRowSettings( title = row.title, preferenceOptions = preferenceOptions, viewOptions = row.config.viewOptions, + defaultViewOptions = defaultViewOptions, onViewOptionsChange = { viewModel.updateViewOptions(dest.rowId, it) }, @@ -190,7 +201,18 @@ fun HomeSettingsPage( } HomeSettingsDestination.GlobalSettings -> { + val preferences by + viewModel.preferencesDataStore.data.collectAsState( + AppPreferences.getDefaultInstance(), + ) + HomeSettingsGlobal( + preferences = preferences, + onPreferenceChange = { newPrefs -> + scope.launchIO { + viewModel.preferencesDataStore.updateData { newPrefs } + } + }, onClickResize = { viewModel.resizeCards(it) }, onClickSave = { showConfirmDialog = diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 34f6285105..6e7f47b4ee 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -3,6 +3,7 @@ package com.github.damontecres.wholphin.ui.main.settings import android.content.Context import android.widget.Toast import androidx.compose.runtime.Immutable +import androidx.datastore.core.DataStore import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.github.damontecres.wholphin.R @@ -19,6 +20,7 @@ import com.github.damontecres.wholphin.data.model.HomeRowConfig.RecentlyAdded import com.github.damontecres.wholphin.data.model.HomeRowConfig.RecentlyReleased import com.github.damontecres.wholphin.data.model.HomeRowConfig.Suggestions import com.github.damontecres.wholphin.data.model.HomeRowViewOptions +import com.github.damontecres.wholphin.preferences.AppPreferences import com.github.damontecres.wholphin.services.BackdropService import com.github.damontecres.wholphin.services.HomePageResolvedSettings import com.github.damontecres.wholphin.services.HomeRowConfigDisplay @@ -64,6 +66,7 @@ class HomeSettingsViewModel private val navDrawerItemRepository: NavDrawerItemRepository, private val backdropService: BackdropService, private val seerrServerRepository: SeerrServerRepository, + val preferencesDataStore: DataStore, @param:IoCoroutineScope private val ioScope: CoroutineScope, ) : ViewModel() { private val _state = MutableStateFlow(HomePageSettingsState.EMPTY) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d93619b657..6d1a7436a6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -501,8 +501,8 @@ Overwrite local settings? For episodes Suggestions for %1$s - Increase all cards size - Decrease all cards size + Increase size for all cards + Decrease size for all cards Use thumb images From c3c054a291dec6fc369da2c51d0b289761c7db06 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Thu, 5 Feb 2026 14:55:57 -0500 Subject: [PATCH 49/53] Show empty rows in settings --- .../ui/components/FocusableItemRow.kt | 84 +++++++++++++++++++ .../damontecres/wholphin/ui/main/HomePage.kt | 63 ++++---------- .../ui/main/settings/HomeSettingsPage.kt | 1 + 3 files changed, 103 insertions(+), 45 deletions(-) create mode 100644 app/src/main/java/com/github/damontecres/wholphin/ui/components/FocusableItemRow.kt diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/components/FocusableItemRow.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/components/FocusableItemRow.kt new file mode 100644 index 0000000000..03394bb89a --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/components/FocusableItemRow.kt @@ -0,0 +1,84 @@ +package com.github.damontecres.wholphin.ui.components + +import androidx.compose.animation.animateColorAsState +import androidx.compose.animation.core.animateDpAsState +import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.foundation.background +import androidx.compose.foundation.focusable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsFocusedAsState +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.runtime.Composable +import androidx.compose.runtime.NonRestartableComposable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.scale +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.unit.dp +import androidx.tv.material3.MaterialTheme +import androidx.tv.material3.Text + +/** + * Placeholder for [com.github.damontecres.wholphin.ui.cards.ItemRow]. It is [focusable] so it can be scrolled. + */ +@Composable +@NonRestartableComposable +fun FocusableItemRow( + title: String, + subtitle: String, + modifier: Modifier = Modifier, + isError: Boolean = false, +) = FocusableItemRow( + titleContent = { + Text( + text = title, + style = MaterialTheme.typography.titleLarge, + color = MaterialTheme.colorScheme.onBackground, + ) + }, + subtitleContent = { + Text( + text = subtitle, + style = MaterialTheme.typography.titleMedium, + color = if (isError) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.onBackground, + modifier = Modifier.padding(start = 8.dp), + ) + }, + modifier = modifier, +) + +@Composable +fun FocusableItemRow( + titleContent: @Composable () -> Unit, + subtitleContent: @Composable () -> Unit, + modifier: Modifier = Modifier, +) { + val interactionSource = remember { MutableInteractionSource() } + val focused by interactionSource.collectIsFocusedAsState() + val padding by animateDpAsState(if (focused) 8.dp else 0.dp) + val scale by animateFloatAsState(if (focused) 1.1f else 1f) + val background by animateColorAsState( + if (focused) { + MaterialTheme.colorScheme.border.copy(alpha = .25f) + } else { + Color.Unspecified + }, + ) + Column( + verticalArrangement = Arrangement.spacedBy(8.dp), + modifier = + modifier + .padding(start = 8.dp) + .focusable(interactionSource = interactionSource) + .scale(scale) + .background(background, shape = RoundedCornerShape(8.dp)) + .padding(padding), + ) { + titleContent.invoke() + subtitleContent.invoke() + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt index f139eef6c8..8394af5abb 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt @@ -1,8 +1,6 @@ package com.github.damontecres.wholphin.ui.main -import androidx.compose.foundation.background import androidx.compose.foundation.focusGroup -import androidx.compose.foundation.focusable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -33,7 +31,6 @@ import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.focusRestorer import androidx.compose.ui.focus.onFocusChanged -import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.key.onKeyEvent import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource @@ -58,6 +55,7 @@ import com.github.damontecres.wholphin.ui.components.DialogParams import com.github.damontecres.wholphin.ui.components.DialogPopup import com.github.damontecres.wholphin.ui.components.EpisodeName import com.github.damontecres.wholphin.ui.components.ErrorMessage +import com.github.damontecres.wholphin.ui.components.FocusableItemRow import com.github.damontecres.wholphin.ui.components.LoadingPage import com.github.damontecres.wholphin.ui.components.QuickDetails import com.github.damontecres.wholphin.ui.data.AddPlaylistViewModel @@ -198,6 +196,7 @@ fun HomePageContent( loadingState: LoadingState? = null, listState: LazyListState = rememberLazyListState(), takeFocus: Boolean = true, + showEmptyRows: Boolean = false, ) { var position by rememberPosition() val focusedItem = @@ -264,52 +263,20 @@ fun HomePageContent( is HomeRowLoadingState.Loading, is HomeRowLoadingState.Pending, -> { - Column( - verticalArrangement = Arrangement.spacedBy(8.dp), + FocusableItemRow( + title = r.title, + subtitle = stringResource(R.string.loading), modifier = Modifier.animateItem(), - ) { - Text( - text = r.title, - style = MaterialTheme.typography.titleLarge, - color = MaterialTheme.colorScheme.onBackground, - ) - Text( - text = stringResource(R.string.loading), - style = MaterialTheme.typography.titleMedium, - color = MaterialTheme.colorScheme.onBackground, - ) - } + ) } is HomeRowLoadingState.Error -> { - var focused by remember { mutableStateOf(false) } - Column( - verticalArrangement = Arrangement.spacedBy(8.dp), - modifier = - Modifier - .onFocusChanged { - focused = it.isFocused - }.focusable() - .background( - if (focused) { - // Just so the user can tell it has focus - MaterialTheme.colorScheme.border.copy(alpha = .25f) - } else { - Color.Unspecified - }, - ).animateItem(), - ) { - Text( - text = r.title, - style = MaterialTheme.typography.titleLarge, - color = MaterialTheme.colorScheme.onBackground, - ) - Text( - text = r.localizedMessage, - style = MaterialTheme.typography.titleMedium, - color = MaterialTheme.colorScheme.error, - ) - } + FocusableItemRow( + title = r.title, + subtitle = r.localizedMessage, + isError = true, + modifier = Modifier.animateItem(), + ) } is HomeRowLoadingState.Success -> { @@ -369,6 +336,12 @@ fun HomePageContent( ) }, ) + } else if (showEmptyRows) { + FocusableItemRow( + title = r.title, + subtitle = stringResource(R.string.no_results), + modifier = Modifier.animateItem(), + ) } } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index 9c061ba995..d7eac3c0eb 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -256,6 +256,7 @@ fun HomeSettingsPage( onUpdateBackdrop = viewModel::updateBackdrop, listState = listState, takeFocus = false, + showEmptyRows = true, modifier = Modifier .fillMaxHeight() From 3879072c1d6685e5d22bf1b726fe845f2d09c6ee Mon Sep 17 00:00:00 2001 From: Damontecres Date: Tue, 10 Feb 2026 16:27:01 -0500 Subject: [PATCH 50/53] Check version when parsing --- .../wholphin/data/model/HomeRowConfig.kt | 4 ++-- .../wholphin/services/HomeSettingsService.kt | 14 +++++++++++++- .../ui/main/settings/HomeSettingsViewModel.kt | 16 ++++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt index 53e58397a0..7d521ce4d4 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/model/HomeRowConfig.kt @@ -181,10 +181,10 @@ sealed interface HomeRowConfig { @SerialName("HomePageSettings") data class HomePageSettings( val rows: List, - val version: Int = SUPPORTED_HOME_PAGE_SETTINGS_VERSION, + val version: Int, ) { companion object { - val EMPTY = HomePageSettings(listOf()) + val EMPTY = HomePageSettings(listOf(), SUPPORTED_HOME_PAGE_SETTINGS_VERSION) } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index 96e9efa989..f463c35112 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -6,6 +6,7 @@ import com.github.damontecres.wholphin.data.NavDrawerItemRepository import com.github.damontecres.wholphin.data.model.BaseItem import com.github.damontecres.wholphin.data.model.HomePageSettings import com.github.damontecres.wholphin.data.model.HomeRowConfig +import com.github.damontecres.wholphin.data.model.SUPPORTED_HOME_PAGE_SETTINGS_VERSION import com.github.damontecres.wholphin.preferences.DefaultUserConfiguration import com.github.damontecres.wholphin.preferences.HomePagePreferences import com.github.damontecres.wholphin.ui.DefaultItemFields @@ -30,8 +31,10 @@ import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.decodeFromJsonElement import kotlinx.serialization.json.encodeToStream +import kotlinx.serialization.json.intOrNull import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject +import kotlinx.serialization.json.jsonPrimitive import org.jellyfin.sdk.api.client.ApiClient import org.jellyfin.sdk.api.client.extensions.displayPreferencesApi import org.jellyfin.sdk.api.client.extensions.liveTvApi @@ -174,6 +177,10 @@ class HomeSettingsService * This is public only for testing */ fun decode(element: JsonElement): HomePageSettings { + val version = element.jsonObject["version"]?.jsonPrimitive?.intOrNull + if (version == null || version > SUPPORTED_HOME_PAGE_SETTINGS_VERSION) { + throw UnsupportedHomeSettingsVersionException(version) + } val rowsElement = element.jsonObject["rows"]?.jsonArray val rows = rowsElement @@ -186,7 +193,7 @@ class HomeSettingsService null } }.orEmpty() - return HomePageSettings(rows) + return HomePageSettings(rows, version) } /** @@ -928,3 +935,8 @@ enum class HomeSectionType( fun fromString(homeKey: String?) = homeKey?.let { entries.firstOrNull { it.serialName == homeKey } } } } + +class UnsupportedHomeSettingsVersionException( + val unsupportedVersion: Int?, + val maxSupportedVersion: Int = SUPPORTED_HOME_PAGE_SETTINGS_VERSION, +) : Exception("Unsupported version $unsupportedVersion, max supported is $maxSupportedVersion") diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 6e7f47b4ee..3cb005353c 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -20,12 +20,14 @@ import com.github.damontecres.wholphin.data.model.HomeRowConfig.RecentlyAdded import com.github.damontecres.wholphin.data.model.HomeRowConfig.RecentlyReleased import com.github.damontecres.wholphin.data.model.HomeRowConfig.Suggestions import com.github.damontecres.wholphin.data.model.HomeRowViewOptions +import com.github.damontecres.wholphin.data.model.SUPPORTED_HOME_PAGE_SETTINGS_VERSION import com.github.damontecres.wholphin.preferences.AppPreferences import com.github.damontecres.wholphin.services.BackdropService import com.github.damontecres.wholphin.services.HomePageResolvedSettings import com.github.damontecres.wholphin.services.HomeRowConfigDisplay import com.github.damontecres.wholphin.services.HomeSettingsService import com.github.damontecres.wholphin.services.SeerrServerRepository +import com.github.damontecres.wholphin.services.UnsupportedHomeSettingsVersionException import com.github.damontecres.wholphin.services.UserPreferencesService import com.github.damontecres.wholphin.services.hilt.IoCoroutineScope import com.github.damontecres.wholphin.ui.launchIO @@ -385,7 +387,8 @@ class HomeSettingsViewModel serverRepository.currentUser.value?.let { user -> Timber.d("Saving home settings to remote") val rows = state.value.rows.map { it.config } - val settings = HomePageSettings(rows = rows) + val settings = + HomePageSettings(rows = rows, SUPPORTED_HOME_PAGE_SETTINGS_VERSION) try { Timber.d("saveToRemote") homeSettingsService.saveToServer(user.id, settings) @@ -418,6 +421,10 @@ class HomeSettingsViewModel showToast(context, "No server-side settings found") } fetchRowData() + } catch (ex: UnsupportedHomeSettingsVersionException) { + // TODO + Timber.w(ex) + showToast(context, "Error: ${ex.localizedMessage}") } catch (ex: Exception) { Timber.e(ex) showToast(context, "Error: ${ex.localizedMessage}") @@ -456,7 +463,8 @@ class HomeSettingsViewModel ioScope.launchIO { serverRepository.currentUser.value?.let { user -> val rows = state.value.rows.map { it.config } - val settings = HomePageSettings(rows = rows) + val settings = + HomePageSettings(rows = rows, SUPPORTED_HOME_PAGE_SETTINGS_VERSION) try { Timber.d("saveToLocal") val local = homeSettingsService.loadFromLocal(user.id) @@ -465,6 +473,10 @@ class HomeSettingsViewModel homeSettingsService.saveToLocal(user.id, settings) showToast(context, context.getString(R.string.save), Toast.LENGTH_SHORT) } + } catch (ex: UnsupportedHomeSettingsVersionException) { + Timber.w(ex, "Overwriting local settings") + homeSettingsService.saveToLocal(user.id, settings) + showToast(context, context.getString(R.string.save), Toast.LENGTH_SHORT) } catch (ex: Exception) { Timber.e(ex) showToast(context, "Error saving: ${ex.localizedMessage}") From 7005adc5071523972fe502048f6051547808f3ee Mon Sep 17 00:00:00 2001 From: Damontecres Date: Tue, 10 Feb 2026 16:57:44 -0500 Subject: [PATCH 51/53] A few UI tweaks --- .../wholphin/ui/components/FocusableItemRow.kt | 8 +------- .../ui/main/settings/HomeSettingsViewModel.kt | 12 ++++++++++-- app/src/main/res/values/strings.xml | 1 + 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/components/FocusableItemRow.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/components/FocusableItemRow.kt index 03394bb89a..b04bf451ae 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/components/FocusableItemRow.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/components/FocusableItemRow.kt @@ -1,8 +1,6 @@ package com.github.damontecres.wholphin.ui.components import androidx.compose.animation.animateColorAsState -import androidx.compose.animation.core.animateDpAsState -import androidx.compose.animation.core.animateFloatAsState import androidx.compose.foundation.background import androidx.compose.foundation.focusable import androidx.compose.foundation.interaction.MutableInteractionSource @@ -16,7 +14,6 @@ import androidx.compose.runtime.NonRestartableComposable import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.scale import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.tv.material3.MaterialTheme @@ -59,8 +56,6 @@ fun FocusableItemRow( ) { val interactionSource = remember { MutableInteractionSource() } val focused by interactionSource.collectIsFocusedAsState() - val padding by animateDpAsState(if (focused) 8.dp else 0.dp) - val scale by animateFloatAsState(if (focused) 1.1f else 1f) val background by animateColorAsState( if (focused) { MaterialTheme.colorScheme.border.copy(alpha = .25f) @@ -74,9 +69,8 @@ fun FocusableItemRow( modifier .padding(start = 8.dp) .focusable(interactionSource = interactionSource) - .scale(scale) .background(background, shape = RoundedCornerShape(8.dp)) - .padding(padding), + .padding(8.dp), ) { titleContent.invoke() subtitleContent.invoke() diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 3cb005353c..711aaa3e96 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -392,6 +392,7 @@ class HomeSettingsViewModel try { Timber.d("saveToRemote") homeSettingsService.saveToServer(user.id, settings) + showSaveToast() } catch (ex: Exception) { Timber.e(ex) showToast(context, "Error saving: ${ex.localizedMessage}") @@ -471,12 +472,12 @@ class HomeSettingsViewModel // Only save if there are changes if (local != settings) { homeSettingsService.saveToLocal(user.id, settings) - showToast(context, context.getString(R.string.save), Toast.LENGTH_SHORT) + showSaveToast() } } catch (ex: UnsupportedHomeSettingsVersionException) { Timber.w(ex, "Overwriting local settings") homeSettingsService.saveToLocal(user.id, settings) - showToast(context, context.getString(R.string.save), Toast.LENGTH_SHORT) + showSaveToast() } catch (ex: Exception) { Timber.e(ex) showToast(context, "Error saving: ${ex.localizedMessage}") @@ -526,6 +527,13 @@ class HomeSettingsViewModel fetchRowData() } } + + private suspend fun showSaveToast() = + showToast( + context, + context.getString(R.string.settings_saved), + Toast.LENGTH_SHORT, + ) } data class HomePageSettingsState( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6c8c991b2b..e8980443f4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -512,6 +512,7 @@ Increase size for all cards Decrease size for all cards Use thumb images + Settings saved Disabled From f592f3081b6829169fb82928bdfdecca36de8d43 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Wed, 11 Feb 2026 22:14:47 -0500 Subject: [PATCH 52/53] Add some display option presets --- .../ui/main/settings/HomeRowPresets.kt | 206 ++++++++++++++++++ .../main/settings/HomeSettingsDestination.kt | 3 + .../ui/main/settings/HomeSettingsPage.kt | 8 + .../ui/main/settings/HomeSettingsRowList.kt | 25 ++- .../ui/main/settings/HomeSettingsViewModel.kt | 105 +++++++++ app/src/main/res/values/strings.xml | 2 + 6 files changed, 348 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowPresets.kt diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowPresets.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowPresets.kt new file mode 100644 index 0000000000..e0a6422112 --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeRowPresets.kt @@ -0,0 +1,206 @@ +package com.github.damontecres.wholphin.ui.main.settings + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.itemsIndexed +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +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 com.github.damontecres.wholphin.R +import com.github.damontecres.wholphin.data.model.HomeRowViewOptions +import com.github.damontecres.wholphin.preferences.PrefContentScale +import com.github.damontecres.wholphin.ui.AspectRatio +import com.github.damontecres.wholphin.ui.Cards +import com.github.damontecres.wholphin.ui.components.ViewOptionImageType +import com.github.damontecres.wholphin.ui.tryRequestFocus +import org.jellyfin.sdk.model.api.CollectionType + +data class HomeRowPresets( + val continueWatching: HomeRowViewOptions, + val movieLibrary: HomeRowViewOptions, + val tvLibrary: HomeRowViewOptions, + val videoLibrary: HomeRowViewOptions, + val photoLibrary: HomeRowViewOptions, + val playlist: HomeRowViewOptions, + val genreSize: Int, +) { + fun getByCollectionType(collectionType: CollectionType): HomeRowViewOptions = + when (collectionType) { + CollectionType.MOVIES -> movieLibrary + + CollectionType.TVSHOWS -> tvLibrary + + CollectionType.MUSICVIDEOS -> videoLibrary + + CollectionType.TRAILERS -> videoLibrary + + CollectionType.HOMEVIDEOS -> videoLibrary + + CollectionType.BOXSETS -> movieLibrary + + CollectionType.PHOTOS -> photoLibrary + + CollectionType.UNKNOWN, + CollectionType.MUSIC, + CollectionType.BOOKS, + CollectionType.LIVETV, + CollectionType.PLAYLISTS, + CollectionType.FOLDERS, + -> HomeRowViewOptions() + } + + companion object { + val WholphinDefault by lazy { + HomeRowPresets( + continueWatching = HomeRowViewOptions(), + movieLibrary = HomeRowViewOptions(), + tvLibrary = HomeRowViewOptions(), + videoLibrary = + HomeRowViewOptions( + aspectRatio = AspectRatio.WIDE, + ), + photoLibrary = + HomeRowViewOptions( + aspectRatio = AspectRatio.WIDE, + contentScale = PrefContentScale.CROP, + ), + playlist = + HomeRowViewOptions( + aspectRatio = AspectRatio.SQUARE, + contentScale = PrefContentScale.FIT, + ), + genreSize = Cards.HEIGHT_2X3_DP, + ) + } + + val WholphinCompact by lazy { + val height = 148 + val epHeight = 100 + HomeRowPresets( + continueWatching = + HomeRowViewOptions( + heightDp = height, + ), + movieLibrary = + HomeRowViewOptions( + heightDp = height, + ), + tvLibrary = + HomeRowViewOptions( + heightDp = height, + ), + videoLibrary = + HomeRowViewOptions( + heightDp = epHeight, + aspectRatio = AspectRatio.WIDE, + ), + photoLibrary = + HomeRowViewOptions( + heightDp = epHeight, + aspectRatio = AspectRatio.WIDE, + contentScale = PrefContentScale.CROP, + ), + playlist = + HomeRowViewOptions( + heightDp = epHeight, + aspectRatio = AspectRatio.SQUARE, + contentScale = PrefContentScale.FIT, + ), + genreSize = epHeight, + ) + } + + val Thumbnails by lazy { + val height = 148 + val epHeight = 100 + HomeRowPresets( + continueWatching = + HomeRowViewOptions( + heightDp = epHeight, + imageType = ViewOptionImageType.THUMB, + aspectRatio = AspectRatio.WIDE, + episodeImageType = ViewOptionImageType.THUMB, + episodeAspectRatio = AspectRatio.WIDE, + ), + movieLibrary = + HomeRowViewOptions( + heightDp = height, + ), + tvLibrary = + HomeRowViewOptions( + heightDp = height, + ), + videoLibrary = + HomeRowViewOptions( + heightDp = epHeight, + aspectRatio = AspectRatio.WIDE, + ), + photoLibrary = + HomeRowViewOptions( + heightDp = epHeight, + aspectRatio = AspectRatio.WIDE, + contentScale = PrefContentScale.CROP, + ), + playlist = + HomeRowViewOptions( + heightDp = epHeight, + aspectRatio = AspectRatio.SQUARE, + contentScale = PrefContentScale.FIT, + ), + genreSize = epHeight, + ) + } + } +} + +@Composable +fun HomeRowPresetsContent( + onApply: (HomeRowPresets) -> Unit, + modifier: Modifier = Modifier, +) { + val presets = + remember { + listOf( + "Wholphin Default", + "Wholphin Compact", + "Thumbnails", + ) + } + val focusRequesters = remember { List(presets.size) { FocusRequester() } } + LaunchedEffect(Unit) { focusRequesters[0].tryRequestFocus() } + Column(modifier = modifier) { + TitleText(stringResource(R.string.display_presets)) + LazyColumn( + contentPadding = PaddingValues(8.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + modifier = + modifier + .fillMaxHeight() + .focusRestorer(focusRequesters[0]), + ) { + itemsIndexed(presets) { index, title -> + HomeSettingsListItem( + selected = false, + headlineText = title, + onClick = { + when (index) { + 0 -> onApply.invoke(HomeRowPresets.WholphinDefault) + 1 -> onApply.invoke(HomeRowPresets.WholphinCompact) + 2 -> onApply.invoke(HomeRowPresets.Thumbnails) + } + }, + modifier = Modifier.focusRequester(focusRequesters[index]), + ) + } + } + } +} diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt index 8148e6199e..ad433c231f 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsDestination.kt @@ -32,4 +32,7 @@ sealed interface HomeSettingsDestination : NavKey { @Serializable data object GlobalSettings : HomeSettingsDestination + + @Serializable + data object Presets : HomeSettingsDestination } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt index d7eac3c0eb..616eff13fc 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsPage.kt @@ -100,6 +100,7 @@ fun HomeSettingsPage( state = state, onClickAdd = { backStack.add(HomeSettingsDestination.AddRow) }, onClickSettings = { backStack.add(HomeSettingsDestination.GlobalSettings) }, + onClickPresets = { backStack.add(HomeSettingsDestination.Presets) }, onClickMove = viewModel::moveRow, onClickDelete = viewModel::deleteRow, onClick = { index, row -> @@ -241,6 +242,13 @@ fun HomeSettingsPage( modifier = destModifier, ) } + + HomeSettingsDestination.Presets -> { + HomeRowPresetsContent( + onApply = viewModel::applyPreset, + modifier = destModifier, + ) + } } } }, diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt index 54a4f60508..231243ce71 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsRowList.kt @@ -56,6 +56,7 @@ fun HomeSettingsRowList( onClick: (Int, HomeRowConfigDisplay) -> Unit, onClickAdd: () -> Unit, onClickSettings: () -> Unit, + onClickPresets: () -> Unit, onClickMove: (MoveDirection, Int) -> Unit, onClickDelete: (Int) -> Unit, modifier: Modifier, @@ -64,7 +65,7 @@ fun HomeSettingsRowList( val scope = rememberCoroutineScope() val listState = rememberLazyListState() - val itemsBeforeRows = 3 + val itemsBeforeRows = 4 val focusRequesters = remember(state.rows.size) { List(itemsBeforeRows + state.rows.size) { FocusRequester() } } @@ -117,6 +118,28 @@ fun HomeSettingsRowList( modifier = Modifier.focusRequester(focusRequesters[1]), ) } + item { + HomeSettingsListItem( + selected = false, + headlineText = stringResource(R.string.display_presets), + supportingContent = { + Text( + text = stringResource(R.string.display_presets_description), + ) + }, + leadingContent = { + Text( + text = stringResource(R.string.fa_sliders), + fontFamily = FontAwesome, + ) + }, + onClick = { + position = 2 + onClickPresets.invoke() + }, + modifier = Modifier.focusRequester(focusRequesters[1]), + ) + } item { TitleText(stringResource(R.string.home_rows)) HorizontalDivider() diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 711aaa3e96..c2e414e040 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -49,6 +49,8 @@ import kotlinx.coroutines.flow.update import kotlinx.coroutines.sync.Semaphore import kotlinx.coroutines.sync.withPermit import kotlinx.serialization.Serializable +import org.jellyfin.sdk.api.client.ApiClient +import org.jellyfin.sdk.api.client.extensions.userLibraryApi import org.jellyfin.sdk.model.api.BaseItemKind import org.jellyfin.sdk.model.api.CollectionType import org.jellyfin.sdk.model.serializer.UUIDSerializer @@ -62,6 +64,7 @@ class HomeSettingsViewModel @Inject constructor( @param:ApplicationContext private val context: Context, + private val api: ApiClient, private val homeSettingsService: HomeSettingsService, private val serverRepository: ServerRepository, private val userPreferencesService: UserPreferencesService, @@ -534,6 +537,108 @@ class HomeSettingsViewModel context.getString(R.string.settings_saved), Toast.LENGTH_SHORT, ) + + fun applyPreset(preset: HomeRowPresets) { + _state.update { it.copy(loading = LoadingState.Loading) } + viewModelScope.launchIO { + val state = state.value + + val typeCache = mutableMapOf() + + suspend fun getCollectionType(itemId: UUID): CollectionType = + typeCache.getOrPut(itemId) { + state.libraries + .firstOrNull { it.itemId == itemId } + ?.collectionType + ?: api.userLibraryApi + .getItem(itemId) + .content.collectionType ?: CollectionType.UNKNOWN + } ?: CollectionType.UNKNOWN + + val newRows = + state.rows.map { + val newConfig = + when (it.config) { + is ContinueWatching, + is NextUp, + is ContinueWatchingCombined, + -> { + it.config.updateViewOptions(preset.continueWatching) + } + + is HomeRowConfig.ByParent -> { + val collectionType = getCollectionType(it.config.parentId) + val viewOptions = preset.getByCollectionType(collectionType) + it.config.updateViewOptions(viewOptions) + } + + is HomeRowConfig.Favorite -> { + val viewOptions = + when (it.config.kind) { + BaseItemKind.MOVIE -> preset.movieLibrary + BaseItemKind.SERIES -> preset.tvLibrary + BaseItemKind.EPISODE -> preset.continueWatching + BaseItemKind.VIDEO -> preset.videoLibrary + BaseItemKind.PLAYLIST -> preset.playlist + BaseItemKind.PERSON -> preset.movieLibrary + else -> preset.movieLibrary + } + it.config.updateViewOptions(viewOptions) + } + + is Genres -> { + it.config.updateViewOptions(it.config.viewOptions.copy(heightDp = preset.genreSize)) + } + + is HomeRowConfig.GetItems -> { + it.config + } + + is RecentlyAdded -> { + val collectionType = getCollectionType(it.config.parentId) + val viewOptions = preset.getByCollectionType(collectionType) + it.config.updateViewOptions(viewOptions) + } + + is RecentlyReleased -> { + val collectionType = getCollectionType(it.config.parentId) + val viewOptions = preset.getByCollectionType(collectionType) + it.config.updateViewOptions(viewOptions) + } + + is HomeRowConfig.Recordings -> { + it.config.updateViewOptions(preset.tvLibrary) + } + + is Suggestions -> { + val collectionType = getCollectionType(it.config.parentId) + val viewOptions = preset.getByCollectionType(collectionType) + it.config.updateViewOptions(viewOptions) + } + + is HomeRowConfig.TvPrograms -> { + it.config.updateViewOptions(preset.tvLibrary) + } + } + it.copy(config = newConfig) + } + + _state.update { + it.copy( + loading = LoadingState.Success, + rows = newRows, + rowData = + it.rowData.toMutableList().mapIndexed { index, row -> + if (row is HomeRowLoadingState.Success) { + row.copy(viewOptions = newRows[index].config.viewOptions) + } else { + row + } + }, + ) + } + } + } } data class HomePageSettingsState( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e8980443f4..e091e68a24 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -513,6 +513,8 @@ Decrease size for all cards Use thumb images Settings saved + Display presets + Built-in presets to quickly style all rows Disabled From 9ea407f7f96528745e5845ea17752735bc6ebfa8 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Wed, 11 Feb 2026 22:30:47 -0500 Subject: [PATCH 53/53] Ensure changes are reflected when going back to home page --- .../damontecres/wholphin/services/HomeSettingsService.kt | 9 +++++++++ .../wholphin/ui/main/settings/HomeSettingsViewModel.kt | 3 +++ 2 files changed, 12 insertions(+) diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index f463c35112..a868692a20 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -239,6 +239,15 @@ class HomeSettingsService currentSettings.update { resolvedSettings } } + suspend fun updateCurrent(settings: HomePageSettings) { + val resolvedRows = + settings.rows.mapIndexed { index, config -> + resolve(index, config) + } + val resolvedSettings = HomePageResolvedSettings(resolvedRows) + currentSettings.update { resolvedSettings } + } + /** * Create a default [HomePageResolvedSettings] using the available libraries */ diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index c2e414e040..3a5f088a45 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -475,7 +475,10 @@ class HomeSettingsViewModel // Only save if there are changes if (local != settings) { homeSettingsService.saveToLocal(user.id, settings) + homeSettingsService.updateCurrent(settings) showSaveToast() + } else { + Timber.d("No changes") } } catch (ex: UnsupportedHomeSettingsVersionException) { Timber.w(ex, "Overwriting local settings")