mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 08:01:20 +02:00
Better restoration for auto sign in (#566)
## Description Improves how the app restores state when auto sign in is enabled. If auto sign in is enabled, the app will restore back to the last page. #538 altered the app start up logic. This caused the app to reset state more often when it goes into the background. ### Related issues Related to #552
This commit is contained in:
parent
bcc7e660ea
commit
b671e14826
6 changed files with 61 additions and 23 deletions
|
|
@ -46,9 +46,11 @@ class ServerRepository
|
|||
private var _current = EqualityMutableLiveData<CurrentUser?>(null)
|
||||
val current: LiveData<CurrentUser?> = _current
|
||||
|
||||
private var _currentUserDto = EqualityMutableLiveData<UserDto?>(null)
|
||||
val currentUserDto: LiveData<UserDto?> = _currentUserDto
|
||||
|
||||
val currentServer: LiveData<JellyfinServer?> get() = _current.map { it?.server }
|
||||
val currentUser: LiveData<JellyfinUser?> get() = _current.map { it?.user }
|
||||
val currentUserDto: LiveData<UserDto?> get() = _current.map { it?.userDto }
|
||||
|
||||
/**
|
||||
* Adds a server to the app database and updated the [ApiClient] to the server's URL
|
||||
|
|
@ -101,7 +103,8 @@ class ServerRepository
|
|||
}.build()
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
_current.value = CurrentUser(updatedServer, updatedUser, userDto)
|
||||
_current.value = CurrentUser(updatedServer, updatedUser)
|
||||
_currentUserDto.value = userDto
|
||||
}
|
||||
sharedPreferences.edit(true) {
|
||||
putString(SERVER_URL_KEY, updatedServer.url)
|
||||
|
|
@ -128,11 +131,21 @@ class ServerRepository
|
|||
serverDao.getServer(serverId)
|
||||
}
|
||||
if (serverAndUsers != null) {
|
||||
val user = serverAndUsers.users.firstOrNull { it.id == userId }
|
||||
if (user != null) {
|
||||
// TODO pin-related
|
||||
val current = _current.value
|
||||
if (current != null && current.server.id == serverId && current.user.id == userId) {
|
||||
Timber.v("Restoring session for current user, so shortcut")
|
||||
apiClient.update(
|
||||
baseUrl = current.server.url,
|
||||
accessToken = current.user.accessToken,
|
||||
)
|
||||
return current
|
||||
} else {
|
||||
val user = serverAndUsers.users.firstOrNull { it.id == userId }
|
||||
if (user != null) {
|
||||
// TODO pin-related
|
||||
// if (user != null && !user.hasPin) {
|
||||
return changeUser(serverAndUsers.server, user)
|
||||
return changeUser(serverAndUsers.server, user)
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
|
@ -271,5 +284,4 @@ class ServerRepository
|
|||
data class CurrentUser(
|
||||
val server: JellyfinServer,
|
||||
val user: JellyfinUser,
|
||||
val userDto: UserDto,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue