Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
40 changes: 34 additions & 6 deletions src/AniSprinkles.Core/Converters/RainbowAccentConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ public sealed class RainbowAccentConverter : IValueConverter
};

/// <summary>
/// Hardcoded colors for the standard list status sections, anime and manga alike.
/// Checked after <see cref="_keyMappings"/> are applied, before the hash fallback,
/// so each status section always renders with a distinct, consistent color.
/// Hardcoded colors for the keys that must not be left to the hash: the standard list status
/// sections (anime and manga alike), and Settings' two stat cards. Checked after
/// <see cref="_keyMappings"/> are applied, before the hash fallback, so each of these always
/// renders with a distinct, consistent color rather than whatever its name happens to hash to.
/// </summary>
private static readonly Dictionary<string, string> _statusColors = new(StringComparer.OrdinalIgnoreCase)
private static readonly Dictionary<string, string> _fixedColors = new(StringComparer.OrdinalIgnoreCase)
{
["Watching"] = "RainbowBlue",
["Rewatching"] = "RainbowCyan",
Expand All @@ -49,6 +50,33 @@ public sealed class RainbowAccentConverter : IValueConverter
["Completed"] = "RainbowGreen",
["Paused"] = "RainbowYellow",
["Dropped"] = "RainbowRed",

// Settings' two stat cards (#12). These keys exist only there, deliberately: the obvious
// parameters — "Manga", "Chapters", "Volumes" — are already spoken for by Search's type
// pills, the Library nav titles and the details-page chips, so pinning those to suit a
// stat tile would silently recolour four other screens.
//
// Pinned rather than hashed because the two cards have to stay visually apart, and the
// hash does not care: left to it, Manga, Chapters and Volumes all landed on RainbowBlue,
// the same colour as Mean Score, so every manga figure rendered identically blue beside a
// four-colour anime card.
//
// The palette has eight stops and the two cards have ten slots, so exactly two colours
// recur. Both are deliberate: RainbowBlue on each Mean Score, which is the same metric on
// both cards, and RainbowCyan on the anime header and the manga Volumes tile, which never
// sit in the same role. The anime entries pin the colours that card already rendered, so
// it does not change.
["StatsAnimeHeader"] = "RainbowCyan",
["StatsTotalAnime"] = "RainbowPink",
["StatsEpisodes"] = "RainbowGreen",
["StatsDaysWatched"] = "RainbowYellow",
["StatsAnimeScore"] = "RainbowBlue",

["StatsMangaHeader"] = "RainbowPurple",
["StatsTotalManga"] = "RainbowRed",
["StatsChapters"] = "RainbowOrange",
["StatsVolumes"] = "RainbowCyan",
["StatsMangaScore"] = "RainbowBlue",
};

public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
Expand Down Expand Up @@ -103,8 +131,8 @@ public static string ResourceKeyFor(string key)
key = mappedKey;
}

// Use hardcoded color for known status sections; fall back to hash for everything else.
if (_statusColors.TryGetValue(key, out var colorKey))
// Use hardcoded color for known status sections and the stat cards; fall back to hash for everything else.
if (_fixedColors.TryGetValue(key, out var colorKey))
{
return colorKey;
}
Expand Down
1 change: 1 addition & 0 deletions src/AniSprinkles.Core/Models/AniListUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public class AniListUser
/// </summary>
public List<string> MangaSectionOrder { get; set; } = [];
public UserAnimeStatistics AnimeStatistics { get; set; } = new();
public UserMangaStatistics MangaStatistics { get; set; } = new();
}
16 changes: 16 additions & 0 deletions src/AniSprinkles.Core/Models/UserMangaStatistics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace AniSprinkles.Models;

