prevent the app from getting into an invalid state when old shortcuts are used (#3252)
This commit is contained in:
parent
07a4e97e9b
commit
ff79919d2a
1 changed files with 7 additions and 6 deletions
|
@ -45,9 +45,8 @@ class AccountManager @Inject constructor(db: AppDatabase) {
|
||||||
init {
|
init {
|
||||||
accounts = accountDao.loadAll().toMutableList()
|
accounts = accountDao.loadAll().toMutableList()
|
||||||
|
|
||||||
activeAccount = accounts.find { acc ->
|
activeAccount = accounts.find { acc -> acc.isActive }
|
||||||
acc.isActive
|
?: accounts.firstOrNull()?.also { acc -> acc.isActive = true }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -169,15 +168,17 @@ class AccountManager @Inject constructor(db: AppDatabase) {
|
||||||
*/
|
*/
|
||||||
fun setActiveAccount(accountId: Long) {
|
fun setActiveAccount(accountId: Long) {
|
||||||
|
|
||||||
|
val newActiveAccount = accounts.find { (id) ->
|
||||||
|
id == accountId
|
||||||
|
} ?: return // invalid accountId passed, do nothing
|
||||||
|
|
||||||
activeAccount?.let {
|
activeAccount?.let {
|
||||||
Log.d(TAG, "setActiveAccount: saving account with id " + it.id)
|
Log.d(TAG, "setActiveAccount: saving account with id " + it.id)
|
||||||
it.isActive = false
|
it.isActive = false
|
||||||
saveAccount(it)
|
saveAccount(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
activeAccount = accounts.find { (id) ->
|
activeAccount = newActiveAccount
|
||||||
id == accountId
|
|
||||||
}
|
|
||||||
|
|
||||||
activeAccount?.let {
|
activeAccount?.let {
|
||||||
it.isActive = true
|
it.isActive = true
|
||||||
|
|
Loading…
Reference in a new issue