From 7345b0406193601bf357b0005a8f8eb2a3cb9711 Mon Sep 17 00:00:00 2001 From: Damontecres Date: Fri, 30 Jan 2026 17:52:41 -0500 Subject: [PATCH] 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 be7862de..0f8b7ee4 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 4e82ba0a..6cc0a197 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 0e3e2c7e..e2fc85f2 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,