feat: Refactor account management to use SharedPreferences for last logged public key for immediate access
This commit is contained in:
@@ -93,21 +93,30 @@ fun UnlockScreen(
|
||||
)
|
||||
}
|
||||
|
||||
// Select account - prioritize: selectedAccountId > lastLoggedPublicKey > first account
|
||||
// Get last logged account from SharedPreferences (synchronous, reliable)
|
||||
val lastLoggedKey = accountManager.getLastLoggedPublicKey()
|
||||
|
||||
Log.d("UnlockScreen", "Loading accounts. selectedAccountId=$selectedAccountId, lastLoggedKey=$lastLoggedKey")
|
||||
Log.d("UnlockScreen", "Loading accounts. lastLoggedKey=$lastLoggedKey")
|
||||
Log.d("UnlockScreen", "Available accounts: ${accounts.map { "${it.name}:${it.publicKey.take(8)}" }}")
|
||||
|
||||
// Find the target account
|
||||
// Find the target account - prioritize selectedAccountId, then lastLoggedKey
|
||||
val targetAccount = when {
|
||||
selectedAccountId != null -> accounts.find { it.publicKey == selectedAccountId }
|
||||
lastLoggedKey != null -> accounts.find { it.publicKey == lastLoggedKey }
|
||||
else -> null
|
||||
selectedAccountId != null -> {
|
||||
Log.d("UnlockScreen", "Using selectedAccountId: $selectedAccountId")
|
||||
accounts.find { it.publicKey == selectedAccountId }
|
||||
}
|
||||
lastLoggedKey != null -> {
|
||||
Log.d("UnlockScreen", "Using lastLoggedKey: ${lastLoggedKey.take(8)}")
|
||||
accounts.find { it.publicKey == lastLoggedKey }
|
||||
}
|
||||
else -> {
|
||||
Log.d("UnlockScreen", "No lastLoggedKey, using first account")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
selectedAccount = targetAccount ?: accounts.firstOrNull()
|
||||
Log.d("UnlockScreen", "Selected account: ${selectedAccount?.name}:${selectedAccount?.publicKey?.take(8)}")
|
||||
Log.d("UnlockScreen", "Final selected: ${selectedAccount?.name}:${selectedAccount?.publicKey?.take(8)}")
|
||||
}
|
||||
|
||||
// Filter accounts by search
|
||||
@@ -136,8 +145,12 @@ fun UnlockScreen(
|
||||
// Auto-focus search when dropdown opens
|
||||
LaunchedEffect(isDropdownExpanded) {
|
||||
if (isDropdownExpanded) {
|
||||
kotlinx.coroutines.delay(200)
|
||||
searchFocusRequester.requestFocus()
|
||||
kotlinx.coroutines.delay(300)
|
||||
try {
|
||||
searchFocusRequester.requestFocus()
|
||||
} catch (e: Exception) {
|
||||
// FocusRequester may not be attached yet, ignore
|
||||
}
|
||||
} else {
|
||||
searchQuery = ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user