Seen the following crash in user reports:
```
com.google.android.gms.common.api.ApiException: 17:
API: ModuleInstall.API is not available on this device.
Connection failed with:
ConnectionResult{statusCode=SERVICE_INVALID, resolution=null, message=null}
```
Doesn't appear to be properly documented anywhere I can find. To work
around this catch exceptions when checking for MLKit modules or
installing them and return defaults.
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.
Previous code didn't encode v2 filter keywords, so created v2 filters by
first creating the filter with no keywords (one API call) then making
1-N API calls to add each keyword to the filter.
Fix this by adding a dedicated converter for the `NewContentFilter` type
that encodes it correctly so the filter can be created with a single API
call.
This necessitates moving some types around,
It's possible for some servers to return a conversation that has an
empty (or possibly missing) `accounts` property. In the previous code
this would crash trying to access an item in an empty list.
Fix this by handling the "no participants" case.
Fixes#971
The new anti-harassment features will add several different types of
filtering options through the UI.
To ensure there is no confusion, rename the existing "Filters" UI and
code to "Content filters" to accurately describe what they operate on,
distinct from new filters which will act on account metadata.
Fixes#926.
Previously, tapping a tab would jump to the top of the loaded content,
which might trigger a load of a fresh page.
Provide a preference to control this; the default is the current
behaviour, the user can also choose to discard the current content and
load the newest content.
Fixes#939
Update `DownloadUrlUseCase` with a parameter to specify the account that
"owns" the media. This is either the account that posted the status, or
the account being viewed (e.g., if downloading an account's header
image).
Add a new `DownloadLocation` enum constant to download to directories
named after that account.
Pass this information through at the call sites.
Fixes#938
Provde an `appTheme` property in `SharedPreferenceRepository` to manage
read access, simplifying calling code.
Update `PreferenceEnum.from` to check the `value` property of the enum
first.
Fixes#950
The existing code downloaded any attachments to the user's "Downloads"
folder. If the user is logged in with several accounts these downloads
will be mixed up together.
Fix this by adding a new preference that allows the user to specify the
downloads should be placed in a sub-folder per account, named after the
account.
To do this:
- Add an interface for enums that can be used as preferences, with
properties for the string resource to display and the value to store.
- Add `EnumListPreference`, a `ListPreference` that allows the user to
choose between different enum values.
- Add a `DownloadLocation` enum and preference key so the user can
choose the location.
- Add a `core.domain` module, with a use case for downloading URLs that
respect's the user's download preference. Use this use-case everywhere
that files are currently downloaded.
Fixes#938
Previous code showed any JSON-wrapped errors from notification fetches
as the JSON string, instead of the error message.
Fix this by switching to `ApiResult` and using the formatted error
message.
Fixes 937
Previous code saved the reading position of a fully visible status. But
there are situations where no status is fully visible.
1. The user is in the middle of viewing a status longer than the screen
height, and the top/bottom of the status are off the top/bottom of the
screen.
2. The user has scrolled between two statuses. Collectively they are
longer than the screen height, and the top of one status is off the top
of the screen and the bottom of the other status is off the bottom of
the screen.
In both cases the user's reading position was not saved.
In these situations use the ID of the status closest to the bottom of
the screen, even if not fully visible. This should ensure the user never
missing anything.
Fixes#936
Previous code used `Response`. Convert to `ApiResult` as part of the
work to implement anti-harassment controls, which will need to query the
user's list of accounts they are following.
Converting just `accountFollowing` wasn't practical, as all the methods
are called by a single function in `AccountListFragment` which expects
the return type to be the same.
In rare occasions the preview card text could overlap the image if the
image had a portrait aspect ratio.
This seems to be due to the use of the `with(...) {}` scope function and
Kotlin's interoperability with Java setters.
Replace this with code that explicitly gets and sets the layout params
to ensure they are set correctly.
androidx.media3 1.4.0-rc01 and above (at the time of writing) has a bug
that breaks shared element transitions with a `PlayerView` (see
https://github.com/androidx/media/issues/1594).
This can be worked around by setting `app:surface_type="texture_view"`.
This uses more power, but for the typical length of social media videos
this shouldn't be a problem at the moment.
Fixes#920.
Previous code used `filterIsInstance<Ok<UploadEvent.FinishedEvent>>()`.
This can fail at runtime with class cast exception because the type in
`Ok<...>` is erased so `filterIsInstance` was accepting any `Ok`
`Result`. Later attempts to operate on it as a `.FinishedEvent`
generated the run time error.
Fix that by explicitly checking the type of the `Ok` result in `first`
instead.