mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-06-13 19:30:57 +02:00
Fix account switching
This commit is contained in:
parent
269197a59d
commit
f34d79106d
@ -83,6 +83,10 @@ object LocalPreferences {
|
|||||||
addAccount(npub)
|
addAccount(npub)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun switchToAccount(npub: String) {
|
||||||
|
currentAccount = npub
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the account from the app level shared preferences
|
* Removes the account from the app level shared preferences
|
||||||
*/
|
*/
|
||||||
|
@ -86,7 +86,7 @@ fun AccountSwitchBottomSheet(
|
|||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.clickable {
|
modifier = Modifier.clickable {
|
||||||
accountStateViewModel.login(acc.npub)
|
accountStateViewModel.switchUser(acc.npub)
|
||||||
},
|
},
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
|
@ -55,6 +55,12 @@ class AccountStateViewModel() : ViewModel() {
|
|||||||
login(account)
|
login(account)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun switchUser(npub: String) {
|
||||||
|
prepareLogoutOrSwitch()
|
||||||
|
LocalPreferences.switchToAccount(npub)
|
||||||
|
tryLoginExistingAccount()
|
||||||
|
}
|
||||||
|
|
||||||
fun newKey() {
|
fun newKey() {
|
||||||
val account = Account(Persona())
|
val account = Account(Persona())
|
||||||
LocalPreferences.updatePrefsForLogin(account)
|
LocalPreferences.updatePrefsForLogin(account)
|
||||||
@ -86,7 +92,7 @@ class AccountStateViewModel() : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun logOff(npub: String) {
|
private fun prepareLogoutOrSwitch() {
|
||||||
val state = accountContent.value
|
val state = accountContent.value
|
||||||
|
|
||||||
when (state) {
|
when (state) {
|
||||||
@ -104,7 +110,10 @@ class AccountStateViewModel() : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_accountContent.update { AccountState.LoggedOff }
|
_accountContent.update { AccountState.LoggedOff }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun logOff(npub: String) {
|
||||||
|
prepareLogoutOrSwitch()
|
||||||
LocalPreferences.updatePrefsForLogout(npub)
|
LocalPreferences.updatePrefsForLogout(npub)
|
||||||
tryLoginExistingAccount()
|
tryLoginExistingAccount()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user