Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .claude/skills/project-architecture/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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`, `ISecureTokenStorage`, `TokenStore`, `ListEntryStatusFlow` | Singleton |
| `ErrorReportService`, `HttpClient`, `IAuthService`, `IAniListClient`, `IAiringNotificationService`, `IOutageStateService`, `INavigationService`, `IUserFeedback`, `IDialogService`, `IExternalBrowser`, `ISecureTokenStorage`, `TokenStore`, `ListEntryStatusFlow`, `IUpNextOffer` | Singleton |
| `IPreferences`, `IAppInfo`, `TimeProvider` (`TryAddSingleton` — MAUI exposes the first two only as statics, so DI has no default) | Singleton |
| `AnimeLibraryPageModel`, `MangaLibraryPageModel`, `DiscoverPageModel`, `SearchPageModel`, `SettingsPageModel` | **Singleton** (survive page recreation across tab switches) |
| `LoggingHandler`, `AniListRateLimitHandler` | Transient |
Expand Down Expand Up @@ -57,6 +57,7 @@ See `AnimeLibraryPage.xaml.cs` and `SettingsPage.xaml.cs` for reference implemen
- `MediaBrowsePage` ("View All", transient): `DeferredContentLoader` + one `PaginatedSection<BrowseMediaItem>` over the same `DiscoverSectionFetch`; `DiscoverSectionDefinitions` is the single source of truth for section title/sort/filters/format/rank. Has the Library view-mode switcher; the mode persists to the shared `ListViewModePreference` key, so both Library halves and View All always match (Library re-syncs in `OnAppearing`).
- `BrowseTemplates.xaml` (merged in App.xaml) holds the shared templates: `BrowseMediaRowTemplate` (Standard, also used by search results), `BrowseMediaLargeTemplate` (2-col grid), `BrowseMediaCompactTemplate`, plus `ListStatusPillStyle` — the ONE on-list status pill style. Rows/grid cards overlay it inline (their own layout); the 130×170 carousel cards get it for free from `CoverImage` (`ListStatusText`/`ListStatusColor` props), which is the shared cover used by the Discover carousel AND every detail-page media carousel (relations, recommendations, studio productions, staff production roles, character appearances). Those detail pages send the viewer token so `mediaListEntry` is populated. Tap commands resolve from the hosting CollectionView's BindingContext (`NavigateToMediaCommand`).
- `EntryActionCoordinator` (`PageModels/`) owns the long-press action flows (menu, add/move/rate/edit-progress/complete/remove, persistence, toasts/snackbars) for both Library halves AND the browse surfaces; page models supply `EntryActionHost` callbacks (optimistic removal, reload vs in-place chip update, error details). Item long press is MAUI's `LongPressGestureRecognizer` on the **same element** as the item's `TapGestureRecognizer`, with `CommandParameter="{Binding .}"`: the two then share one Android `GestureDetector`, which never reports a tap at finger-up after a long press, so no suppression is needed (#171). A long press on a different element from the tap — including a nested button like Library's `+1` — gets its own detector and loses that guarantee, and a tap-only element reports a tap on release after any hold, so Library's `+1` carries its own long press to the same menu; a long press that is the only recognizer on a view also misfires after a plain tap on MAUI 11.0.10 (dotnet/maui#40180).
- **Up next (#103)**: every path that lands an entry on Completed — the coordinator's completion, Move to → Completed and Add to list → Completed, and the details page's status dropdown and +1-reaches-total path — calls `IUpNextOffer.Begin(entry)` (singleton `UpNextOffer`, `Services/UpNext/`) for a per-flow `UpNextScope`, or null when the Settings toggle is off. The scope is threaded into `ListEntryStatusFlow` so the light `MediaRelations` fetch (`IAniListClient.GetMediaRelationsAsync`, never cached: its per-node `mediaListEntry` is what stops an add overwriting an entry already on the list) starts once the completion is confirmed and runs behind the rating popup. The offer is made after the completion save succeeds and before the host's status-changed callback, so Library reloads once with the adds in it. The save's own toast goes through `UpNextScope.ConfirmSavedThenOfferAsync` and is never shown while the sheet is up (an Android toast draws over every window, so it sat on the sheet's buttons): it shows straight away when there is nothing to offer, and after the sheet closes on Not now; when titles are picked, their own toast replaces it. Rules live in `UpNextCandidates` (sequel / side story / spin-off / alternative, same media type, 18+ filtered), which fixes each candidate's `Target` once, so a row's label, save and toast cannot disagree. Everything follows the `up_next_status` preference (Watching by default, or Planning): a new title is added there; one already on the list is moved, by saving back the whole entry the relations query read (`RelatedMedia.ViewerEntry`) so score, notes and repeat count survive — Planning, Paused and Dropped to the preference, Completed to Rewatching (or to Planning when that is the preference, with progress reset to 0), whether or not the completion was itself a rewatch. An unreleased title only ever goes to Planning, and a cancelled one is never offered. Watching and Rewatching, and anything already in its target list, are not offered. Every row starts unticked. The full matrix is `UpNextTests.Candidates_FollowTheMatrix`.

## Details Page UX

Expand Down
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
- **Endpoint**: `https://graphql.anilist.co`. Auth: OAuth implicit grant, redirect URI `anisprinkles://auth`, token in `SecureStorage` keys `anilist_access_token` and `anilist_access_token_expires_at`.
- **Every request must carry a `Referer: https://anilist.co/` header** (#160). AniList rejects any request that has neither a `Referer` nor an `Authorization` header with HTTP 403 — and the body says *"The AniList API has been temporarily disabled due to severe stability issues"*, which `AniListErrorClassifier` reads as an outage marker. So the failure does not present as "we sent a bad request", it presents as a false **"AniList is Down"** banner while AniList is serving other clients normally. A token satisfies the same filter, but cannot be the whole answer: signed-out browsing (Discover, Search, every details page) has no token by definition, and `AiringScheduleFetcher` has none by design. The header is set in **two** places — `AniListClient.SendAsyncCore` and `AiringScheduleFetcher.Fetch` — because the worker deliberately bypasses the client; if a third path to AniList is ever added, it needs its own. `AniListRateLimitHandler` rebuilds requests from a `RequestTemplate` on retry and copies request headers across, so retries keep it; there is a test pinning that.
- **Signed-in API behaviour can be tested from the desktop, as the test account.** `driver.ps1 dump-token` (#160) writes the dedicated test account's token to `tmp/dev-token.txt`. That file is git-ignored, so it lives in the **main checkout only**: a worktree has to read it from there, at `$(git rev-parse --git-common-dir)/../tmp/dev-token.txt`. The recorder reads the same file. Send the token as a `Bearer` header for read-only probes of how AniList answers a signed-in viewer, where that can differ from signed-out. #199 is the example: for a viewer with Display Adult Content off, AniList filters top-level reads (`Page.media` returns no 18+ titles even when asked for `isAdult: true`, and `Media(id:)` of one returns `404 "Not Found."`), but not nested connections, which return them exactly as signed out. Never print it, log it, or put it in a command line. To find out what the account's settings are, query `Viewer { options { ... } }` rather than assuming.
- **The account is shared.** The user, other sessions and the recorder all use it at the same time, often on another emulator, so its list, favourites and settings can change between two of your requests. Don't read an unexpected change as a bug in your own work until you've ruled that out. Writing to the account (a list save, a settings change, a favourite) can change someone else's run too, so ask before doing any.
- **The test account is `AniSprinkles` (id 7720462)**, not the user's personal account. A session signed in as it should say so rather than treat its list as the user's.
- **The account is shared.** The user, other sessions and the recorder all use it at the same time, often on another emulator, so its list, favourites and settings can change between two of your requests. Don't read an unexpected change as a bug in your own work until you've ruled that out.
- **Writing to it is allowed without asking.** It is a throwaway test account, not the user's own, so list saves, settings changes, favourites, recording fixtures with `tools/record-anilist-fixtures.cs` and seeding with `tools/clone-anilist-list.cs` all need no sign-off. Two limits: add nothing unsavoury (no hentai, Ecchi or other 18+ titles — the account's content ends up in public fixtures and screenshots), and leave its settings as you found them when a change was only for a test, since other runs read them. The same token is usually in `ANILIST_RECORDER_TOKEN` as well.
- **Viewer ID caching**: lightweight `Viewer { id }` query cached by token string; invalidates on re-auth.
- **Person names come from `userPreferred`, never `full`** (#130). AniList resolves `userPreferred` server-side against the viewer's Staff Name Language, and it is script-aware where `full` is not: measured on a real account set to `ROMAJI`, `full` returned "Bairstow Caitlyn" for a Latin-script name while `userPreferred` returned "Caitlyn Bairstow" (a Japanese name flipped in both). All eleven `name { ... }` selections request it, and `StaffNameFormat` falls back to `full` only when it is absent. The cost is that a change needs a refetch rather than a re-projection — see `InvalidateEntityCache` under Caching.
- **Operations**: `Viewer`, `ViewerFull`, `MediaListCollection`, `Media`, `SaveMediaListEntry`, `DeleteMediaListEntry`, `UpdateUser`, `AiringSchedule` / `Staff` / `Character` / `Studio` / `Search` / `DiscoverSections` / `BrowseAnime` (the latter seven work without auth; the browse/search trio sends the token when present so `mediaListEntry` fills in the viewer's list status). `DiscoverSections` batches every Discover row's first page (+ `pageInfo`) into ONE aliased request — keep it that way (rate-limit budget); scrolling a row past its seed pages it through `BrowseAnime`, one request per row-page, via the shared `DiscoverSectionFetch`.
Expand Down
5 changes: 5 additions & 0 deletions src/AniSprinkles.Core/Converters/RainbowAccentConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public sealed class RainbowAccentConverter : IValueConverter
["StatsChapters"] = "RainbowOrange",
["StatsVolumes"] = "RainbowCyan",
["StatsMangaScore"] = "RainbowBlue",

// Settings' Up Next section (#103). Hashed, it came out the same orange as Content &
// Privacy directly beneath it, so the two headers read as one. Green is free among the
// section headers (Display blue, Privacy orange, Notifications pink, Account cyan).
["UpNext"] = "RainbowGreen",
};

public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
Expand Down
3 changes: 3 additions & 0 deletions src/AniSprinkles.Core/Models/MediaRelationEdge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace AniSprinkles.Models;
public class MediaRelationEdge : ObservableObject, IDisplayProjection
{
public string? RelationType { get; set; }

/// <summary>The same relation as <see cref="RelationType"/>, typed, for code that branches on it (#103).</summary>
public MediaRelationKind Kind { get; set; }
public RelatedMedia? Node { get; set; }

// The card's metric badge (year), stamped by the PageModel; always shown (— when no year).
Expand Down
49 changes: 49 additions & 0 deletions src/AniSprinkles.Core/Models/MediaRelationKind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace AniSprinkles.Models;

/// <summary>
/// AniList's <c>MediaRelation</c> enum as asked for at <c>relationType(version: 3)</c>. Parsed from
/// the raw value rather than from <see cref="MediaRelationEdge.RelationType"/>, which is the
/// title-cased display string ("Side Story") and not something to branch on (#103).
/// </summary>
public enum MediaRelationKind
{
/// <summary>Absent, or a value this build does not know.</summary>
Unknown,
Adaptation,
Prequel,
Sequel,
Parent,
SideStory,
Character,
Summary,
Alternative,
SpinOff,
Other,
Source,
Compilation,
Contains,
SameUniverse,
}

public static class MediaRelationKindExtensions
{
/// <summary>
/// <c>SIDE_STORY</c> → <see cref="MediaRelationKind.SideStory"/>. Anything unrecognised is
/// <see cref="MediaRelationKind.Unknown"/>, so a relation type AniList adds later is simply never
/// offered rather than misread as one we act on.
/// </summary>
public static MediaRelationKind ParseMediaRelationKind(string? raw)
{
if (string.IsNullOrWhiteSpace(raw))
{
return MediaRelationKind.Unknown;
}

var name = raw.Replace("_", string.Empty, StringComparison.Ordinal);
return Enum.TryParse<MediaRelationKind>(name, ignoreCase: true, out var kind)
&& Enum.IsDefined(kind)
&& !int.TryParse(name, out _)
? kind
: MediaRelationKind.Unknown;
}
}
9 changes: 9 additions & 0 deletions src/AniSprinkles.Core/Models/RelatedMedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ public class RelatedMedia
public int? ListProgress { get; set; }
public double? ListScore { get; set; }

/// <summary>
/// The viewer's whole list entry for this title, on relation nodes only (#103), so the up-next
/// offer can move an entry that is already on the list. Complete only when it came from
/// <c>IAniListClient.GetMediaRelationsAsync</c>, which selects every field a save sends back
/// (score, repeat count, notes, private). The details query selects four, so a save built
/// from that copy would write nulls over the rest.
/// </summary>
public MediaListEntry? ViewerEntry { get; set; }

// Was its own copy of the chain, falling back to "Unknown" where Media said "Unknown Title" —
// the drift that motivated consolidating this (#141).
public string DisplayTitle
Expand Down
2 changes: 2 additions & 0 deletions src/AniSprinkles.Core/PageModels/AnimeLibraryPageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public partial class AnimeLibraryPageModel(
IDialogService dialogs,
IUserFeedback feedback,
ListEntryStatusFlow statusFlow,
IUpNextOffer upNext,
TimeProvider timeProvider,
ILogger<MediaListPageModel> logger)
: MediaListPageModel(
Expand All @@ -30,6 +31,7 @@ public partial class AnimeLibraryPageModel(
dialogs,
feedback,
statusFlow,
upNext,
timeProvider,
logger)
{
Expand Down
3 changes: 2 additions & 1 deletion src/AniSprinkles.Core/PageModels/DiscoverPageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public DiscoverPageModel(
IUserFeedback feedback,
IDialogService dialogs,
ListEntryStatusFlow statusFlow,
IUpNextOffer upNext,
ErrorReportService errorReportService,
TimeProvider timeProvider,
ILogger<DiscoverPageModel> logger)
Expand Down Expand Up @@ -85,7 +86,7 @@ public DiscoverPageModel(
// Shared long-press flows. A successful mutation is written back onto EVERY item showing
// that media (the same anime can sit in several rows), keeping the chips and the
// TTL-cached sections consistent without a refetch.
_entryActions = new EntryActionCoordinator(aniListClient, errorReportService, dialogs, feedback, statusFlow, logger, new EntryActionHost
_entryActions = new EntryActionCoordinator(aniListClient, errorReportService, dialogs, feedback, statusFlow, upNext, logger, new EntryActionHost
{
OpenDetailsAsync = entry => NavigateToMediaByIdAsync(entry.MediaId),
OnEntrySavedInPlaceAsync = entry => { ApplyEntryToItems(entry); return Task.CompletedTask; },
Expand Down
Loading