Commit Graph

48 Commits

Author SHA1 Message Date
Nik Clayton d39eb3b642
refactor: Extract PreviewCard display code to `PreviewCardView` (#184) 2023-10-19 12:54:58 +02:00
Nik Clayton db2bd3199e
refactor: Create repositories for preferences and StatusDisplayOptions (#149)
Previously, code for handling shared preferences, and how those
preferences affect `StatusDisplayOptions`, was scattered through the
code base with duplicate implementations.

Bring it together in to a `SharedPreferencesRepository` and a
`StatusDisplayOptionsRepository`.

`SharedPreferencesRepository` is a thin wrapper over`SharedPreferences`
that delegates most work to `SharedPreferences`. It configures a
listener for preference changes, and exposes those changes as a flow.

`StatusDisplayOptions` now contains explicit defaults to ensure they
are in one place.

`StatusDisplayOptionsRepository` exposes a `StatusDisplayOptions` flow
that updates whenever the active account changes or a relevant
preference changes.

The viewmodels expose `StatusDisplayOptionsRepository.flow` to the
activities and fragments so they can pass the current value to the
adapter.

This obsoletes `PreferenceChangedEvent`. An event is still fired when
filters change, `FilterChangedEvent`.

This allowed many of the mocks in tests to be replaced with either the
real type (because a fake is injected in to it, or one of its
dependencies) or a custom fake that provides a mock.
2023-10-15 22:52:47 +02:00
Nik Clayton c50f10a989
refactor: Extract Poll display code to `PollView` (#177) 2023-10-15 22:26:34 +02:00
Nik Clayton 71df6254ef
fix: Show thread indicators and other dividers using Material colours (#157)
Use the Material colour for `conversation_thread_line` (which is
`colorOutlineVariant`) instead of a custom attribute.

Elsewhere, use the Material attribute directly (in code), or replace the
custom divider with a `MaterialDivider`.

This makes some colour definitions unused, so remove them.

Fixes #148
2023-10-13 11:36:05 +02:00
Nik Clayton 53e7842439
change: Increase compileSdk and targetSdk to 34 (#150)
Associated changes:

- Handle new null/non-null type signatures in overriden methods
- Configure Robolectric to use SDK 33 (current highest supported
version)
2023-10-11 12:28:45 +02:00
Nik Clayton 38214648dd
refactor: Migrate from Dagger to Hilt (#143)
- Remove `Injectable` interface, use `@AndroidEntryPoint`
- Remove `DispatchingAndroidInjector`
- Remove `viewModelFactory`, use `@HiltViewModel`
- Create providers for the different DAOs, and inject those instead of
  `AppDatabase`
- Create provider for a database transaction, inject that instead of
  `AppDatabase`
- Update tests
2023-10-07 19:30:11 +02:00
Nik Clayton 802cdd4c46
feat: Embed the privacy policy in the app (#139)
Instead of linking to the privacy policy embed it in the app as a string
of HTML.

The string is created with a new `markdown2resource` plugin, which
converts `PRIVACY.md` to HTML and generates a Java class with the HTML
content.

Create `PrivacyPolicyActivity` to display the HTML in a `WebView`, and
link to it from `AboutActivity`.
2023-10-03 12:56:30 +02:00
Nik Clayton 651b0efcd6
feat: Link to the privacy policy from "About" (#137)
Google requires an in-app link to the privacy policy.
2023-09-30 13:15:44 +02:00
Nik Clayton 6fedfe54ba
fix: Restore the user's reading position under all circumstances (#133)
The previous code did not always work when the user returned to the app
after a lengthy absence (e.g., overnight).

Instead of restoring by scrolling in `TimelineFragment`, restore by
working with the platform.

Determine the initial page to fetch by looking half a page ahead of the
saved saved status ID, and fetch that status and the page immediately
prior. This seems to match the view's expectations about what will be
immediately available.

Set `jumpThreshold` and `enablePlaceholders` in the `PagingConfig` so
the paging system will jump to the saved status.

Remove the restoration code in `TimelineFragment`.

Fixes #53
2023-09-29 11:10:55 +02:00
Nik Clayton 50d9aedad9
chore(deps): Update to AGP 8.1.1 (#130) 2023-09-27 18:06:14 +02:00
Nik Clayton 11fecb1914
feat: Show vertical scrollbars on scrollable lists (#96)
Display normal Android (i.e., fading) scrollbars when the user scrolls
in lists.
2023-09-26 15:57:35 +02:00
Nik Clayton af7b668476
fix: Enable/disable vote button when the user can/can't vote (#91)
Previously the voting button was always enabled, even if the user hadn't
made a choice.

Disable the button by default, and listen for clicks on the options.
Enable the button whenever one or more options are selected.

Fixes #90
2023-09-23 21:01:33 +02:00
Nik Clayton 2169c91281 fix: Ensure `setLifeOnScrollTargetView` is called when fragment resumes
If you do not do this and the fragment is in a pager then it can be
overridden when another fragment is swiped in to view.
2023-09-23 16:21:05 +02:00
Nik Clayton f45a3df83f refactor: Use resource strings on the hashtag toolbar menu 2023-09-20 19:05:35 +02:00
Nik Clayton f9e5063ce6 fix: Label the header and avatar on the account screen 2023-09-20 19:05:35 +02:00
Nik Clayton 2bcb595777 fix: Label the image on the focus dialog 2023-09-20 19:05:35 +02:00
Nik Clayton 254edf5e6f refactor: Mark the image overlay is not important for accessibility 2023-09-20 19:05:35 +02:00
Nik Clayton 0fadb6f3fd fix: Set the contentDescription for avatars 2023-09-20 19:05:35 +02:00
Nik Clayton acaf2a7d89 refactor: Remove warnings about unclosed resources
In `MediaUploader` the lint warning can be ignored, as the stream is
closed elsewhere.

In the other files `.use` is used to simplify the code and remove
the need for Closeable.closeQuietly (as `.use` catches exceptions that
are thrown when closing).
2023-09-20 19:05:35 +02:00
Nik Clayton d00dc97a5f refactor: Suppress an unncessary CheckResult lint error
The result is used, lint isn't smart enough to figure that out.
2023-09-20 19:05:35 +02:00
Nik Clayton 9de829995b
fix: Check permissions before sending a failure notification (#77) 2023-09-19 22:18:17 +02:00
Nik Clayton 0f6975ffcc
fix: Check build version is >= T before POST_NOTIFICATIONS request (#76) 2023-09-19 22:04:42 +02:00
Nik Clayton 0bf459d385
refactor: Use "compat" drawables where appropriate (#72)
Use AppCompatResources.getDrawable() and app:drawableStartCompat.
Resolves existing lint issues.
2023-09-19 17:42:20 +02:00
Nik Clayton c97c3a4156
refactor: Add @NonNull and @Nullable annotations where appropriate (#71)
Adding the annotations cleans up an entire class of lint errors, and
it will be easire to convert from Java to Kotlin later.
2023-09-19 17:17:31 +02:00
Nik Clayton f4e14dcf44
fix: Restore the user's reading position in more circumstances (#49)
The previous code only attempted to restore the user's reading position
once, after any initial refresh.

Adjust this so the position is restored after any refresh (which may
have been triggered from a menu instead of a swipe), and use
`scrollToPositionWithOffset` to ensure it's visible.
2023-09-15 16:09:18 +02:00
Nik Clayton 7bb1e6fe17
change: Restore dividers between list items (#45)
Switching to the Material 3 themes caused the previous list dividers to
disappear.

Replace `DividerItemDecoration` with `MaterialDividerItemDecoration` to
restore them.
2023-09-14 19:10:59 +02:00
Nik Clayton ec66942ae9
fix: Show the FAB according to the user's preferences (#29)
The previous code didn't collect the uiState, so it was fixed at the
default value, ignoring any changes that happened over the life of
the viewmodel.

Fix that, so that the FAB will hide/show on scroll according to the
user's preferences.

While I'm here simplify the show/hide logic. The previous code would
ignore the user's preference if scrolling up. There doesn't seem to
be a good reason for that, and spelunking 6+ years back through the
history didn't find a justification for that behaviour in the original
commit.

Fixes #15
2023-09-11 21:19:45 +02:00
Nik Clayton ecd81e80b0
fix: Fix toolbar flickering when scrolling lists (#26)
Scrolling a thread, set of search results, or viewing a thread would
cause the toolbar to flicker as items moved under it.

Fix this by configuring the toolbar to `liftOnScroll` in the relevant
layouts.

It needs to be configured with the view (or ID of the view) that it
will be scrolling. For views that are in the same layout this is done
with the `liftOnScrollTargetViewId` attribute.

For views that are in different layouts (e.g. the toolbar is in
the activity and the scrolling view is in a fragment) the app bar's
`setLiftOnScrollTargetView` method must be called.

Do this in `TimelineFragment` if the hosting activity is a new
interface `AppBarLayoutHost`. Implement this interface in
`StatusListActivity`.

Update the relevant layouts to use `MaterialToolbar`.

Fixes #21
2023-09-11 17:48:42 +02:00
Nik Clayton 811856a3b6
fix: Fix crash on entering MainActivity on Pixel C devices (#25)
First crash appeared to be caused by a failure to find the
`attr/colorBackgroundAccent` colour from the theme.

It wasn't clear why the attribute could not be found, so to fix it was
simpler to remove the color and attribute entirely, and replace it with
something more appropriate from the Material 3 tokens.

- Preview cards are stroked with `colorOutline`
- Poll options use `colorPrimary` (user's vote) or `colorSecondary`
  (other choices) with appropriate text colours.
- Links in link preview cards use `android:attr/textColorLink`
- The placeholder icon in preview cards uses `?android/textColorLink`
- Remove it from `help_message_background`, and stroke with
  `?colorOutline`

Doing this I discovered several places where a colour was being
specified unnecessarily, those have been removed.

To make it easier to understand the theme hierarchy that has been
collapsed and renamed to follow Android conventions.

- AppTheme -> Base.Theme.Pachli
- BaseTheme -> Theme.Pachli
- DefaultTheme has been removed as unnecessary

This unearthed a second crash, where `attr/actionBarSizeWithSubtitle`
was not found.

To fix that create an explicit style for toolbars that need it, and
apply the style (`Pachli.Widget.Toolbar`).

This also surfaced a third problem, where the `fragment_timeline*`
layouts had not been updated in `layout-sw640dp`, so those have been
updated to reflect the same views/IDs as the default `fragment_timeline`
layout.

These changes caused a small chain of "unused resource" lint errors,
which have been fixed by removing the unused colours.

The Android Material libraries were also being implicitly depended on
through other library imports instead of being explicit. So include
them as an explicit dependency.

Fixes #18
2023-09-11 13:54:29 +02:00
Nik Clayton 4879f0449f
docs: Add a privacy policy (#2)
While drafting the policy I noticed that the `READ_MEDIA_*` permissions
could be added (for newer devices), the `ACCESS_NETWORK_STATE`
permission was missing, and `VIBRATE` was unnecessary.
2023-09-05 15:35:06 +02:00
Nik Clayton 1bf13b10f8
refactor: Transition from Tusky to Pachli
- Rename packages to app.pachli.*
- Switch to Pachli icons (blue / orange)
- Reset database schema version to 1
- Reset versionCode to 1 and versionName to "1.0"
- Update colour scheme, use colorPrimary etc through the app
- Use Material UI components for toolbars
- Use "Pachli" in strings (UI, constants, etc)
- Update copyright on code I contributed
- Update README
- Update fastlane metadata
2023-09-05 13:33:37 +02:00
Nik Clayton a441576bf6
style: Require trailing comma, and break lines
Requiring trailing commas on multi-line lists of items (declarations
and call sites) reduces future repository churn when those lines are
changed, but introduces additional churn now.

Bite the bullet and make the change, as well as adjusting lines that
were too long / indented incorrectly.

The changes were performed automatically, using the `ktlintFormat` task.

Based on https://github.com/tuskyapp/Tusky/pull/3968 by
https://github.com/tinsukE
2023-09-04 20:22:10 +02:00
Nik Clayton fc2a830ea1
feat: Remove explicit "Load more", load on demand
Prior to this change the user had to repeatedly tap "Load more" when
scrolling. This is tedious for the user.

In addition, the previous code had bugs that meant that not all statuses
were being loaded. Users could leave the app for a while (overnight,
say), and when returning would discover far fewer statuses than had
actually been posted.

Fix this, following the architecture first introduced for notifications
(Fragment -> ViewModel -> Repository -> Source/Mediator).

- Load statuses for cached and non-cached timelines using Paging3
- Show Failures during a load, and the user can retry
- Delete the "Reading order" preference, it is no longer necessary
2023-09-04 20:22:08 +02:00
Nik Clayton 6539146b58
feat: Allow the user to choose a different font
Android's choices for font customisation can be limited, depending on
the vendor. Allow users to choose from a small collection of embedded
fonts, chosen by asking users for recommendations.

The font choice is implemented as a preference. Provide a custom dialog
that shows the fonts (in that font) so the user can see what they're
choosing between.

Ensure the font's license information is displayed in the "About"
section.
2023-09-04 20:22:07 +02:00
Nik Clayton dfc16c0351
fix: Ensure third party code is properly credited
The previous code did not credit all third party code used in the app,
or provide access to the licenses.

Fix this by adopting the "aboutlibraries" library, which processes
dependencies at build time and generates a list of dependencies,
versions, and license information to display to the user.

Use this to also ensure that the non-source dependencies (artwork,
emoji) are given appropriate credit.
2023-09-04 20:22:07 +02:00
Nik Clayton 369979a60e
feat: Allow the user to specify an arbitrary number of tabs
- Remove the existing restriction on the number of tabs
- Allow the tabs to scroll to display more
- Update UI and text resources to remove obsolete content
2023-09-04 20:22:05 +02:00
Nik Clayton b6102a755a
Rename "Trending" to "TrendingTags" or similar where necessary (#3906)
The "trending" functionality will expand to include trending links and
posts. But at the moment the "Trending" references in the code are
exclusively to hashtags.

Rename "Trending" to "TrendingTags" or similar everywhere necessary in
order to prepare for this.

This includes a database migration, as the identifier for the "Trending
tags" tab in the account preferences was changed from "Trending" to
"TrendingTags". The migration updates the stored value if necessary.
2023-08-19 12:54:35 +02:00
Konrad Pozniak dc9e9f2aeb
Improve account switching intents (#3732)
Before, intent creation was scattered across multiple sites, with account switching logic in both `ComposeActivity` and `MainActivity`.

Now, intents are only created in `MainActivity` Companion, and account switching only occurs in `MainActivity`

Fixes #3695
2023-08-19 12:31:47 +02:00
UlrichKu cb8a09d3f7
Officially rename error elephant to errorphant (#3922)
In honor of
https://strangeobject.space/@esther/109866090382540100
https://masto.ai/@mynotaurus/110826349670549779
2023-08-05 15:39:07 +02:00
Nik Clayton 30be3ce1f0
Use lint version 8.1.0 to fix erroneous warning about forEach (#3903)
Android lint was erroneously warning that the forEach construct in
Kotlin required API 24+, which is incorrect, see
https://issuetracker.google.com/issues/185418482.

Work around that by forcing the Android lint version to 8.1.0.

This triggered some additional checks, which have been ignored, and a
new baseline.
2023-07-30 21:45:43 +02:00
Nik Clayton 121db1713d
Fix lint issues in AppDatabase.java (#3809) 2023-07-06 19:37:51 +02:00
Nik Clayton 1f7a5f626d
Show notifications from workers (#3760)
Fix a crash where workers, in some conditions, should show a notification. These are sent to a dedicated channel with no importance.

Convert NotificationWorker to a CoroutineWorker and remove its use of `runBlocking`.

Fixes #3754
2023-06-29 18:37:27 +02:00
Konrad Pozniak 85b7caa887
Replace deprecated getParcelable* methods with compat versions (#3633) 2023-06-11 12:58:55 +02:00
Konrad Pozniak f23c0cc634
Refactor "trending hashtags" code (#3595)
- Fix codeformatting
- Add new refreshing state
- Disable LogConditional lint rule
- Update lint-baseline
2023-06-10 19:47:07 +02:00
Nik Clayton c154aaa17d
Ignore LogConditional issues (#3615)
Logs are stripped in release builds, this is an unnecessary lint
2023-05-04 14:50:21 +02:00
Nik Clayton 168be9223d
Disable lint checks for unused resource IDs (#3557)
* Disable lint checks for unused resource IDs

The check doesn't catch some instances where resources are used through viewbinding, and has too many false positives to be useful.

* Regenerate lint baseline

Delete the existing file, then regenerated with `.\gradlew lintBlueDebug -Dlint.baselines.continue=true`
2023-04-24 09:20:03 +02:00
Konrad Pozniak 3d71b6e69a
add lint to ci checks (#3462)
* add lint to ci checks

* update lint baseline
2023-03-21 18:56:11 +01:00
Nik Clayton 3ff8f73246
Enforce lint cleanliness when building (#3363)
* Enforce lint cleanliness when building

The volume of lintable issues is growing. To stem the tide:

1. Add `app/lint-baseline.xml`, which contains the current set of lint issues.
   Any issue appearing here will not cause the build to fail.

2. Move lint configuration settings in to `lint.xml`.

3. Update the lint configuration so that any issue (i.e., any issue not
   in lint-baseline.xml) causes a build failure.

4. Add the lint tasks as depedency when assembling an APK, to ensure the
   lint checks are run.

* lint: Convert launcher images to webp

* Move lint.xml location

* Don't lint when assembling

* Update baseline
2023-03-13 10:23:42 +01:00