Skip to content

Commit

Permalink
Rework note editor popup with new control
Browse files Browse the repository at this point in the history
  • Loading branch information
aetherstrata committed Feb 19, 2024
1 parent 019f416 commit 42e524f
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 205 deletions.
4 changes: 3 additions & 1 deletion Aosta.Ava/Aosta.Ava/Assets/Localization/en-US.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"App.Version": "Version {0}",

"AnimeDetails.Menu.OpenOnMAL": "Open on MyAnimeList",
"AnimeDetails.Menu.Remove": "Remove from list",
"AnimeDetails.Score.PopupTitle": "Score",
"AnimeDetails.Score.Watermark": "Rate this anime",
Expand All @@ -13,6 +12,7 @@
"EpisodeDetails.Notes.Header": "Notes",
"EpisodeDetails.Notes.TitleWatermark": "Insert the title",
"EpisodeDetails.Notes.NoteWatermark": "Write a new note",
"EpisodeDetails.Notes.TextValidation": "Ciuppa",
"EpisodeDetails.ToolTip.MarkAsWatched": "Mark this episode as watched",

"HomePage.SeasonalAnime.Header" : "Currently airing",
Expand Down Expand Up @@ -43,6 +43,7 @@
"Label.CloseButton": "Cancel",
"Label.ContentType": "Type",
"Label.Date": "Date",
"Label.Duration": "Duration",
"Label.Episode.Number": "Episode #{0}",
"Label.Episodes": "Episodes",
"Label.Filler": "Filler",
Expand All @@ -51,6 +52,7 @@
"Label.NotAvailable.Long" : "Not available",
"Label.NotAvailable.Short" : "N/A",
"Label.Online": "Online",
"label.OpenOnMal": "Open on MyAnimeList",
"Label.PrimaryButton": "OK",
"Label.Recap": "Recap",
"Label.Score": "Score",
Expand Down
3 changes: 2 additions & 1 deletion Aosta.Ava/Aosta.Ava/Assets/Localization/it-IT.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"App.Version": "Versione {0}",

"AnimeDetails.Menu.OpenOnMAL": "Apri su MyAnimeList",
"AnimeDetails.Menu.Remove": "Rimuovi dalla lista",
"AnimeDetails.Score.PopupTitle": "Voto",
"AnimeDetails.Score.Watermark": "Dai un voto a questo anime",
Expand Down Expand Up @@ -42,6 +41,7 @@
"Label.CloseButton": "Annulla",
"Label.ContentType": "Tipo",
"Label.Date": "Data",
"Label.Duration": "Durata",
"Label.Episode.Number": "Episodio n.{0}",
"Label.Episodes": "Episodi",
"Label.Filler": "Filler",
Expand All @@ -50,6 +50,7 @@
"Label.NotAvailable.Long" : "Non disponibile",
"Label.NotAvailable.Short" : "N/D",
"Label.Online": "Online",
"Label.OpenOnMal": "Apri su MyAnimeList",
"Label.PrimaryButton": "OK",
"Label.Recap": "Recap",
"Label.Score": "Voto",
Expand Down
99 changes: 61 additions & 38 deletions Aosta.Ava/Aosta.Ava/Controls/AnimatedPopup.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Avalonia.Controls;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Styling;
using Avalonia.Threading;

using Splat;
Expand Down Expand Up @@ -74,7 +73,6 @@ public AnimatedPopup()
private readonly Timer _sizingTimer;
private readonly Control _underlay;


private int _currentTick;
private Size _desiredSize;
private bool _firstAnimation = true;
Expand All @@ -85,7 +83,7 @@ public AnimatedPopup()

#region Control Properties

private TimeSpan _animationTime = TimeSpan.FromSeconds(0.5);
private TimeSpan _animationTime = TimeSpan.FromSeconds(0.3);

