Make sure accounts are updated

This commit is contained in:
Luna712 2023-11-10 17:39:34 -07:00
parent 8f85aed7e8
commit ae669971c9
2 changed files with 23 additions and 1 deletions

View file

@ -323,6 +323,17 @@ object AccountHelper {
recyclerView.setLinearListLayout(isHorizontal = true)
val currentAccount = DataStoreHelper.accounts.firstOrNull {
it.keyIndex == DataStoreHelper.selectedKeyIndex
} ?: getDefaultAccount(activity)
// We want to make sure the accounts are up-to-date
viewModel.handleAccountSelect(
currentAccount,
activity,
reloadForActivity = true
)
activity.observe(viewModel.accounts) { liveAccounts ->
recyclerView.adapter = AccountAdapter(
liveAccounts,

View file

@ -89,8 +89,19 @@ class AccountViewModel : ViewModel() {
fun handleAccountSelect(
account: DataStoreHelper.Account,
context: Context,
forStartup: Boolean = false
forStartup: Boolean = false,
reloadForActivity: Boolean = false
) {
if (reloadForActivity) {
val currentAccount = DataStoreHelper.accounts.firstOrNull {
it.keyIndex == DataStoreHelper.selectedKeyIndex
}
_accounts.postValue(getAccounts(context))
_selectedKeyIndex.postValue(getAccounts(context).indexOf(currentAccount))
return
}
// Check if the selected account has a lock PIN set
if (account.lockPin != null) {
// The selected account has a PIN set, prompt the user to enter the PIN