UI - Added desktop notifications API

This commit is contained in:
SpoinkyNL committed 2021-01-10 12:49:36 +01:00
1 parent 883fccef7b
commit 30c4314f1d
15 files changed
+217 -42

No files matched your search

@@ -15,5 +15,6 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cdatamodelvisualization/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cdialog/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cinterfaces/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cmessage/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cwindow/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=utilities/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
@@ -13,6 +13,12 @@ namespace Artemis.UI.Shared.Services
/// </summary>
ISnackbarMessageQueue MainMessageQueue { get; }
/// <summary>
/// Sets up the notification provider that shows desktop notifications
/// </summary>
/// <param name="notificationProvider">The notification provider that shows desktop notifications</param>
void ConfigureNotificationProvider(INotificationProvider notificationProvider);
/// <summary>
/// Queues a notification message for display in a snackbar.
/// </summary>
@@ -111,5 +117,28 @@ namespace Artemis.UI.Shared.Services
bool promote,
bool neverConsiderToBeDuplicate,
TimeSpan? durationOverride = null);
/// <summary>
/// Shows a desktop notification
/// </summary>
/// <param name="title">The title of the notification</param>
/// <param name="message">The message of the notification</param>
void ShowNotification(string title, string message);
/// <summary>
/// Shows a desktop notification with a Material Design icon
/// </summary>
/// <param name="title">The title of the notification</param>
/// <param name="message">The message of the notification</param>
/// <param name="icon">The name of the icon</param>
void ShowNotification(string title, string message, PackIconKind icon);
/// <summary>
/// Shows a desktop notification with a Material Design icon
/// </summary>
/// <param name="title">The title of the notification</param>
/// <param name="message">The message of the notification</param>
/// <param name="icon">The name of the icon as a string</param>
void ShowNotification(string title, string message, string icon);
}
}
@@ -0,0 +1,19 @@
using MaterialDesignThemes.Wpf;
namespace Artemis.UI.Shared.Services
{
/// <summary>
/// Represents a class provides desktop notifications so that <see cref="IMessageService" /> can us it to show desktop
/// notifications
/// </summary>
public interface INotificationProvider
{
/// <summary>
/// Shows a notification
/// </summary>
/// <param name="title">The title of the notification</param>
/// <param name="message">The message of the notification</param>
/// <param name="icon">The Material Design icon to show in the notification</param>
void ShowNotification(string title, string message, PackIconKind icon);
}
}
@@ -5,13 +5,20 @@ namespace Artemis.UI.Shared.Services
{
internal class MessageService : IMessageService
{
private INotificationProvider _notificationProvider;
public ISnackbarMessageQueue MainMessageQueue { get; }
public MessageService(ISnackbarMessageQueue mainMessageQueue)
{
MainMessageQueue = mainMessageQueue;
}
/// <inheritdoc />
public void ConfigureNotificationProvider(INotificationProvider notificationProvider)
{
_notificationProvider = notificationProvider;
}
public void ShowMessage(object content)
{
MainMessageQueue.Enqueue(content);
@@ -63,5 +70,24 @@ namespace Artemis.UI.Shared.Services
{
MainMessageQueue.Enqueue(content, actionContent, actionHandler, actionArgument, promote, neverConsiderToBeDuplicate, durationOverride);
}
/// <inheritdoc />
public void ShowNotification(string title, string message)
{
_notificationProvider.ShowNotification(title, message, PackIconKind.None);
}
/// <inheritdoc />
public void ShowNotification(string title, string message, PackIconKind icon)
{
_notificationProvider.ShowNotification(title, message, icon);
}
/// <inheritdoc />
public void ShowNotification(string title, string message, string icon)
{
Enum.TryParse(typeof(PackIconKind), icon, true, out object? iconKind);
_notificationProvider.ShowNotification(title, message, (PackIconKind) (iconKind ?? PackIconKind.None));
}
}
}
@@ -1,12 +1,13 @@
using System;
using MaterialDesignThemes.Wpf;
namespace Artemis.UI.Shared.Services
{
/// <summary>
/// Represents a class that manages a main window, used by the <see cref="IWindowService" /> to control the state of
/// Represents a class that provides the main window, so that <see cref="IWindowService" /> can control the state of
/// the main window.
/// </summary>
public interface IMainWindowManager
public interface IMainWindowProvider
{
/// <summary>
/// Gets a boolean indicating whether the main window is currently open
@@ -13,10 +13,10 @@ namespace Artemis.UI.Shared.Services
bool IsMainWindowOpen { get; }
/// <summary>
/// Sets up the main window manager that controls the state of the main window
/// Sets up the main window provider that controls the state of the main window
/// </summary>
/// <param name="mainWindowManager">The main window manager to use to control the state of the main window</param>
void ConfigureMainWindowManager(IMainWindowManager mainWindowManager);
/// <param name="mainWindowProvider">The main window provider to use to control the state of the main window</param>
void ConfigureMainWindowProvider(IMainWindowProvider mainWindowProvider);
/// <summary>
/// Opens the main window if it is not already open
@@ -4,7 +4,7 @@ namespace Artemis.UI.Shared.Services
{
internal class WindowService : IWindowService
{
private IMainWindowManager? _mainWindowManager;
private IMainWindowProvider? _mainWindowManager;
protected virtual void OnMainWindowOpened()
{
@@ -46,9 +46,9 @@ namespace Artemis.UI.Shared.Services
public bool IsMainWindowOpen { get; private set; }
public void ConfigureMainWindowManager(IMainWindowManager mainWindowManager)
public void ConfigureMainWindowProvider(IMainWindowProvider mainWindowProvider)
{
if (mainWindowManager == null) throw new ArgumentNullException(nameof(mainWindowManager));
if (mainWindowProvider == null) throw new ArgumentNullException(nameof(mainWindowProvider));
if (_mainWindowManager != null)
{
@@ -56,7 +56,7 @@ namespace Artemis.UI.Shared.Services
_mainWindowManager.MainWindowClosed -= HandleMainWindowClosed;
}
_mainWindowManager = mainWindowManager;
_mainWindowManager = mainWindowProvider;
_mainWindowManager.MainWindowOpened += HandleMainWindowOpened;
_mainWindowManager.MainWindowClosed += HandleMainWindowClosed;