Update system session when system user is modified

This commit is contained in:
Niels van Velzen
2021-07-13 22:15:35 +02:00
parent c51b92265d
commit c726cf73cb
2 changed files with 13 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package org.jellyfin.androidtv.ui.preference.category
import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.auth.AuthenticationRepository
import org.jellyfin.androidtv.auth.SessionRepository
import org.jellyfin.androidtv.preference.AuthenticationPreferences
import org.jellyfin.androidtv.preference.Preference
import org.jellyfin.androidtv.preference.constant.UserSelectBehavior
@@ -13,7 +14,8 @@ import org.jellyfin.sdk.model.serializer.toUUIDOrNull
fun OptionsScreen.authenticationCategory(
authenticationRepository: AuthenticationRepository,
authenticationPreferences: AuthenticationPreferences
authenticationPreferences: AuthenticationPreferences,
sessionRepository: SessionRepository,
) = category {
setTitle(R.string.lbl_settings)
@@ -38,7 +40,10 @@ fun OptionsScreen.authenticationCategory(
authenticationPreferences,
AuthenticationPreferences.systemUserBehavior,
AuthenticationPreferences.systemUserId
)
) {
// Update current system session
sessionRepository.restoreDefaultSystemSession()
}
}
}
}
@@ -50,6 +55,7 @@ private fun OptionsBinder.Builder<UserSelection>.from(
authenticationPreferences: AuthenticationPreferences,
userBehaviorPreference: Preference<UserSelectBehavior>,
userIdPreference: Preference<String>,
onSet: ((UserSelection) -> Unit)? = null,
) {
get {
UserSelection(
@@ -61,6 +67,8 @@ private fun OptionsBinder.Builder<UserSelection>.from(
set {
authenticationPreferences[userBehaviorPreference] = it.behavior
authenticationPreferences[userIdPreference] = it.userId?.toString().orEmpty()
onSet?.invoke(it)
}
default {

View File

@@ -2,6 +2,7 @@ package org.jellyfin.androidtv.ui.preference.screen
import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.auth.AuthenticationRepository
import org.jellyfin.androidtv.auth.SessionRepository
import org.jellyfin.androidtv.preference.AuthenticationPreferences
import org.jellyfin.androidtv.ui.preference.category.authenticationCategory
import org.jellyfin.androidtv.ui.preference.category.manageServersCategory
@@ -12,6 +13,7 @@ import org.koin.android.ext.android.inject
class AuthPreferencesScreen : OptionsFragment() {
private val authenticationRepository: AuthenticationRepository by inject()
private val authenticationPreferences: AuthenticationPreferences by inject()
private val sessionRepository: SessionRepository by inject()
init {
rebuildOnResume = true
@@ -20,7 +22,7 @@ class AuthPreferencesScreen : OptionsFragment() {
override val screen get() = optionsScreen {
setTitle(R.string.pref_authentication_cat)
authenticationCategory(authenticationRepository, authenticationPreferences)
authenticationCategory(authenticationRepository, authenticationPreferences, sessionRepository)
manageServersCategory(authenticationRepository)
}
}