/// <summary>
/// The viewer's manga totals (#12). Separate from <see cref="UserAnimeStatistics"/> even though
/// AniList returns one <c>UserStatistics</c> type for both: that type carries every field for
/// either kind, so a shared model would put a meaningless <c>EpisodesWatched</c> on manga and a
/// meaningless <c>ChaptersRead</c> on anime. Modelling only the fields that mean something keeps
/// the Settings card from being able to show a number that cannot be true.
/// </summary>
public class UserMangaStatistics
{
public int Count { get; set; }
public double MeanScore { get; set; }
public int ChaptersRead { get; set; }
public int VolumesRead { get; set; }
}
23 changes: 23 additions & 0 deletions src/AniSprinkles.Core/PageModels/SettingsPageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ public partial class SettingsPageModel : ObservableObject
[ObservableProperty]
private string _meanScore = "0";

// Manga totals (#12). Shown even for an account with no manga, matching the anime card, which
// has always rendered zeros for a fresh account rather than hiding itself.
[ObservableProperty]
private string _totalManga = "0";

[ObservableProperty]
private string _chaptersRead = "0";

[ObservableProperty]
private string _volumesRead = "0";

[ObservableProperty]
private string _mangaMeanScore = "0";

// --- Display preferences ---
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(HasUnsavedChanges))]
Expand Down Expand Up @@ -420,6 +434,11 @@ private void PopulateCore(AniListUser user)
DaysWatched = days.ToString("N1");
MeanScore = user.AnimeStatistics.MeanScore.ToString("N1");

TotalManga = user.MangaStatistics.Count.ToString("N0");
ChaptersRead = user.MangaStatistics.ChaptersRead.ToString("N0");
VolumesRead = user.MangaStatistics.VolumesRead.ToString("N0");
MangaMeanScore = user.MangaStatistics.MeanScore.ToString("N1");

// Display preferences.
//
// Every one of these is resolved rather than taken straight from the viewer (#128). A save
Expand Down Expand Up @@ -590,6 +609,10 @@ private void ClearUserData()
EpisodesWatched = "0";
DaysWatched = "0";
MeanScore = "0";
TotalManga = "0";
ChaptersRead = "0";
VolumesRead = "0";
MangaMeanScore = "0";
NotificationItems.Clear();

// Sign-out must not leave the previous account's unconfirmed changes shadowing the next
Expand Down
24 changes: 24 additions & 0 deletions src/AniSprinkles.Core/Services/AniListClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,13 @@ private static AniListUser MapUser(ViewerFullDto dto)
MeanScore = dto.Statistics?.Anime?.MeanScore ?? 0,
MinutesWatched = dto.Statistics?.Anime?.MinutesWatched ?? 0,
EpisodesWatched = dto.Statistics?.Anime?.EpisodesWatched ?? 0
},
MangaStatistics = new UserMangaStatistics
{
Count = dto.Statistics?.Manga?.Count ?? 0,
MeanScore = dto.Statistics?.Manga?.MeanScore ?? 0,
ChaptersRead = dto.Statistics?.Manga?.ChaptersRead ?? 0,
VolumesRead = dto.Statistics?.Manga?.VolumesRead ?? 0
}
};
}
Expand Down Expand Up @@ -1641,14 +1648,19 @@ private sealed class MediaListTypeOptionsDto
private sealed class UserStatisticTypesDto
{
public UserStatisticsDto? Anime { get; set; }
public UserStatisticsDto? Manga { get; set; }
}

// One DTO for both, because AniList's UserStatistics type is one type for both: it carries
// every counter, and which ones mean anything depends on which branch you read it from.
private sealed class UserStatisticsDto
{
public int? Count { get; set; }
public double? MeanScore { get; set; }
public int? MinutesWatched { get; set; }
public int? EpisodesWatched { get; set; }
public int? ChaptersRead { get; set; }
public int? VolumesRead { get; set; }
}

