@@ -53,6 +53,8 @@ internal class HomeViewModel @Inject constructor(
5353 appSettingsCoordinator.update(setting = AppSettingValue .BiometricsRequired , value = false , fromUser = false )
5454 }
5555
56+ private var loginRequest: String? = null
57+
5658 fun handleLoginEntropy (
5759 entropy : String ,
5860 onSwitchAccount : () -> Unit ,
@@ -61,37 +63,53 @@ internal class HomeViewModel @Inject constructor(
6163 // If currently logged in, and the login request comes for a different account
6264 // present a confirmation dialog to switch accounts
6365 if (entropy != userManager.entropy) {
64- BottomBarManager .showMessage(
65- BottomBarManager .BottomBarMessage (
66- title = resources.getString(R .string.title_logoutAndLoginConfirmation),
67- subtitle = resources.getString(R .string.subtitle_logoutAndLoginConfirmation),
68- isDismissible = false ,
69- showCancel = true ,
70- showScrim = true ,
71- actions = buildList {
72- add(
73- BottomBarAction (
74- text = resources.getString(R .string.action_logIn),
75- onClick = {
76- viewModelScope.launch {
77- delay(150 ) // wait for dismiss
78- authManager.logoutAndSwitchAccount(entropy)
79- .onSuccess { onSwitchAccount() }
80- .onFailure {
81- BottomBarManager .showError(
82- title = resources.getString(R .string.error_title_failedToLogOut),
83- message = resources.getString(R .string.error_description_failedToLogOut),
84- )
85- }
86- }
66+ // debounce login request to ensure only one is present or handled at a time
67+ if (loginRequest != entropy) {
68+ loginRequest = entropy
69+ presentSwitchConfirmation(entropy, onSwitchAccount, onDismissed)
70+ }
71+ }
72+ }
73+
74+ private fun presentSwitchConfirmation (
75+ entropy : String ,
76+ onSwitchAccount : () -> Unit ,
77+ onDismissed : () -> Unit ) {
78+ BottomBarManager .showMessage(
79+ BottomBarManager .BottomBarMessage (
80+ title = resources.getString(R .string.title_logoutAndLoginConfirmation),
81+ subtitle = resources.getString(R .string.subtitle_logoutAndLoginConfirmation),
82+ isDismissible = false ,
83+ showCancel = true ,
84+ showScrim = true ,
85+ actions = buildList {
86+ add(
87+ BottomBarAction (
88+ text = resources.getString(R .string.action_logIn),
89+ onClick = {
90+ viewModelScope.launch {
91+ delay(150 ) // wait for dismiss
92+ authManager.logoutAndSwitchAccount(entropy)
93+ .onSuccess {
94+ onSwitchAccount()
95+ }
96+ .onFailure {
97+ BottomBarManager .showError(
98+ title = resources.getString(R .string.error_title_failedToLogOut),
99+ message = resources.getString(R .string.error_description_failedToLogOut),
100+ )
101+ }
87102 }
88- )
103+ }
89104 )
90- },
91- onClose = { onDismissed() }
92- )
105+ )
106+ },
107+ onClose = {
108+ loginRequest = null
109+ onDismissed()
110+ }
93111 )
94- }
112+ )
95113 }
96114
97115 private fun checkBiometrics () {
0 commit comments