Add mail categories support
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<ContentDialog
|
||||
x:Class="Wino.Dialogs.EditMailCategoryDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:domain="using:Wino.Core.Domain"
|
||||
xmlns:helpers="using:Wino.Helpers"
|
||||
xmlns:mailModels="using:Wino.Core.Domain.Models.MailItem"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
DefaultButton="Primary"
|
||||
PrimaryButtonClick="SaveClicked"
|
||||
PrimaryButtonText="{x:Bind domain:Translator.Buttons_Save, Mode=OneTime}"
|
||||
SecondaryButtonClick="CancelClicked"
|
||||
SecondaryButtonText="{x:Bind domain:Translator.Buttons_Cancel, Mode=OneTime}"
|
||||
Style="{StaticResource WinoDialogStyle}"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<ContentDialog.Resources>
|
||||
<x:Double x:Key="ContentDialogMinWidth">520</x:Double>
|
||||
<x:Double x:Key="ContentDialogMaxWidth">520</x:Double>
|
||||
</ContentDialog.Resources>
|
||||
|
||||
<StackPanel Spacing="16">
|
||||
<TextBox
|
||||
x:Name="CategoryNameTextBox"
|
||||
Header="{x:Bind domain:Translator.MailCategoryDialog_Name, Mode=OneTime}"
|
||||
PlaceholderText="{x:Bind domain:Translator.MailCategoryDialog_NamePlaceholder, Mode=OneTime}"
|
||||
Text="{x:Bind CategoryName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
TextChanged="CategoryNameTextChanged" />
|
||||
|
||||
<StackPanel Spacing="8">
|
||||
<TextBlock Style="{StaticResource BodyStrongTextBlockStyle}" Text="{x:Bind domain:Translator.MailCategoryDialog_Color, Mode=OneTime}" />
|
||||
|
||||
<GridView
|
||||
x:Name="ColorsGridView"
|
||||
IsItemClickEnabled="True"
|
||||
ItemClick="ColorOptionClicked"
|
||||
ItemsSource="{x:Bind AvailableColors, Mode=OneWay}"
|
||||
SelectedItem="{x:Bind SelectedColor, Mode=TwoWay}"
|
||||
SelectionMode="Single">
|
||||
<GridView.ItemTemplate>
|
||||
<DataTemplate x:DataType="mailModels:MailCategoryColorOption">
|
||||
<Border
|
||||
Width="100"
|
||||
Padding="8,6"
|
||||
Background="{x:Bind helpers:XamlHelpers.GetSolidColorBrushFromHex(BackgroundColorHex), Mode=OneWay}"
|
||||
BorderBrush="{x:Bind helpers:XamlHelpers.GetSolidColorBrushFromHex(TextColorHex), Mode=OneWay}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="10">
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
Foreground="{x:Bind helpers:XamlHelpers.GetSolidColorBrushFromHex(TextColorHex), Mode=OneWay}"
|
||||
Text="Preview" />
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</GridView.ItemTemplate>
|
||||
</GridView>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</ContentDialog>
|
||||
@@ -0,0 +1,59 @@
|
||||
using System.Linq;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities.Mail;
|
||||
using Wino.Core.Domain.Models.MailItem;
|
||||
|
||||
namespace Wino.Dialogs;
|
||||
|
||||
public sealed partial class EditMailCategoryDialog : ContentDialog
|
||||
{
|
||||
public MailCategoryDialogResult? Result { get; private set; }
|
||||
public string CategoryName { get; set; }
|
||||
public MailCategoryColorOption? SelectedColor { get; set; }
|
||||
|
||||
public System.Collections.Generic.IReadOnlyList<MailCategoryColorOption> AvailableColors => MailCategoryPalette.DefaultOptions;
|
||||
|
||||
public EditMailCategoryDialog(MailCategory? category = null)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Title = category == null ? Translator.MailCategoryDialog_CreateTitle : Translator.MailCategoryDialog_EditTitle;
|
||||
CategoryName = category?.Name ?? string.Empty;
|
||||
SelectedColor = MailCategoryPalette.DefaultOptions.FirstOrDefault(a =>
|
||||
a.BackgroundColorHex == category?.BackgroundColorHex &&
|
||||
a.TextColorHex == category?.TextColorHex) ?? MailCategoryPalette.DefaultOptions.First();
|
||||
|
||||
IsPrimaryButtonEnabled = !string.IsNullOrWhiteSpace(CategoryName);
|
||||
}
|
||||
|
||||
private void CategoryNameTextChanged(object sender, TextChangedEventArgs e)
|
||||
=> IsPrimaryButtonEnabled = !string.IsNullOrWhiteSpace(CategoryNameTextBox.Text) && SelectedColor != null;
|
||||
|
||||
private void ColorOptionClicked(object sender, ItemClickEventArgs e)
|
||||
{
|
||||
if (e.ClickedItem is MailCategoryColorOption option)
|
||||
{
|
||||
SelectedColor = option;
|
||||
ColorsGridView.SelectedItem = option;
|
||||
IsPrimaryButtonEnabled = !string.IsNullOrWhiteSpace(CategoryNameTextBox.Text);
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
||||
{
|
||||
if (SelectedColor == null)
|
||||
{
|
||||
args.Cancel = true;
|
||||
return;
|
||||
}
|
||||
|
||||
Result = new MailCategoryDialogResult(CategoryNameTextBox.Text?.Trim(), SelectedColor.BackgroundColorHex, SelectedColor.TextColorHex);
|
||||
Hide();
|
||||
}
|
||||
|
||||
private void CancelClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user