private sealed class MediaDto
Expand Down Expand Up @@ -2265,6 +2277,12 @@ query ViewerFull {
minutesWatched
episodesWatched
}
manga {
count
meanScore
chaptersRead
volumesRead
}
}
}
}";
Expand Down Expand Up @@ -2615,6 +2633,12 @@ mutation UpdateUser($titleLanguage: UserTitleLanguage, $displayAdultContent: Boo
minutesWatched
episodesWatched
}
manga {
count
meanScore
chaptersRead
volumesRead
}
}
}
}";
Expand Down
9 changes: 9 additions & 0 deletions src/AniSprinkles/Services/CI/CIAniListClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ private static class StubData
MinutesWatched = 24912,
MeanScore = 8.75,
},
// Deliberately not a round multiple of the anime figures, and a different mean, so the
// screenshot would show it if the Manga Stats card were ever wired to the anime numbers.
MangaStatistics = new UserMangaStatistics
{
Count = 3,
ChaptersRead = 373,
VolumesRead = 42,
MeanScore = 9.0,
},
};

// ── Currently Watching ───────────────────────────────────────────────────
Expand Down
63 changes: 56 additions & 7 deletions src/AniSprinkles/Views/SettingsLoadedContentView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,49 +82,98 @@
</Grid>
</Border>

<!-- 2. ANIME STATISTICS -->
<!-- 2. STATISTICS — one card per list, mirroring the Library's two halves (#12) -->
<Border Style="{StaticResource AccentCardBorderStyle}" Padding="16">
<VerticalStackLayout Spacing="12">
<HorizontalStackLayout Spacing="8">
<Image WidthRequest="20" HeightRequest="20" VerticalOptions="Center">
<Image.Source>
<FontImageSource Glyph="{x:Static icons:FluentIconsRegular.DataBarVertical24}"
FontFamily="{x:Static icons:FluentIconsRegular.FontFamily}"
Color="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='Stats'}"
Color="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='StatsAnimeHeader'}"
Size="20" />
</Image.Source>
</Image>
<Label Text="Anime Stats"
Style="{StaticResource Title3}"
TextColor="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='Stats'}" />
TextColor="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='StatsAnimeHeader'}" />
</HorizontalStackLayout>
<Grid ColumnDefinitions="*,*" RowDefinitions="Auto,Auto"
ColumnSpacing="12" RowSpacing="12">
<Border Grid.Row="0" Grid.Column="0" Style="{StaticResource CardStyle}" Padding="12">
<VerticalStackLayout Spacing="2" HorizontalOptions="Center">
<Label Text="{Binding TotalAnime}" Style="{StaticResource Title2}" HorizontalTextAlignment="Center"
TextColor="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='Anime'}" />
TextColor="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='StatsTotalAnime'}" />
<Label Text="Total Anime" Style="{StaticResource Caption1}" TextColor="{StaticResource Gray400}" HorizontalTextAlignment="Center" />
</VerticalStackLayout>
</Border>
<Border Grid.Row="0" Grid.Column="1" Style="{StaticResource CardStyle}" Padding="12">
<VerticalStackLayout Spacing="2" HorizontalOptions="Center">
<Label Text="{Binding EpisodesWatched}" Style="{StaticResource Title2}" HorizontalTextAlignment="Center"
TextColor="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='Episodes'}" />
TextColor="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='StatsEpisodes'}" />
<Label Text="Episodes" Style="{StaticResource Caption1}" TextColor="{StaticResource Gray400}" HorizontalTextAlignment="Center" />
</VerticalStackLayout>
</Border>
<Border Grid.Row="1" Grid.Column="0" Style="{StaticResource CardStyle}" Padding="12">
<VerticalStackLayout Spacing="2" HorizontalOptions="Center">
<Label Text="{Binding DaysWatched}" Style="{StaticResource Title2}" HorizontalTextAlignment="Center"
TextColor="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='Days'}" />
TextColor="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='StatsDaysWatched'}" />
<Label Text="Days Watched" Style="{StaticResource Caption1}" TextColor="{StaticResource Gray400}" HorizontalTextAlignment="Center" />
</VerticalStackLayout>
</Border>
<Border Grid.Row="1" Grid.Column="1" Style="{StaticResource CardStyle}" Padding="12">
<VerticalStackLayout Spacing="2" HorizontalOptions="Center">
<Label Text="{Binding MeanScore}" Style="{StaticResource Title2}" HorizontalTextAlignment="Center"
TextColor="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='Score'}" />
TextColor="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='StatsAnimeScore'}" />
<Label Text="Mean Score" Style="{StaticResource Caption1}" TextColor="{StaticResource Gray400}" HorizontalTextAlignment="Center" />
</VerticalStackLayout>
</Border>
</Grid>
</VerticalStackLayout>
</Border>

