Skip to content
Merged
4 changes: 3 additions & 1 deletion .claude/skills/project-architecture/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ XAML referencing a Core type needs `;assembly=AniSprinkles.Core` on the `clr-nam

| Registration | Lifetime |
| ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| `ErrorReportService`, `HttpClient`, `IAuthService`, `IAniListClient`, `IAiringNotificationService`, `IOutageStateService`, `INavigationService`, `IUserFeedback`, `IDialogService`, `IExternalBrowser`, `ListEntryStatusFlow` | Singleton |
| `ErrorReportService`, `HttpClient`, `IAuthService`, `IAniListClient`, `IAiringNotificationService`, `IOutageStateService`, `INavigationService`, `IUserFeedback`, `IDialogService`, `IExternalBrowser`, `ISecureTokenStorage`, `TokenStore`, `ListEntryStatusFlow` | Singleton |
| `IPreferences`, `IAppInfo`, `TimeProvider` (`TryAddSingleton` — MAUI exposes the first two only as statics, so DI has no default) | Singleton |
| `MyAnimePageModel`, `DiscoverPageModel`, `SearchPageModel`, `SettingsPageModel` | **Singleton** (survive page recreation across tab switches) |
| `LoggingHandler`, `AniListRateLimitHandler` | Transient |

`AuthService` keeps only the platform half of auth — the `WebAuthenticator` round trip and the Android WebView cookie store — and delegates token state to Core's `TokenStore`, which owns the in-memory token, single-flights the first read of `ISecureTokenStorage`, and answers `Absent` / `Expired` / `Valid` (#119). `TokenStore` must stay singleton: a transient one would give every caller its own gate and its own copy, which is the race it exists to fix.

`IAniListClient` resolves to `CachingAniListClient` wrapping the concrete `AniListClient` (session-lifetime in-memory cache of character/staff reads, with request coalescing). The shared `HttpClient` pipeline is `AniListRateLimitHandler` → `LoggingHandler` → `HttpClientHandler`, so every AniList call is serialized and 429/`Retry-After`-aware app-wide.
| `MyAnimePage`, `DiscoverPage`, `SearchPage`, `FeedPage`, `MyMangaPage`, `SettingsPage`, `MediaDetailsPageModel`, `MediaDetailsPage`, `StaffDetailsPageModel`, `StaffDetailsPage`, `CharacterDetailsPageModel`, `CharacterDetailsPage`, `StudioDetailsPageModel`, `StudioDetailsPage`, `MediaBrowsePageModel`, `MediaBrowsePage` | Transient |

Expand Down
21 changes: 19 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dotnet test tests/AniSprinkles.UnitTests/AniSprinkles.UnitTests.csproj -c Debug
- **CI**: GitHub Actions `android-release.yml` triggers on Release publication (or manual `workflow_dispatch`). `promote-release.yml` promotes between Play Console tracks (internal → alpha → beta → production).
- **Version scheme**: `ApplicationDisplayVersion` from release tag semver (`vX.Y.Z` → `X.Y.Z`); `ApplicationVersion` (versionCode) from `YYMMDDNNN` (date + run_number mod 1000).
- **Unit tests** — `tests/AniSprinkles.UnitTests/` (xUnit, `net10.0`, NSubstitute). Project-references `src/AniSprinkles.Core/`; there are no link-compile globs any more (#62). Covers pure algorithms, PageModel state machines, and repo-level file validation (`.xaml` well-formedness, icon-glyph resolution). Test doubles live in `Fakes/`. `tests/AniSprinkles.UITests/` is still a scaffold for future device tests.
- **Watch what throws vs. what returns null off-device.** On the plain `net10.0` TFM, `Shell.Current` and `Application.Current` are `null` (a quiet no-op that reads as a passing test), while `Preferences`, `MainThread`, `AppInfo` and `Browser` throw `NotImplementedInReferenceAssemblyException`. Anything a test needs to reach must be injected.
- **Watch what throws vs. what returns null off-device.** On the plain `net10.0` TFM, `Shell.Current` and `Application.Current` are `null` (a quiet no-op that reads as a passing test), while `Preferences`, `SecureStorage`, `MainThread`, `AppInfo` and `Browser` throw `NotImplementedInReferenceAssemblyException`. Anything a test needs to reach must be injected — `SecureStorage` behind `ISecureTokenStorage` (#119) is the most recent example.
- **Fixing a bug starts with a failing test.** Write the test that reproduces the reported behaviour, run it, and watch it fail *for the reason you expect*, before touching the fix. A test written after the fix proves the code passes its own description — it does not prove it would have caught the bug, and a test that never failed is indistinguishable from one asserting the wrong thing. If the bug genuinely cannot be reached from `tests/` (see what throws off-device, above), say so explicitly and verify on device via `/run-anisprinkles` instead — don't quietly skip the step.
- `AppSettings.Load/Save/Clear/SyncFromViewer` go through the injectable `AppSettings.Storage` seam (#121), so paths ending in them — a successful `SettingsPageModel.LoadAsync`, for instance — are testable. `TestDataBuilder.ResetAppSettings()` installs a `FakePreferences` and returns it.
- Test classes that write to the process-wide `AppSettings` statics must join the `AppSettings` collection (`AppSettingsCollection.Name`) so they do not run in parallel. That includes `AppSettings.Storage`.
Expand All @@ -76,6 +76,18 @@ These stubs are **compiled out entirely** in standard Debug and Release builds.

The project must build with **zero warnings**. Do not introduce new warnings; fix any that appear before committing. CA1822 ("member can be static") is suppressed project-wide in `.editorconfig` — MAUI `{Binding}` requires instance members even when they only read static state, so the analyzer produces false positives.

**"Zero warnings" means every project, and the test project is the one that gets missed.** Building `src/AniSprinkles/AniSprinkles.csproj` does not compile `tests/`, and `dotnet test` output filtered for failures hides warnings entirely — which is how 15 `xUnit1051` warnings reached a PR while the app builds were reported clean. `xUnit1051` in particular fires on any `await` of a method taking a `CancellationToken`: pass `TestContext.Current.CancellationToken`. Check all five before pushing:

```powershell
dotnet build tests/AniSprinkles.UnitTests/AniSprinkles.UnitTests.csproj -c Debug
dotnet build src/AniSprinkles.Core/AniSprinkles.Core.csproj -c Debug
dotnet build src/AniSprinkles/AniSprinkles.csproj -c Debug -f net10.0-android
dotnet build src/AniSprinkles/AniSprinkles.csproj -c Debug -f net10.0-android -p:EmbedAssembliesIntoApk=true -p:CiBuild=true
dotnet build src/AniSprinkles/AniSprinkles.csproj -c Debug -f net10.0-android -p:ErrorSim=true
```

**A green local suite is not a green suite.** Test classes writing to the process-wide `AppSettings` statics share one collection, so failures that depend on *ordering within* it surface on CI and not here — #128's pending-upstream markers leaked between tests exactly that way, passing locally every run. `TestDataBuilder.ResetAppSettings()` goes through `AppSettings.Clear()` so those markers reset; **new process-wide state must be reset there too**, or it poisons whichever test happens to run next.

## Project Conventions

- **MAUI-first guidance**: do not mix WPF/Xamarin.Forms/Blazor/React patterns unless explicitly requested. Verify MAUI APIs against official Microsoft docs and current project code before recommending.
Expand All @@ -84,7 +96,12 @@ The project must build with **zero warnings**. Do not introduce new warnings; fi
- Exception: `Platforms/Android/MainActivity.cs` and `Platforms/Android/AiringCheckWorker.cs` call `Android.Util.Log` directly because they run before the MAUI DI container is guaranteed to be built (activity lifecycle callbacks; post-reboot WorkManager). Inline comments document this at the call sites. Do not introduce new direct-`Android.Util.Log` callers elsewhere — use ILogger.
- On-device log file: `{AppDataDirectory}/logs/anisprinkles.log` (+ `.1`, `.2` archives). Pull via `adb shell run-as com.RainbowSprinkles.AniSprinkles cat files/logs/anisprinkles.log` or use `/ani-debug`.
- **Telemetry**: Sentry crash reporting only (`SendDefaultPii = false`, `TracesSampleRate = 0.0`, plus a `BeforeSend` redaction pass — `SendDefaultPii` governs IP/username, not message content). Use `ErrorReportService.Record()` for handled exceptions.
- **User prefs**: `AppSettings` (static, `Utilities/`) persists title language, score format, adult content toggle, and section order through the injectable `AppSettings.Storage` seam, which defaults to `Preferences.Default` (#121). `DisplayAdultContent` commits the instant the Settings toggle flips via `SetDisplayAdultContent`, ahead of the debounced AniList save (#118) — every browse surface filters on it and only re-checks when it appears, so a late commit left 18+ results on screen. Paging must be pinned to the value its page 1 was seeded under (`_seededDisplayAdult` in `SearchPageModel`, `DiscoverPageModel` and `MediaBrowsePageModel`; passed into `DiscoverSectionFetch.PageAsync`) rather than re-reading the static per page, or one result set can hold two policies. All four surfaces — Library included — compare it against the value their current data was built with. A locally committed change outranks the server's copy until the server reports that same value back, so neither a refresh elsewhere in the app nor a return to Settings can sync the pre-change value over it; `SettingsPage.OnDisappearing` flushes any pending save so the server catches up promptly.
- **User prefs**: `AppSettings` (static, `Utilities/`) persists title language, score format, adult content toggle, and section order through the injectable `AppSettings.Storage` seam, which defaults to `Preferences.Default` (#121). `DisplayAdultContent` commits the instant the Settings toggle flips via `SetDisplayAdultContent`, ahead of the debounced AniList save (#118) — every browse surface filters on it and only re-checks when it appears, so a late commit left 18+ results on screen. Paging must be pinned to the value its page 1 was seeded under (`_seededDisplayAdult` in `SearchPageModel`, `DiscoverPageModel` and `MediaBrowsePageModel`; passed into `DiscoverSectionFetch.PageAsync`) rather than re-reading the static per page, or one result set can hold two policies. All four surfaces — Library included — compare it against the value their current data was built with. Title language and score format commit the same way, via `SetTitleLanguage` / `SetScoreFormat` (#128); before that they reached `AppSettings` only once a save had succeeded. A locally committed change outranks the server's copy until the server reports that same value back — for all three now, not just the adult toggle — so neither a refresh elsewhere in the app nor a return to Settings can sync the pre-change value over it; `SettingsPage.OnDisappearing` flushes any pending save so the server catches up promptly. The settings the Settings page holds on its own (staff name language, restrict-messages, activity merge time, airing notifications, and the per-type notification toggles) carry the same markers there — the per-type ones as a set of unconfirmed types, so a change made on another device still arrives for every type the user did not touch. `AnimeSectionOrder` deliberately has none — there is no control for it, so it can only come from the server.
- **The airing job follows the toggle both ways.** `PopulateFromUser` schedules the WorkManager check when airing notifications land on, and cancels it when they land off. Only the enabling half was wired originally, so turning the setting off anywhere else — the AniList website, another device — left this device still scheduled, and the switch read off while notifications kept arriving. Cancelling an unscheduled job is a no-op, so the else-branch is safe on every load.
- **Pushed detail pages get no lifecycle on a tab return.** `OnAppearing` / `OnDisappearing` fire on tab-*root* pages (Library, Discover, Search, Settings) when you switch tabs, but **not** on a page pushed onto a backgrounded tab's navigation stack — the four detail pages and View All (`AppShell.xaml.cs:23-27`). Verified on device: `MediaDetailsPage.OnAppearing` logged exactly once, at the initial navigation, and tabbing away and back produced nothing. **Use `OnNavigatedTo` instead** — it fires on every tab return, and pairs with `OnNavigatedFrom` on the way out; all five pushed pages call `ViewModel.RefreshDisplaySettings()` from it. Confirmed in the same device run: `OnAppearing` 1, `OnDisappearing` 0, `OnNavigatedTo` 3 across two tab round-trips. No unit test will tell you which to use — the page model behaves correctly when called, and the bug is that nothing calls it, so a test driving the page model directly passes while the feature is dead on device. Verify on device via `/run-anisprinkles`, and see #131.
- **`ConfigureAwait(true)` in page models is deliberate.** It is the default, so it changes nothing at runtime — it states that the continuation writes bound state and must stay on the UI thread. `DetailsPageModelBase`, `PaginatedSection`, `MediaBrowsePageModel`, `ListOperationRunner` and `SettingsPageModel` all mark their data-fetch awaits this way. A `ConfigureAwait(false)` inside `AniListClient` governs continuations *inside that method* and does not propagate to the caller, so a page-model await resumes wherever its caller was — which is the UI thread for every lifecycle and command entry point. Don't add `ConfigureAwait(false)` to a page-model await whose continuation touches an `[ObservableProperty]` or a bound `ObservableCollection`.
- **Failed settings saves**: dirty-tracking is baselined against what the *server* reported, not the resolved local value, so a change that never landed leaves the page dirty and the next flush re-sends it (#128). A successful `UpdateUser` clears the markers for the values it actually carried — compared field by field, since the user can change a setting while a save is in flight, and clearing that one would discard a change the server never saw. A save arriving while another is in flight is coalesced into a second pass rather than dropped, and the failure snackbar goes through `ShowFailureSnackbarAsync` so a `ServiceOutage` offers no Retry.
- **Display settings and already-rendered pages**: title language and score format feed computed properties (`Media.DisplayTitle`, `MediaListEntry.ScoreDisplay`, the details rating control), so a change has to re-render what is already on screen. Each surface snapshots a `DisplaySettingsSnapshot` and re-projects in its appearing path when it moved — **never a refetch**, which would spend an AniList request on a formatting change (#127). `Media` and `RelatedMedia` are plain classes and cannot raise `PropertyChanged`, so the observable containers implement `IDisplayProjection` and re-raise the property carrying them (`Media` / `Node`), which makes MAUI re-resolve the nested binding path. A new carousel item type that shows a media title must implement it, or its cards render stale titles forever with nothing to catch it. Title language also moves the Title **sort order**, since `MediaListSection` sorts by `DisplayTitle`.

See `/project-architecture` for page patterns and performance defaults.

Expand Down
Binary file modified screenshots/browse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/character_details.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/discover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/my_anime.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/one_piece_details.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/staff_details.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/studio_details.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion src/AniSprinkles.Core/Models/BrowseMediaItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace AniSprinkles.Models;
/// is deliberately not observable, so after a long-press mutation the page model rewrites the
/// node's list fields and calls <see cref="NotifyListEntryChanged"/> to refresh the bound chip.
/// </summary>
public partial class BrowseMediaItem : ObservableObject
public partial class BrowseMediaItem : ObservableObject, IDisplayProjection
{
public RelatedMedia? Node { get; set; }

Expand Down Expand Up @@ -97,4 +97,11 @@ public void ClearListEntry()
Node.ListScore = null;
NotifyListEntryChanged();
}

/// <inheritdoc />
/// <remarks>
/// Re-raising <c>Node</c> is what makes the nested <c>Node.DisplayTitle</c> binding re-resolve;
/// <c>RelatedMedia</c> is a plain class and cannot notify for itself.
/// </remarks>
public void RefreshDisplayProjections() => OnPropertyChanged(nameof(Node));
}
9 changes: 8 additions & 1 deletion src/AniSprinkles.Core/Models/CharacterMediaEdge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace AniSprinkles.Models;

public partial class CharacterMediaEdge : ObservableObject
public partial class CharacterMediaEdge : ObservableObject, IDisplayProjection
{
public RelatedMedia? Node { get; set; }
public string? CharacterRole { get; set; }
Expand All @@ -15,4 +15,11 @@ public partial class CharacterMediaEdge : ObservableObject
private ItemMetricBadge? _metricBadge;

public bool HasMetricBadge => MetricBadge is not null;

/// <inheritdoc />
/// <remarks>
/// Re-raising <c>Node</c> is what makes the nested <c>Node.DisplayTitle</c> binding re-resolve;
/// <c>RelatedMedia</c> is a plain class and cannot notify for itself.
/// </remarks>
public void RefreshDisplayProjections() => OnPropertyChanged(nameof(Node));
}
21 changes: 21 additions & 0 deletions src/AniSprinkles.Core/Models/IDisplayProjection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace AniSprinkles.Models;

/// <summary>
/// An item whose bound text is computed from <c>AppSettings</c> and therefore goes stale when a
/// display setting changes underneath it (#127).
/// <para>
/// The awkward part this exists to paper over: <c>Media</c> and <c>RelatedMedia</c> carry the
/// computed <c>DisplayTitle</c> but are plain classes, so they cannot raise <c>PropertyChanged</c>
/// themselves. Implementers are the observable <em>containers</em> that hold one, and they re-raise
/// the property carrying it — MAUI then re-resolves the whole binding path, <c>DisplayTitle</c>
/// included, without those POCOs needing change notification of their own.
/// </para>
/// </summary>
public interface IDisplayProjection
{
/// <summary>
/// Re-raises change notification for every bound member computed from a display setting. Does no
/// work beyond notification — the underlying data is unchanged and no fetch is involved.
/// </summary>
void RefreshDisplayProjections();
}
16 changes: 15 additions & 1 deletion src/AniSprinkles.Core/Models/MediaListEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace AniSprinkles.Models;

public partial class MediaListEntry : ObservableObject
public partial class MediaListEntry : ObservableObject, IDisplayProjection
{
public int Id { get; set; }
public int MediaId { get; set; }
Expand Down Expand Up @@ -74,6 +74,20 @@ public string ProgressDisplay
public bool IsNumericScoreFormat => AppSettings.ScoreFormat is ScoreFormat.Point100
or ScoreFormat.Point10Decimal or ScoreFormat.Point10;

/// <inheritdoc />
/// <remarks>
/// <c>Media</c> is re-raised rather than <c>DisplayTitle</c> directly: the templates bind the
/// nested path <c>Media.DisplayTitle</c>, and <c>Media</c> is a plain class that cannot notify
/// for itself. The score members read <c>AppSettings.ScoreFormat</c> on this type, so they are
/// raised by name.
/// </remarks>
public void RefreshDisplayProjections()
{
OnPropertyChanged(nameof(Media));
OnPropertyChanged(nameof(ScoreDisplay));
OnPropertyChanged(nameof(IsNumericScoreFormat));
}

/// <summary>
/// Cap for +1 / progress-slider logic. Uses the total episode count when known,
/// otherwise falls back to the most-recently-aired episode (<c>NextAiringEpisode.Episode - 1</c>)
Expand Down
Loading