Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
insomniachi committed Aug 4, 2023
1 parent 4d2545c commit 9a43757
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 88 deletions.
28 changes: 0 additions & 28 deletions Totoro.WinUI/Behaviors/HideInfoBadeBehavior.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Totoro.WinUI/Totoro.WinUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
<PackageReference Include="CommunityToolkit.WinUI.Notifications" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Behaviors" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Media" Version="7.1.2" />
<PackageReference Include="H.NotifyIcon.WinUI" Version="2.0.108" />
<PackageReference Include="H.NotifyIcon.WinUI" Version="2.0.115" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230602002" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230724000" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<PackageReference Include="ReactiveMarbles.ObservableEvents.SourceGenerator" Version="1.2.3">
<PrivateAssets>all</PrivateAssets>
Expand Down
9 changes: 4 additions & 5 deletions Totoro.WinUI/UserControls/AnimeCard.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:help="using:Totoro.WinUI.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:root="using:Totoro.WinUI"
xmlns:uc="using:Totoro.WinUI.UserControls"
mc:Ignorable="d">

<ctk:SwitchPresenter Value="{x:Bind DisplayMode}">
Expand All @@ -33,16 +34,14 @@
Source="{x:Bind Anime.Image, Mode=OneWay}"
Stretch="UniformToFill" />

<InfoBadge
x:Name="InfoBadge"
<uc:UnwatchedEpisodesBadge
Width="30"
Height="30"
MaxHeight="30"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Style="{ThemeResource AttentionValueInfoBadgeStyle}"
Visibility="{x:Bind InfoBadgeVisibillity(InfoBadge.Value), Mode=OneWay}"
Value="{x:Bind UnwatchedEpisodes(Anime.AiredEpisodes), Mode=OneWay}" />
Anime="{x:Bind Anime, Mode=OneWay}"
Style="{ThemeResource AttentionValueInfoBadgeStyle}" />

<Grid
x:Name="NextEpisodeInContainer"
Expand Down
23 changes: 0 additions & 23 deletions Totoro.WinUI/UserControls/AnimeCard.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,4 @@ public Dictionary<string, string> GetAdditionalInformation(AnimeModel anime)
["Popularity"] = $"#{fa.Popularity}"
};
}

public Visibility InfoBadgeVisibillity(int value) => value > 0 ? Visibility.Visible : Visibility.Collapsed;

public int UnwatchedEpisodes(int airedEpisodes)
{
if (Anime is null)
{
return -1;
}

if (Anime.Tracking is null || Anime.Tracking.WatchedEpisodes is null)
{
return -1;
}

if (airedEpisodes == 0)
{
return -1;
}

return (airedEpisodes - Anime.Tracking.WatchedEpisodes.Value);
}

}
50 changes: 50 additions & 0 deletions Totoro.WinUI/UserControls/UnwatchedEpisodesBadge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace Totoro.WinUI.UserControls;

public class UnwatchedEpisodesBadge : InfoBadge
{
public AnimeModel Anime
{
get { return (AnimeModel)GetValue(AnimeProperty); }
set { SetValue(AnimeProperty, value); }
}

public static readonly DependencyProperty AnimeProperty =
DependencyProperty.Register("Anime", typeof(AnimeModel), typeof(UnwatchedEpisodesBadge), new PropertyMetadata(null));

public UnwatchedEpisodesBadge()
{
this.WhenAnyValue(x => x.Anime)
.WhereNotNull()
.SelectMany(x => x.WhenAnyValue(x => x.AiredEpisodes))
.Select(airedEpisodes => GetUnwatchedEpsiodes(Anime, airedEpisodes))
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(unwatchedEpisodes =>
{
Value = unwatchedEpisodes;
Visibility = unwatchedEpisodes > 0 ? Visibility.Visible : Visibility.Collapsed;
});
}

private static int GetUnwatchedEpsiodes(AnimeModel anime, int airedEpisodes)
{
if (anime is null)
{
return -1;
}

if (anime.Tracking is null || anime.Tracking.WatchedEpisodes is null)
{
return -1;
}

if (airedEpisodes == 0)
{
return -1;
}

return (airedEpisodes - anime.Tracking.WatchedEpisodes.Value);
}
}
11 changes: 3 additions & 8 deletions Totoro.WinUI/Views/UserListPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,10 @@
Margin="10,0"
VerticalAlignment="Center"
Text="{Binding Title}" />
<InfoBadge
x:Name="InfoBadge"
<uc:UnwatchedEpisodesBadge
VerticalAlignment="Center"
Style="{ThemeResource AttentionValueInfoBadgeStyle}"
Value="{x:Bind v:UserListPage.UnwatchedEpisodes((cm:AnimeModel), AiredEpisodes), Mode=OneWay}">
<Interactivity:Interaction.Behaviors>
<b:HideInfoBadeBehavior />
</Interactivity:Interaction.Behaviors>
</InfoBadge>
Anime="{x:Bind}"
Style="{ThemeResource AttentionValueInfoBadgeStyle}" />
</StackPanel>
</DataTemplate>
</ctk:DataGridTemplateColumn.CellTemplate>
Expand Down
22 changes: 0 additions & 22 deletions Totoro.WinUI/Views/UserListPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,28 +163,6 @@ private void OnLoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.ContextFlyout = Converters.AnimeToFlyout(e.Row.DataContext as AnimeModel);
}

public static Visibility InfoBadgeVisibillity(int value) => value > 0 ? Visibility.Visible : Visibility.Collapsed;

public static int UnwatchedEpisodes(AnimeModel anime, int airedEpisodes)
{
if (anime is null)
{
return -1;
}

if (anime.Tracking is null || anime.Tracking.WatchedEpisodes is null)
{
return -1;
}

if (airedEpisodes == 0)
{
return -1;
}

return (airedEpisodes - anime.Tracking.WatchedEpisodes.Value);
}
}


Expand Down

0 comments on commit 9a43757

Please sign in to comment.