mirror of
https://github.com/pachli/pachli-android.git
synced 2025-02-04 03:07:40 +01:00
59a0e3087c
Previous code assumed the active account could always be determined from the account manager. This causes a few problems. 1. The account manager has to handle the case where there is no active account (e.g., the user is logging out of the last account). This meant the `activeAccount` property had to be nullable, so every consumer of that property either used it with a `let` or `!!` expression. 2. The active account can change over the life of the UI component, for example, when the user is switching accounts. There's a theoretical race condition where the UI component has started an operation for one account, then the account changes and the network authentication code uses the new account. 3. All operations assume they operate on whatever the active account is, making it difficult to provide any features that allow the user to temporarily operate as another account ("Boost as...", etc). This "ambient account" was effectively global mutable state, with all the problems that can cause. Start to fix this. The changes in this commit do not fix the problem completely, but they are some progress. Each activity (except LoginActivity) is expected to be launched with an intent that includes the ID of the Pachli account it defaults to operating with. This is `pachliAccountId`, and is the *database ID* (not the server ID) of the account. This is non-null, which removes one class of bugs. This account is passed to each fragment and any piece of code that has to perform an operation on behalf of this account. It's not used in most of those places yet, that will be done over a number of followup PRs as part of modernising each module.