Fix crash

This commit is contained in:
Damontecres 2026-01-30 17:52:41 -05:00
parent 8c33738e31
commit 7345b04061
No known key found for this signature in database
3 changed files with 26 additions and 20 deletions

View file

@ -265,9 +265,7 @@ class MainActivity : AppCompatActivity() {
server = current.server, server = current.server,
startDestination = startDestination =
requestedDestination requestedDestination
// TODO undo after testing ?: Destination.Home(),
// ?: Destination.Home(),
?: Destination.HomeSettings,
navigationManager = navigationManager, navigationManager = navigationManager,
preferences = preferences, preferences = preferences,
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),

View file

@ -199,18 +199,22 @@ class HomeSettingsService
// User local then server/remote otherwise create a default // User local then server/remote otherwise create a default
val settings = val settings =
try { try {
loadFromLocal(userId) val local = loadFromLocal(userId)
Timber.v("Found local? %s", local != null)
local
} catch (ex: Exception) { } catch (ex: Exception) {
Timber.w(ex, "Error loading local settings") Timber.w(ex, "Error loading local settings")
// TODO show toast? // TODO show toast?
null null
} ?: try { } ?: try {
loadFromServer(userId) val remote = loadFromServer(userId)
Timber.v("Found remote? %s", remote != null)
remote
} catch (ex: Exception) { } catch (ex: Exception) {
Timber.w(ex, "Error loading remote settings") Timber.w(ex, "Error loading remote settings")
null null
} }
val resolvedSettings = parseFromWebConfig(userId)!! val resolvedSettings =
if (settings != null) { if (settings != null) {
Timber.v("Found settings") Timber.v("Found settings")
// Resolve // Resolve

View file

@ -47,6 +47,7 @@ import org.jellyfin.sdk.model.serializer.UUIDSerializer
import timber.log.Timber import timber.log.Timber
import java.util.UUID import java.util.UUID
import javax.inject.Inject import javax.inject.Inject
import kotlin.properties.Delegates
@HiltViewModel @HiltViewModel
class HomeSettingsViewModel class HomeSettingsViewModel
@ -64,6 +65,8 @@ class HomeSettingsViewModel
private val _state = MutableStateFlow(HomePageSettingsState.EMPTY) private val _state = MutableStateFlow(HomePageSettingsState.EMPTY)
val state: StateFlow<HomePageSettingsState> = _state val state: StateFlow<HomePageSettingsState> = _state
private var idCounter by Delegates.notNull<Int>()
val discoverEnabled = seerrServerRepository.active val discoverEnabled = seerrServerRepository.active
init { init {
@ -82,6 +85,7 @@ class HomeSettingsViewModel
val currentSettings = val currentSettings =
homeSettingsService.currentSettings.first { it != HomePageResolvedSettings.EMPTY } homeSettingsService.currentSettings.first { it != HomePageResolvedSettings.EMPTY }
Timber.v("currentSettings=%s", currentSettings) Timber.v("currentSettings=%s", currentSettings)
idCounter = currentSettings.rows.maxOfOrNull { it.id }?.plus(1) ?: 0
_state.update { _state.update {
it.copy( it.copy(
libraries = libraries, libraries = libraries,
@ -190,7 +194,7 @@ class HomeSettingsViewModel
fun addRow(type: MetaRowType): Job = fun addRow(type: MetaRowType): Job =
viewModelScope.launchIO { viewModelScope.launchIO {
val id = state.value.rows.size val id = idCounter++
val newRow = val newRow =
when (type) { when (type) {
MetaRowType.CONTINUE_WATCHING -> { MetaRowType.CONTINUE_WATCHING -> {
@ -239,7 +243,7 @@ class HomeSettingsViewModel
rowType: LibraryRowType, rowType: LibraryRowType,
): Job = ): Job =
viewModelScope.launchIO { viewModelScope.launchIO {
val id = state.value.rows.size val id = idCounter++
val newRow = val newRow =
when (rowType) { when (rowType) {
LibraryRowType.RECENTLY_ADDED -> { LibraryRowType.RECENTLY_ADDED -> {
@ -288,7 +292,7 @@ class HomeSettingsViewModel
fun addFavoriteRow(type: BaseItemKind): Job = fun addFavoriteRow(type: BaseItemKind): Job =
viewModelScope.launchIO { viewModelScope.launchIO {
Timber.v("Adding favorite row for $type") Timber.v("Adding favorite row for $type")
val id = state.value.rows.size val id = idCounter++
val newRow = val newRow =
HomeRowConfigDisplay( HomeRowConfigDisplay(
id = id, id = id,