public static readonly DirectProperty<AnimatedPopup, TimeSpan> AnimationTimeProperty =
AvaloniaProperty.RegisterDirect<AnimatedPopup, TimeSpan>(
Expand All @@ -106,30 +104,51 @@ public TimeSpan AnimationTime
public bool IsOpen
{
get => _isOpen;
set => SetAndRaise(IsOpenProperty, ref _isOpen, value);
set
{
if (_isOpen == value) return;

updateAnimation();

SetAndRaise(IsOpenProperty, ref _isOpen, value);
}
}

#endregion
private bool _animateWidth = true;

public void Open()
{
IsOpen = true;
public static readonly DirectProperty<AnimatedPopup, bool> AnimateWidthProperty =
AvaloniaProperty.RegisterDirect<AnimatedPopup, bool>(
nameof(AnimateWidth), o => o.AnimateWidth, (o, v) => o.AnimateWidth = v);

updateAnimation();
public bool AnimateWidth
{
get => _animateWidth;
set => SetAndRaise(AnimateWidthProperty, ref _animateWidth, value);
}

public void Close()
{
IsOpen = false;
private bool _animateHeight = true;

public static readonly DirectProperty<AnimatedPopup, bool> AnimateHeightProperty =
AvaloniaProperty.RegisterDirect<AnimatedPopup, bool>(
nameof(AnimateHeight), o => o.AnimateHeight, (o, v) => o.AnimateHeight = v);

updateAnimation();
public bool AnimateHeight
{
get => _animateHeight;
set => SetAndRaise(AnimateHeightProperty, ref _animateHeight, value);
}

#endregion

public void Open() => IsOpen = true;

public void Close() => IsOpen = false;

public override void Render(DrawingContext context)
{
if (!_foundSizing)
{
_sizingTimer.Change(100, int.MaxValue);
_sizingTimer.Change(50, int.MaxValue);
}

base.Render(context);
Expand Down Expand Up @@ -164,8 +183,9 @@ private void animationTick(object? sender, EventArgs args)

double progress = (double)_currentTick / _totalTicks;

Width = _desiredSize.Width * _easing.Ease(progress);
Height = _desiredSize.Height * _easing.Ease(progress);
if (_animateWidth) Width = _desiredSize.Width * _easing.Ease(progress);

if (_animateHeight) Height = _desiredSize.Height * _easing.Ease(progress);
}

private void updateAnimation()
Expand All @@ -180,38 +200,41 @@ private void completeAnimation()
{
if (_isOpen)
{
Width = _desiredSize.Width;
Height = _desiredSize.Height;
Width = double.NaN;
Height = double.NaN;

if (Parent is Grid g)
{
_underlay.IsVisible = true;

if (g.RowDefinitions.Count > 0)
{
_underlay.SetValue(Grid.RowSpanProperty, g.RowDefinitions.Count);
}

if (g.ColumnDefinitions.Count > 0)
{
_underlay.SetValue(Grid.ColumnSpanProperty, g.ColumnDefinitions.Count);
}

g.Children.Insert(0, _underlay);
insertIntoGrid(_underlay, g);
}
}
else
{
Width = 0;
Height = 0;
if (_animateHeight) Height = 0;

if (Parent is Grid g)
if (_animateWidth) Width = 0;

if (Parent is Grid g && g.Children.Contains(_underlay))
{
if (g.Children.Contains(_underlay))
{
g.Children.Remove(_underlay);
}
g.Children.Remove(_underlay);
}
}
}

private static void insertIntoGrid(Control control, Grid g)
{
control.IsVisible = true;

if (g.RowDefinitions.Count > 0)
{
control.SetValue(Grid.RowSpanProperty, g.RowDefinitions.Count);
}

if (g.ColumnDefinitions.Count > 0)
{
control.SetValue(Grid.ColumnSpanProperty, g.ColumnDefinitions.Count);
}

g.Children.Insert(0, control);
}
}
5 changes: 5 additions & 0 deletions Aosta.Ava/Aosta.Ava/Extensions/LocalizationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ namespace Aosta.Ava.Extensions;

public static class LocalizationExtensions
{
public static LocalizedData<T> WrapAndLocalize<T>(this T obj, string key)
{
return new LocalizedData<T>(obj, key);
}

public static LocalizedString Localize(this string key)
{
return LocalizedString.Create(key);
Expand Down
10 changes: 10 additions & 0 deletions Aosta.Ava/Aosta.Ava/Extensions/ModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ namespace Aosta.Ava.Extensions;

public static class ModelExtensions
{
public static LocalizedData<WatchingStatus> LocalizeWithData(this WatchingStatus status) => status switch
{
WatchingStatus.PlanToWatch => status.WrapAndLocalize("Enum.WatchingStatus.PlanToWatch"),
WatchingStatus.Dropped => status.WrapAndLocalize("Enum.WatchingStatus.Dropped"),
WatchingStatus.Completed => status.WrapAndLocalize("Enum.WatchingStatus.Completed"),
WatchingStatus.OnHold => status.WrapAndLocalize("Enum.WatchingStatus.OnHold"),
WatchingStatus.Watching => status.WrapAndLocalize("Enum.WatchingStatus.Watching"),
_ => throw new ArgumentOutOfRangeException(nameof(status), status, error_message(nameof(WatchingStatus)))
};

public static LocalizedString Localize(this WatchingStatus status) => status switch
{
WatchingStatus.PlanToWatch => "Enum.WatchingStatus.PlanToWatch".Localize(),
Expand Down
83 changes: 61 additions & 22 deletions Aosta.Ava/Aosta.Ava/Pages/LocalAnimeDetailsPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Aosta.Ava.Pages.LocalAnimeDetailsPage"
x:DataType="vm:LocalAnimeDetailsViewModel">
<UserControl.Styles>
<Style Selector="fluent|NumberBox">
<Setter Property="BorderThickness" Value="0" />
</Style>
</UserControl.Styles>
<Grid RowDefinitions="Auto,*">
<local:TitleBar Grid.Row="0"
Title="{Binding DefaultTitle}">
Expand All @@ -25,7 +20,7 @@
<fluent:CommandBar ClosedDisplayMode="Minimal"
Height="48">
<fluent:CommandBar.SecondaryCommands>
<fluent:CommandBarButton Label="{localize:Localize AnimeDetails.Menu.OpenOnMAL}"
<fluent:CommandBarButton Label="{localize:Localize Label.OpenOnMal}"
IconSource="Globe"
Command="{Binding OpenOnMal}" />
<fluent:CommandBarButton Label="{localize:Localize AnimeDetails.Menu.Remove}"
Expand Down Expand Up @@ -55,14 +50,53 @@
</Image.OpacityMask>
</Image>
<local:AnimatedPopup Grid.Row="0"
Grid.RowSpan="3"
Grid.RowSpan="4"
Name="ScorePopup"
AnimationTime="0:0:0.3">
<Border Height="200"
Background="Brown">
<TextBlock Text="CHIAPPAFAVA"
FontSize="48"
FontWeight="Bold"/>
VerticalAlignment="Top"
HorizontalAlignment="Center">
<Border Background="{DynamicResource FloatingPaneBackgroundBrush}"
Padding="20"
CornerRadius="0,0,20,20">
<StackPanel Orientation="Horizontal"
Spacing="10">
<NumericUpDown Name="ScoreNumberBox"
ToolTip.Tip="{localize:Localize AnimeDetails.Score.Watermark}"
ToolTip.Placement="Bottom"
ToolTip.VerticalOffset="0"
ToolTip.ShowDelay="1000"
Watermark="{localize:Localize AnimeDetails.Score.Watermark}"
Width="200"
Minimum="0"
Maximum="100"
Increment="1"
BorderThickness="0"
FormatString="F0"
ClipValueToMinMax="True"
ShowButtonSpinner="True" />
<Button Classes="accent"
Tapped="InputElement_OnTapped"
Height="36"
IsDefault="True"
Command="{Binding UpdateScore}"
CommandParameter="{Binding #ScoreNumberBox.Value}">
<fluent:FontIcon Glyph="{StaticResource CheckmarkGlyph}"
FontFamily="{StaticResource SymbolThemeFontFamily}" />
</Button>
</StackPanel>
</Border>
</local:AnimatedPopup>
<local:AnimatedPopup Grid.Row="0"
Grid.RowSpan="4"
Name="StatusPopup"
VerticalAlignment="Top"
HorizontalAlignment="Center">
<Border Background="{DynamicResource FloatingPaneBackgroundBrush}"
Padding="20"
CornerRadius="0,0,20,20">
<ComboBox ItemsSource="{Binding StatusList}"
SelectedItem="{Binding ComboBoxStatus}"
MinWidth="200"
SelectionChanged="SelectingItemsControl_OnSelectionChanged"/>
</Border>
</local:AnimatedPopup>
<Border Grid.Row="0"
Expand All @@ -81,7 +115,7 @@
Foreground="Gold"
VerticalAlignment="Center" />
<TextBlock
Text="{Binding Anime.UserScore, Converter={converters:ShortValueStringConverter}}"
Text="{Binding Anime.UserScore, Converter={converters:ShortValueStringConverter}, StringFormat={}{0} / 100}"
VerticalAlignment="Center" />
</StackPanel>
</Button>
Expand All @@ -90,21 +124,26 @@
Margin="10,10,10,0"
Background="{DynamicResource PureColorBackgroundBrush}"
HorizontalAlignment="Left"
Padding="10"
CornerRadius="5">
<StackPanel Orientation="Horizontal"
Spacing="5">
<fluent:FontIcon Glyph="{StaticResource CalendarGlyph}"
FontFamily="{StaticResource SymbolThemeFontFamily}" />
<ContentControl Content="{Binding Status}" />
</StackPanel>
<Button Command="{Binding #StatusPopup.Open}"
Background="Transparent"
Padding="10"
BorderThickness="0">
<StackPanel Orientation="Horizontal"
Spacing="5">
<fluent:FontIcon Glyph="{StaticResource CalendarGlyph}"
FontFamily="{StaticResource SymbolThemeFontFamily}" />
<ContentControl Content="{Binding Status}" />
</StackPanel>
</Button>
</Border>
<ContentControl Grid.Row="2"
Margin="10,10,10,0"
HorizontalAlignment="Right"
Content="{Binding DetailsPill}" />
<StackPanel Grid.Row="3"
Spacing="10">
Spacing="10"
Margin="10">
<TextBlock Text="{localize:Localize Label.Synopsis}"
FontSize="18"
FontWeight="Bold" />
Expand Down
Loading

0 comments on commit 42e524f

Please sign in to comment.