mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
Fix crash
This commit is contained in:
parent
8c33738e31
commit
7345b04061
3 changed files with 26 additions and 20 deletions
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<HomePageSettingsState> = _state
|
||||
|
||||
private var idCounter by Delegates.notNull<Int>()
|
||||
|
||||
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue