Skip to content

Commit

Permalink
make the rest of it work
Browse files Browse the repository at this point in the history
  • Loading branch information
WamWooWam committed Dec 27, 2024
1 parent 88d5d4d commit 0827be3
Show file tree
Hide file tree
Showing 21 changed files with 444 additions and 246 deletions.
6 changes: 4 additions & 2 deletions UniSky.Services/ModerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ namespace UniSky.Services;

public record struct LabelStrings(string Name, string Description);

public class ModerationService(IProtocolService protocolService, ILogger<ModerationService> logger) : IModerationService
public class ModerationService(
IProtocolService protocolService,
ILogger<ModerationService> logger) : IModerationService
{
private readonly ResourceLoader resources
= ResourceLoader.GetForCurrentView();
= ResourceLoader.GetForViewIndependentUse();

public ModerationOptions ModerationOptions { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions UniSky/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(RootPage), e.Arguments);
rootFrame.Navigate(typeof(RootPage), e.SplashScreen);
}

// Ensure the current window is active
Expand All @@ -152,7 +152,7 @@ private void OnProtocolActivated(ProtocolActivatedEventArgs e)
{
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
rootFrame.Navigate(typeof(RootPage));
rootFrame.Navigate(typeof(RootPage), e.SplashScreen);
Window.Current.Content = rootFrame;
}

Expand Down
120 changes: 65 additions & 55 deletions UniSky/Helpers/Composition/BirdAnimation.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Numerics;
using Microsoft.Toolkit.Uwp.UI.Animations.Behaviors;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry;
using Windows.Foundation;
using Windows.Foundation.Metadata;
Expand All @@ -11,38 +12,13 @@ namespace UniSky.Helpers.Composition;

internal static class BirdAnimation
{
public static void RunBirdAnimation(FrameworkElement frame)
public static void RunBirdAnimation(FrameworkElement extendedSplash, FrameworkElement frame)
{
// TODO: fallback to a shape visual
if (!ApiInformation.IsMethodPresent(typeof(Compositor).FullName, "CreateGeometricClip"))
return;

var appLogoPath = (string)Application.Current.Resources["BlueSkyLogoPath"];
var appLogoWidth = (int)Application.Current.Resources["BlueSkyLogoWidth"];
var appLogoHeight = (int)Application.Current.Resources["BlueSkyLogoHeight"];

var size = new Size(frame.ActualWidth, frame.ActualHeight);
var frameVisual = ElementCompositionPreview.GetElementVisual(frame);

var initialScale = (float)(1.5 * Math.Min(size.Width / 620, 1.0));

var scale = MathF.Max((float)size.Width / 30, (float)size.Height / 12);
var offsetX = (float)(size.Width / 2.0);
var offsetY = (float)(size.Height / 2.0);
var splashVisual = ElementCompositionPreview.GetElementVisual(extendedSplash);

var compositor = frameVisual.Compositor;
var clip = compositor.CreateGeometricClip(appLogoPath);
clip.ViewBox = compositor.CreateViewBox();
clip.ViewBox.Size = new Vector2(appLogoWidth, appLogoHeight);
clip.ViewBox.Stretch = CompositionStretch.None;
clip.AnchorPoint = new Vector2(0.5f, 0.5f);
clip.Scale = new Vector2(initialScale, initialScale);
clip.Offset = new Vector2(offsetX, offsetY);

frameVisual.AnchorPoint = new Vector2(0.5f);
frameVisual.Offset = new Vector3((float)(size.Width / 2), (float)(size.Height / 2), 0);
frameVisual.Clip = clip;

var batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
batch.Completed += (o, ev) =>
{
Expand All @@ -51,34 +27,68 @@ public static void RunBirdAnimation(FrameworkElement frame)
frameVisual.Offset = Vector3.Zero;
};

var ease = compositor.CreateCubicBezierEasingFunction(new Vector2(0.7f, 0), new Vector2(0.84f, 0));
var ease2 = compositor.CreateCubicBezierEasingFunction(new Vector2(0, 0.55f), new Vector2(0.45f, 1));

var group = compositor.CreateAnimationGroup();

var scaleAnimation = compositor.CreateVector2KeyFrameAnimation();
scaleAnimation.InsertKeyFrame(1.0f, new Vector2(scale, scale), ease);
scaleAnimation.DelayTime = TimeSpan.FromSeconds(0.15);
scaleAnimation.Duration = TimeSpan.FromSeconds(0.15);
scaleAnimation.Target = "Scale";
group.Add(scaleAnimation);

var offsetAnimation = compositor.CreateVector2KeyFrameAnimation();
offsetAnimation.InsertKeyFrame(1.0f, new Vector2(offsetX, offsetY - (6 * scale)), ease);
offsetAnimation.DelayTime = TimeSpan.FromSeconds(0.15);
offsetAnimation.Duration = TimeSpan.FromSeconds(0.15);
offsetAnimation.Target = "Offset";
group.Add(offsetAnimation);

var scaleAnimation2 = compositor.CreateVector3KeyFrameAnimation();
scaleAnimation2.InsertKeyFrame(0.5f, new Vector3(1.1f), ease);
scaleAnimation2.InsertKeyFrame(1.0f, new Vector3(1.0f), ease2);
scaleAnimation2.DelayTime = TimeSpan.FromSeconds(0.15);
scaleAnimation2.Duration = TimeSpan.FromSeconds(0.3);
scaleAnimation2.Target = "Scale";

clip.StartAnimationGroup(group);
frameVisual.StartAnimation(scaleAnimation2.Target, scaleAnimation2);
var splashHideAnimation = compositor.CreateScalarKeyFrameAnimation();
splashHideAnimation.InsertKeyFrame(0.0f, 1.0f);
splashHideAnimation.InsertKeyFrame(1.0f, 0.0f);
splashHideAnimation.DelayTime = TimeSpan.FromSeconds(0);
splashHideAnimation.Duration = TimeSpan.FromSeconds(0.15);

if (ApiInformation.IsMethodPresent(typeof(Compositor).FullName, "CreateGeometricClip"))
{
var appLogoPath = (string)Application.Current.Resources["BlueSkyLogoPath"];
var appLogoWidth = (int)Application.Current.Resources["BlueSkyLogoWidth"];
var appLogoHeight = (int)Application.Current.Resources["BlueSkyLogoHeight"];

var size = new Size(frame.ActualWidth, frame.ActualHeight);

var initialScale = (float)(1.5 * Math.Min(size.Width / 620, 1.0));

var scale = MathF.Max((float)size.Width / 30, (float)size.Height / 12);
var offsetX = (float)(size.Width / 2.0);
var offsetY = (float)(size.Height / 2.0);

var clip = compositor.CreateGeometricClip(appLogoPath);
clip.ViewBox = compositor.CreateViewBox();
clip.ViewBox.Size = new Vector2(appLogoWidth, appLogoHeight);
clip.ViewBox.Stretch = CompositionStretch.None;
clip.AnchorPoint = new Vector2(0.5f, 0.5f);
clip.Scale = new Vector2(initialScale, initialScale);
clip.Offset = new Vector2(offsetX, offsetY);

frameVisual.AnchorPoint = new Vector2(0.5f);
frameVisual.Offset = new Vector3((float)(size.Width / 2), (float)(size.Height / 2), 0);
frameVisual.Clip = clip;

var ease = compositor.CreateCubicBezierEasingFunction(new Vector2(0.7f, 0), new Vector2(0.84f, 0));
var ease2 = compositor.CreateCubicBezierEasingFunction(new Vector2(0, 0.55f), new Vector2(0.45f, 1));
var group = compositor.CreateAnimationGroup();

var scaleAnimation = compositor.CreateVector2KeyFrameAnimation();
scaleAnimation.InsertKeyFrame(1.0f, new Vector2(scale, scale), ease);
scaleAnimation.DelayTime = TimeSpan.FromSeconds(0.15);
scaleAnimation.Duration = TimeSpan.FromSeconds(0.15);
scaleAnimation.Target = "Scale";
group.Add(scaleAnimation);

var offsetAnimation = compositor.CreateVector2KeyFrameAnimation();
offsetAnimation.InsertKeyFrame(1.0f, new Vector2(offsetX, offsetY - (6 * scale)), ease);
offsetAnimation.DelayTime = TimeSpan.FromSeconds(0.15);
offsetAnimation.Duration = TimeSpan.FromSeconds(0.15);
offsetAnimation.Target = "Offset";
group.Add(offsetAnimation);

var scaleAnimation2 = compositor.CreateVector3KeyFrameAnimation();
scaleAnimation2.InsertKeyFrame(0.5f, new Vector3(1.1f), ease);
scaleAnimation2.InsertKeyFrame(1.0f, new Vector3(1.0f), ease2);
scaleAnimation2.DelayTime = TimeSpan.FromSeconds(0.15);
scaleAnimation2.Duration = TimeSpan.FromSeconds(0.3);
scaleAnimation2.Target = "Scale";

clip.StartAnimationGroup(group);
frameVisual.StartAnimation(scaleAnimation2.Target, scaleAnimation2);
}

splashVisual.StartAnimation("Opacity", splashHideAnimation);

batch.End();
}
Expand Down
2 changes: 1 addition & 1 deletion UniSky/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<uap:ShowOn Tile="wide310x150Logo"/>
</uap:ShowNameOnTiles>
</uap:DefaultTile >
<uap:SplashScreen Image="Assets\SplashScreen.png" BackgroundColor="#0085ff" />
<uap:SplashScreen Image="Assets\SplashScreen.png" BackgroundColor="#0085ff" uap5:Optional="true" />
<uap:LockScreen Notification="badge" BadgeLogo="Assets\BadgeLogo.png"/>
</uap:VisualElements>
<Extensions>
Expand Down
9 changes: 5 additions & 4 deletions UniSky/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
Window.Current.SetTitleBar(TitleBarDrag);

var safeAreaService = ServiceContainer.Scoped.GetRequiredService<ISafeAreaService>();
safeAreaService.SetTitlebarTheme(ElementTheme.Default);
safeAreaService.SafeAreaUpdated += OnSafeAreaUpdated;

if (e.Parameter is string session || e.Parameter is ATDid did && (session = did.Handler) != null)
{
ViewModel = ActivatorUtilities.CreateInstance<HomeViewModel>(ServiceContainer.Scoped, session);
}
if (e.Parameter is not HomeViewModel)
return;

DataContext = ViewModel = (HomeViewModel)e.Parameter;
}

private void OnSafeAreaUpdated(object sender, SafeAreaUpdatedEventArgs e)
Expand Down
52 changes: 50 additions & 2 deletions UniSky/Pages/LoginPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,55 @@

</Grid>

<!--<Image Source="/Assets/SplashScreen.png" MaxWidth="620" Stretch="Uniform" Grid.RowSpan="5" Grid.ColumnSpan="3"/>-->
<Grid x:Name="AppTitleBar"
Background="Transparent"
Grid.RowSpan="5"
Grid.ColumnSpan="3"
VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="LeftPaddingColumn" Width="0"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>

<Border x:Name="TitleBarDrag"
Background="Transparent"
Grid.Column="1"
Grid.ColumnSpan="2"/>

<Grid Grid.Column="1"
HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="32"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RenderTransform>
<TranslateTransform x:Name="TitleHeaderTransform"/>
</Grid.RenderTransform>

<Viewbox VerticalAlignment="Center"
HorizontalAlignment="Center"
Margin="8,2,0,0"
Width="16"
Height="16"
Grid.Column="1"
IsHitTestVisible="False"
CacheMode="BitmapCache">
<Path x:Name="AppIconPath"
Data="{StaticResource BlueSkyLogoPath}"
Fill="{ThemeResource ApplicationForegroundThemeBrush}"/>
</Viewbox>

<TextBlock x:Name="AppTitleTextBlock"
x:Uid="AppTitle"
Style="{StaticResource CaptionTextBlockStyle}"
Text="Unisky"
VerticalAlignment="Center"
Grid.Column="2"
Margin="8,0"
IsHitTestVisible="False"/>
</Grid>
</Grid>

<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="AdaptiveStates">
Expand All @@ -178,7 +226,7 @@
<Setter Target="SeparatorBorder.BorderBrush" Value="{ThemeResource SeparatorBrush}"/>
<Setter Target="RightGrid.VerticalAlignment" Value="Center"/>
<Setter Target="RightGrid.HorizontalAlignment" Value="Left"/>
<Setter Target="RightGrid.MinWidth" Value="300"/>
<Setter Target="RightGrid.Width" Value="300"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Mobile">
Expand Down
26 changes: 25 additions & 1 deletion UniSky/Pages/LoginPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,36 @@ public LoginViewModel ViewModel
public LoginPage()
{
this.InitializeComponent();
this.ViewModel = ActivatorUtilities.CreateInstance<LoginViewModel>(ServiceContainer.Scoped);
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.Frame.BackStack.Clear();

var safeAreaService = ServiceContainer.Scoped.GetRequiredService<ISafeAreaService>();
safeAreaService.SetTitleBar(TitleBarDrag);
safeAreaService.SetTitlebarTheme(ElementTheme.Default);
safeAreaService.SafeAreaUpdated += OnSafeAreaUpdated;

if (e.Parameter is not LoginViewModel vm)
return;

DataContext = ViewModel = vm;
}

private void OnSafeAreaUpdated(object sender, SafeAreaUpdatedEventArgs e)
{
if (e.SafeArea.HasTitleBar)
{
AppTitleBar.Visibility = Visibility.Visible;
AppTitleBar.Height = e.SafeArea.Bounds.Top;
}
else
{
AppTitleBar.Visibility = Visibility.Collapsed;
}

Margin = new Thickness(e.SafeArea.Bounds.Left, 0, e.SafeArea.Bounds.Right, e.SafeArea.Bounds.Bottom);
}

public bool IsNotNull(object o)
Expand Down
1 change: 1 addition & 0 deletions UniSky/Pages/NotificationsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
base.OnNavigatedTo(e);

var safeAreaService = ServiceContainer.Scoped.GetRequiredService<ISafeAreaService>();
safeAreaService.SetTitlebarTheme(ElementTheme.Default);
safeAreaService.SafeAreaUpdated += OnSafeAreaUpdated;

if (this.ViewModel == null)
Expand Down
1 change: 1 addition & 0 deletions UniSky/Pages/ProfilePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
base.OnNavigatedTo(e);

var safeAreaService = ServiceContainer.Scoped.GetRequiredService<ISafeAreaService>();
safeAreaService.SetTitlebarTheme(ElementTheme.Default);
safeAreaService.SafeAreaUpdated += OnSafeAreaUpdated;

if (e.Parameter is Uri { Scheme: "unisky" } uri)
Expand Down
1 change: 1 addition & 0 deletions UniSky/Pages/SearchPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
base.OnNavigatedTo(e);

var safeAreaService = ServiceContainer.Scoped.GetRequiredService<ISafeAreaService>();
safeAreaService.SetTitlebarTheme(ElementTheme.Default);
safeAreaService.SafeAreaUpdated += OnSafeAreaUpdated;

if (this.ViewModel == null)
Expand Down
1 change: 1 addition & 0 deletions UniSky/Pages/ThreadPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
base.OnNavigatedTo(e);

var safeAreaService = ServiceContainer.Scoped.GetRequiredService<ISafeAreaService>();
safeAreaService.SetTitlebarTheme(ElementTheme.Default);
safeAreaService.SafeAreaUpdated += OnSafeAreaUpdated;

if (e.Parameter is not (ATUri))
Expand Down
30 changes: 26 additions & 4 deletions UniSky/RootPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,38 @@
xmlns:sheet="using:UniSky.Controls.Sheet"
mc:Ignorable="d"
NavigationCacheMode="Required">
<Page.DataContext>
<viewmodels:RootViewModel/>
</Page.DataContext>

<Grid>
<Canvas x:Name="RenderTargetRoot"/>
<Border Background="#FF0085ff"/>
<sheet:SheetRootControl x:Name="SheetRoot"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Frame x:Name="RootFrame"/>
<Frame x:Name="RootFrame"
Navigated="RootFrame_Navigated"/>
</sheet:SheetRootControl>

<Canvas x:Name="ExtendedSplash"
IsHitTestVisible="False"
Background="#FF0085ff">
<Viewbox x:Name="ExtendedSplashContainer">
<Grid x:Name="ExtendedSplashImage"
Width="620"
Height="300">
<Viewbox Width="100"
Height="100"
VerticalAlignment="Center"
HorizontalAlignment="Center"
CacheMode="BitmapCache">
<Path Data="{StaticResource BlueSkyLogoPath}"
Fill="White"/>
</Viewbox>
</Grid>
</Viewbox>
<ProgressRing x:Name="ExtendedProgressRing"
Foreground="White"
IsActive="True"
Width="32"
Height="32"/>
</Canvas>
</Grid>
</Page>
Loading

0 comments on commit 0827be3

Please sign in to comment.