<Border Style="{StaticResource AccentCardBorderStyle}" Padding="16">
<VerticalStackLayout Spacing="12">
<HorizontalStackLayout Spacing="8">
<Image WidthRequest="20" HeightRequest="20" VerticalOptions="Center">
<Image.Source>
<FontImageSource Glyph="{x:Static icons:FluentIconsRegular.DataBarVertical24}"
FontFamily="{x:Static icons:FluentIconsRegular.FontFamily}"
Color="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='StatsMangaHeader'}"
Size="20" />
</Image.Source>
</Image>
<Label Text="Manga Stats"
Style="{StaticResource Title3}"
TextColor="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='StatsMangaHeader'}" />
</HorizontalStackLayout>
<Grid ColumnDefinitions="*,*" RowDefinitions="Auto,Auto"
ColumnSpacing="12" RowSpacing="12">
<Border Grid.Row="0" Grid.Column="0" Style="{StaticResource CardStyle}" Padding="12">
<VerticalStackLayout Spacing="2" HorizontalOptions="Center">
<Label Text="{Binding TotalManga}" Style="{StaticResource Title2}" HorizontalTextAlignment="Center"
TextColor="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='StatsTotalManga'}" />
<Label Text="Total Manga" Style="{StaticResource Caption1}" TextColor="{StaticResource Gray400}" HorizontalTextAlignment="Center" />
</VerticalStackLayout>
</Border>
<Border Grid.Row="0" Grid.Column="1" Style="{StaticResource CardStyle}" Padding="12">
<VerticalStackLayout Spacing="2" HorizontalOptions="Center">
<Label Text="{Binding ChaptersRead}" Style="{StaticResource Title2}" HorizontalTextAlignment="Center"
TextColor="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='StatsChapters'}" />
<Label Text="Chapters" Style="{StaticResource Caption1}" TextColor="{StaticResource Gray400}" HorizontalTextAlignment="Center" />
</VerticalStackLayout>
</Border>
<Border Grid.Row="1" Grid.Column="0" Style="{StaticResource CardStyle}" Padding="12">
<VerticalStackLayout Spacing="2" HorizontalOptions="Center">
<Label Text="{Binding VolumesRead}" Style="{StaticResource Title2}" HorizontalTextAlignment="Center"
TextColor="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='StatsVolumes'}" />
<Label Text="Volumes" Style="{StaticResource Caption1}" TextColor="{StaticResource Gray400}" HorizontalTextAlignment="Center" />
</VerticalStackLayout>
</Border>
<Border Grid.Row="1" Grid.Column="1" Style="{StaticResource CardStyle}" Padding="12">
<VerticalStackLayout Spacing="2" HorizontalOptions="Center">
<Label Text="{Binding MangaMeanScore}" Style="{StaticResource Title2}" HorizontalTextAlignment="Center"
TextColor="{Binding Converter={StaticResource RainbowAccentConverter}, ConverterParameter='StatsMangaScore'}" />
<Label Text="Mean Score" Style="{StaticResource Caption1}" TextColor="{StaticResource Gray400}" HorizontalTextAlignment="Center" />
</VerticalStackLayout>
</Border>
Expand Down
Loading
Loading