Files
Wino-Mail/Wino.Core.UWP/Dialogs/CustomThemeBuilderDialog.xaml.cs

65 lines
1.8 KiB
C#
Raw Permalink Normal View History

2024-04-18 01:44:37 +02:00
using System;
using CommunityToolkit.WinUI.Helpers;
using Microsoft.Extensions.DependencyInjection;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Wino.Core.Domain.Interfaces;
using Wino.Core.UWP;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
namespace Wino.Dialogs;
public sealed partial class CustomThemeBuilderDialog : ContentDialog
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
public byte[] WallpaperData { get; private set; }
public string AccentColor { get; private set; }
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private IThemeService _themeService;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public CustomThemeBuilderDialog()
{
InitializeComponent();
2025-02-16 11:54:23 +01:00
_themeService = WinoApplication.Current.Services.GetService<IThemeService>();
}
2025-02-16 11:54:23 +01:00
private async void ApplyClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
if (Array.Empty<byte>() == WallpaperData)
return;
2025-02-16 11:54:23 +01:00
var deferal = args.GetDeferral();
2025-02-16 11:54:23 +01:00
try
{
await _themeService.CreateNewCustomThemeAsync(ThemeNameBox.Text, AccentColor, WallpaperData);
2025-02-16 11:35:43 +01:00
}
2025-02-16 11:54:23 +01:00
catch (Exception exception)
{
2025-02-16 11:54:23 +01:00
ErrorTextBlock.Text = exception.Message;
}
finally
{
deferal.Complete();
}
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private async void BrowseWallpaperClicked(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
var dialogService = WinoApplication.Current.Services.GetService<IMailDialogService>();
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
var pickedFileData = await dialogService.PickWindowsFileContentAsync(".jpg", ".png");
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
if (pickedFileData == Array.Empty<byte>()) return;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
IsPrimaryButtonEnabled = true;
2025-02-16 11:35:43 +01:00
2025-02-16 11:54:23 +01:00
WallpaperData = pickedFileData;
}
private void PickerColorChanged(Microsoft.UI.Xaml.Controls.ColorPicker sender, Microsoft.UI.Xaml.Controls.ColorChangedEventArgs args)
{
PreviewAccentColorGrid.Background = new SolidColorBrush(args.NewColor);
AccentColor = args.NewColor.ToHex();
2024-04-18 01:44:37 +02:00
}
}