Fix unnecessary home page reloads (#2008)
## Description Fixes the home page reloading from scratch when the app is resumed This happened because the `userDto` is updated on app resume and since it has a last accessed timestamp, it would always different and trigger a reload. ### Related issues Bug introduced by #1981 ### Testing Emulator ## Screenshots N/A ## AI or LLM usage None
This commit is contained in:
parent
365f8f8ada
commit
65954a99eb
9 changed files with 61 additions and 36 deletions
|
|
@ -6,6 +6,7 @@ import androidx.core.content.edit
|
|||
import androidx.datastore.core.DataStore
|
||||
import com.github.damontecres.wholphin.data.model.JellyfinServer
|
||||
import com.github.damontecres.wholphin.data.model.JellyfinUser
|
||||
import com.github.damontecres.wholphin.data.model.ServerUserConfig
|
||||
import com.github.damontecres.wholphin.preferences.AppPreferences
|
||||
import com.github.damontecres.wholphin.services.hilt.IoDispatcher
|
||||
import com.github.damontecres.wholphin.ui.toServerString
|
||||
|
|
@ -28,7 +29,6 @@ import org.jellyfin.sdk.api.client.extensions.quickConnectApi
|
|||
import org.jellyfin.sdk.api.client.extensions.systemApi
|
||||
import org.jellyfin.sdk.api.client.extensions.userApi
|
||||
import org.jellyfin.sdk.model.api.AuthenticationResult
|
||||
import org.jellyfin.sdk.model.api.UserDto
|
||||
import org.jellyfin.sdk.model.serializer.toUUIDOrNull
|
||||
import timber.log.Timber
|
||||
import java.time.ZonedDateTime
|
||||
|
|
@ -53,9 +53,9 @@ class ServerRepository
|
|||
private var _current = MutableStateFlow<CurrentUser?>(null)
|
||||
val current: StateFlow<CurrentUser?> = _current
|
||||
|
||||
private var _currentUserDto = MutableStateFlow<UserDto?>(null)
|
||||
val currentUserDto: UserDto? get() = _currentUserDto.value
|
||||
val currentUserDtoFlow: StateFlow<UserDto?> get() = _currentUserDto
|
||||
private var _currentUserDto = MutableStateFlow<ServerUserConfig?>(null)
|
||||
val currentUserDto: ServerUserConfig? get() = _currentUserDto.value
|
||||
val currentUserDtoFlow: StateFlow<ServerUserConfig?> get() = _currentUserDto
|
||||
|
||||
val currentServer: JellyfinServer? get() = _current.value?.server
|
||||
val currentServerFlow: Flow<JellyfinServer?> get() = _current.map { it?.server }
|
||||
|
|
@ -126,7 +126,7 @@ class ServerRepository
|
|||
val currentUser = CurrentUser(updatedServer, updatedUser)
|
||||
withContext(WholphinDispatchers.Main) {
|
||||
_current.value = currentUser
|
||||
_currentUserDto.value = userDto
|
||||
_currentUserDto.value = ServerUserConfig(userDto)
|
||||
}
|
||||
getServerSharedPreferences(context).edit(true) {
|
||||
putString(SERVER_URL_KEY, updatedServer.url)
|
||||
|
|
@ -319,7 +319,7 @@ class ServerRepository
|
|||
suspend fun updateUserDto() {
|
||||
val userDto by apiClient.userApi.getCurrentUser()
|
||||
_currentUserDto.update {
|
||||
if (it?.id == userDto.id && currentUser?.id == userDto.id) userDto else it
|
||||
if (it?.id == userDto.id && currentUser?.id == userDto.id) ServerUserConfig(userDto) else it
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package com.github.damontecres.wholphin.data.model
|
||||
|
||||
import org.jellyfin.sdk.model.api.UserConfiguration
|
||||
import org.jellyfin.sdk.model.api.UserDto
|
||||
import org.jellyfin.sdk.model.api.UserPolicy
|
||||
import org.jellyfin.sdk.model.serializer.toUUIDOrNull
|
||||
import java.util.UUID
|
||||
|
||||
/**
|
||||
* Server side configuration for a user, similar to [UserDto] but without the timestamps allowing for more reliable equals
|
||||
*/
|
||||
data class ServerUserConfig(
|
||||
val id: UUID,
|
||||
val name: String? = null,
|
||||
val serverId: UUID? = null,
|
||||
val configuration: UserConfiguration? = null,
|
||||
val policy: UserPolicy? = null,
|
||||
) {
|
||||
constructor(userDto: UserDto) : this(
|
||||
id = userDto.id,
|
||||
name = userDto.name,
|
||||
serverId = userDto.serverId?.toUUIDOrNull(),
|
||||
configuration = userDto.configuration,
|
||||
policy = userDto.policy,
|
||||
)
|
||||
|
||||
val tvAccess: Boolean get() = policy?.enableLiveTvAccess == true
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue