Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonofmercy committed Apr 13, 2023
1 parent e166e0a commit 9896f58
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 36 deletions.
2 changes: 1 addition & 1 deletion ImageViewer/Library/NotificationsManger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private async Task HandleNotificationAsync(AppNotificationActivatedEventArgs arg
}
catch(Exception ex)
{
var builder = new AppNotificationBuilder()
AppNotificationBuilder builder = new AppNotificationBuilder()
.AddText(ex.Message);

Runtime.Show(builder.BuildNotification());
Expand Down
59 changes: 24 additions & 35 deletions ImageViewer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,20 @@ private void CustomizeAppBar()

public void RedrawTitleBar()
{
if(AppWindowTitleBar.IsCustomizationSupported())
{
string themeName = MainPage.ActualTheme == ElementTheme.Dark ? "Dark" : "Light";
ResourceDictionary resourceTheme = (ResourceDictionary)Application.Current.Resources.ThemeDictionaries[themeName];
AppWindowTitleBar windowTitleBar = GetAppWindowForCurrentWindow().TitleBar;
if(!AppWindowTitleBar.IsCustomizationSupported()) return;

windowTitleBar.ButtonBackgroundColor = windowTitleBar.ButtonInactiveBackgroundColor = (resourceTheme["TitleBarButtonBackground"] as SolidColorBrush).Color;
windowTitleBar.ButtonForegroundColor = windowTitleBar.ButtonInactiveForegroundColor = (resourceTheme["TitleBarButtonForeground"] as SolidColorBrush).Color;
string themeName = MainPage.ActualTheme == ElementTheme.Dark ? "Dark" : "Light";
ResourceDictionary resourceTheme = (ResourceDictionary)Application.Current.Resources.ThemeDictionaries[themeName];
AppWindowTitleBar windowTitleBar = GetAppWindowForCurrentWindow().TitleBar;

windowTitleBar.ButtonHoverBackgroundColor = (resourceTheme["TitleBarButtonHoverBackground"] as SolidColorBrush).Color;
windowTitleBar.ButtonHoverForegroundColor = (resourceTheme["TitleBarButtonHoverForeground"] as SolidColorBrush).Color;
windowTitleBar.ButtonBackgroundColor = windowTitleBar.ButtonInactiveBackgroundColor = (resourceTheme["TitleBarButtonBackground"] as SolidColorBrush).Color;
windowTitleBar.ButtonForegroundColor = windowTitleBar.ButtonInactiveForegroundColor = (resourceTheme["TitleBarButtonForeground"] as SolidColorBrush).Color;

windowTitleBar.ButtonPressedBackgroundColor = (resourceTheme["TitleBarButtonPressedBackground"] as SolidColorBrush).Color;
windowTitleBar.ButtonPressedForegroundColor = (resourceTheme["TitleBarButtonPressedForeground"] as SolidColorBrush).Color;
}
windowTitleBar.ButtonHoverBackgroundColor = (resourceTheme["TitleBarButtonHoverBackground"] as SolidColorBrush).Color;
windowTitleBar.ButtonHoverForegroundColor = (resourceTheme["TitleBarButtonHoverForeground"] as SolidColorBrush).Color;

windowTitleBar.ButtonPressedBackgroundColor = (resourceTheme["TitleBarButtonPressedBackground"] as SolidColorBrush).Color;
windowTitleBar.ButtonPressedForegroundColor = (resourceTheme["TitleBarButtonPressedForeground"] as SolidColorBrush).Color;
}

public void UpdateTheme(ElementTheme theme)
Expand Down Expand Up @@ -101,15 +100,7 @@ public void UpdateTheme(ElementTheme theme)

public void UpdateTitle(string prefix = null)
{
if(string.IsNullOrEmpty(prefix))
{
Title = Context.GetProductName();
}
else
{
Title = string.Concat(prefix, " - ", Context.GetProductName());
}

Title = string.IsNullOrEmpty(prefix) ? Context.GetProductName() : string.Concat(prefix, " - ", Context.GetProductName());
AppTitleBarText.Text = Title;
}

Expand Down Expand Up @@ -342,14 +333,13 @@ private async void ImageContainer_Drop(object sender, DragEventArgs e)
{
try
{
if(e.DataView.Contains(StandardDataFormats.StorageItems))
{
IReadOnlyList<IStorageItem> items = await e.DataView.GetStorageItemsAsync();
if(!e.DataView.Contains(StandardDataFormats.StorageItems)) return;

IReadOnlyList<IStorageItem> items = await e.DataView.GetStorageItemsAsync();

if(items.Count > 0)
{
Context.Instance().LoadImageFromString(items[0].Path, true);
}
if(items.Count > 0)
{
Context.Instance().LoadImageFromString(items[0].Path, true);
}
}
catch(Exception ex)
Expand All @@ -369,14 +359,13 @@ private async void Window_Paste(KeyboardAccelerator sender, KeyboardAcceleratorI
{
DataPackageView clipboard = Clipboard.GetContent();

if(clipboard.Contains(StandardDataFormats.Bitmap))
{
ImageView.Opacity = 0;
ImageLoadingIndicator.IsActive = true;
if(!clipboard.Contains(StandardDataFormats.Bitmap)) return;

RandomAccessStreamReference clipboardImage = await clipboard.GetBitmapAsync();
Context.Instance().LoadImageFromBuffer(clipboardImage);
}
ImageView.Opacity = 0;
ImageLoadingIndicator.IsActive = true;

RandomAccessStreamReference clipboardImage = await clipboard.GetBitmapAsync();
Context.Instance().LoadImageFromBuffer(clipboardImage);
}
}
}

0 comments on commit 9896f58

Please sign in to comment.