Updating - Added UI for updating (actual update not yet implemented)

Shared UI - Added message service for easy access to the snackbar 🍟
This commit is contained in:
SpoinkyNL committed 2021-01-10 00:20:01 +01:00
1 parent 45fef11a67
commit 883fccef7b
21 files changed
+777 -54

No files matched your search

@@ -15,4 +15,5 @@
<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_005Cwindow/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=utilities/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
@@ -0,0 +1,115 @@
using System;
using MaterialDesignThemes.Wpf;
namespace Artemis.UI.Shared.Services
{
/// <summary>
/// Providers messaging functionality
/// </summary>
public interface IMessageService : IArtemisSharedUIService
{
/// <summary>
/// Gets the main snackbar message queue used by <see cref="ShowMessage(object)" /> and its overloads
/// </summary>
ISnackbarMessageQueue MainMessageQueue { get; }
/// <summary>
/// Queues a notification message for display in a snackbar.
/// </summary>
/// <param name="content">Message.</param>
void ShowMessage(object content);
/// <summary>
/// Queues a notification message for display in a snackbar.
/// </summary>
/// <param name="content">Message.</param>
/// <param name="actionContent">Content for the action button.</param>
/// <param name="actionHandler">Call back to be executed if user clicks the action button.</param>
void ShowMessage(object content, object actionContent, Action actionHandler);
/// <summary>
/// Queues a notification message for display in a snackbar.
/// </summary>
/// <param name="content">Message.</param>
/// <param name="actionContent">Content for the action button.</param>
/// <param name="actionHandler">Call back to be executed if user clicks the action button.</param>
/// <param name="actionArgument">Argument to pass to <paramref name="actionHandler" />.</param>
void ShowMessage<TArgument>(
object content,
object actionContent,
Action<TArgument> actionHandler,
TArgument actionArgument);
/// <summary>
/// Queues a notification message for display in a snackbar.
/// </summary>
/// <param name="content">Message.</param>
/// <param name="neverConsiderToBeDuplicate">
/// Subsequent, duplicate messages queued within a short time span will
/// be discarded. To override this behaviour and ensure the message always gets displayed set to <c>true</c>.
/// </param>
void ShowMessage(object content, bool neverConsiderToBeDuplicate);
/// <summary>
/// Queues a notification message for display in a snackbar.
/// </summary>
/// <param name="content">Message.</param>
/// <param name="actionContent">Content for the action button.</param>
/// <param name="actionHandler">Call back to be executed if user clicks the action button.</param>
/// <param name="promote">The message will promoted to the front of the queue.</param>
void ShowMessage(object content, object actionContent, Action actionHandler, bool promote);
/// <summary>
/// Queues a notification message for display in a snackbar.
/// </summary>
/// <param name="content">Message.</param>
/// <param name="actionContent">Content for the action button.</param>
/// <param name="actionHandler">Call back to be executed if user clicks the action button.</param>
/// <param name="actionArgument">Argument to pass to <paramref name="actionHandler" />.</param>
/// <param name="promote">The message will be promoted to the front of the queue and never considered to be a duplicate.</param>
void ShowMessage<TArgument>(
object content,
object actionContent,
Action<TArgument> actionHandler,
TArgument actionArgument,
bool promote);
/// <summary>
/// Queues a notification message for display in a snackbar.
/// </summary>
/// <param name="content">Message.</param>
/// <param name="actionContent">Content for the action button.</param>
/// <param name="actionHandler">Call back to be executed if user clicks the action button.</param>
/// <param name="actionArgument">Argument to pass to <paramref name="actionHandler" />.</param>
/// <param name="promote">The message will be promoted to the front of the queue.</param>
/// <param name="neverConsiderToBeDuplicate">The message will never be considered a duplicate.</param>
/// <param name="durationOverride">Message show duration override.</param>
void ShowMessage<TArgument>(
object content,
object actionContent,
Action<TArgument> actionHandler,
TArgument actionArgument,
bool promote,
bool neverConsiderToBeDuplicate,
TimeSpan? durationOverride = null);
/// <summary>
/// Queues a notification message for display in a snackbar.
/// </summary>
/// <param name="content">Message.</param>
/// <param name="actionContent">Content for the action button.</param>
/// <param name="actionHandler">Call back to be executed if user clicks the action button.</param>
/// <param name="actionArgument">Argument to pass to <paramref name="actionHandler" />.</param>
/// <param name="promote">The message will promoted to the front of the queue.</param>
/// <param name="neverConsiderToBeDuplicate">The message will never be considered a duplicate.</param>
/// <param name="durationOverride">Message show duration override.</param>
void ShowMessage(
object content,
object actionContent,
Action<object> actionHandler,
object actionArgument,
bool promote,
bool neverConsiderToBeDuplicate,
TimeSpan? durationOverride = null);
}
}
@@ -0,0 +1,67 @@
using System;
using MaterialDesignThemes.Wpf;
namespace Artemis.UI.Shared.Services
{
internal class MessageService : IMessageService
{
public ISnackbarMessageQueue MainMessageQueue { get; }
public MessageService(ISnackbarMessageQueue mainMessageQueue)
{
MainMessageQueue = mainMessageQueue;
}
public void ShowMessage(object content)
{
MainMessageQueue.Enqueue(content);
}
public void ShowMessage(object content, object actionContent, Action actionHandler)
{
MainMessageQueue.Enqueue(content, actionContent, actionHandler);
}
public void ShowMessage<TArgument>(object content, object actionContent, Action<TArgument> actionHandler, TArgument actionArgument)
{
MainMessageQueue.Enqueue(content, actionContent, actionHandler, actionArgument);
}
public void ShowMessage(object content, bool neverConsiderToBeDuplicate)
{
MainMessageQueue.Enqueue(content, neverConsiderToBeDuplicate);
}
public void ShowMessage(object content, object actionContent, Action actionHandler, bool promote)
{
MainMessageQueue.Enqueue(content, actionContent, actionHandler, promote);
}
public void ShowMessage<TArgument>(object content, object actionContent, Action<TArgument> actionHandler, TArgument actionArgument, bool promote)
{
MainMessageQueue.Enqueue(content, actionContent, actionHandler, actionArgument, promote);
}
public void ShowMessage<TArgument>(object content,
object actionContent,
Action<TArgument> actionHandler,
TArgument actionArgument,
bool promote,
bool neverConsiderToBeDuplicate,
TimeSpan? durationOverride = null)
{
MainMessageQueue.Enqueue(content, actionContent, actionHandler, actionArgument, promote, neverConsiderToBeDuplicate, durationOverride);
}
public void ShowMessage(object content,
object actionContent,
Action<object> actionHandler,
object actionArgument,
bool promote,
bool neverConsiderToBeDuplicate,
TimeSpan? durationOverride = null)
{
MainMessageQueue.Enqueue(content, actionContent, actionHandler, actionArgument, promote, neverConsiderToBeDuplicate, durationOverride);
}
}
}
@@ -0,0 +1,38 @@
using System;
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
/// the main window.
/// </summary>
public interface IMainWindowManager
{
/// <summary>
/// Gets a boolean indicating whether the main window is currently open
/// </summary>
bool IsMainWindowOpen { get; }
/// <summary>
/// Opens the main window
/// </summary>
/// <returns></returns>
bool OpenMainWindow();
/// <summary>
/// Closes the main window
/// </summary>
/// <returns></returns>
bool CloseMainWindow();
/// <summary>
/// Occurs when the main window has been opened
/// </summary>
public event EventHandler? MainWindowOpened;
/// <summary>
/// Occurs when the main window has been closed
/// </summary>
public event EventHandler? MainWindowClosed;
}
}
@@ -0,0 +1,41 @@
using System;
namespace Artemis.UI.Shared.Services
{
/// <summary>
/// A service that allows you to view, monitor and manage the open/close state of the main window
/// </summary>
public interface IWindowService : IArtemisSharedUIService
{
/// <summary>
/// Gets a boolean indicating whether the main window is currently open
/// </summary>
bool IsMainWindowOpen { get; }
/// <summary>
/// Sets up the main window manager 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);
/// <summary>
/// Opens the main window if it is not already open
/// </summary>
void OpenMainWindow();
/// <summary>
/// Closes the main window if it is not already closed
/// </summary>
void CloseMainWindow();
/// <summary>
/// Occurs when the main window has been opened
/// </summary>
public event EventHandler? MainWindowOpened;
/// <summary>
/// Occurs when the main window has been closed
/// </summary>
public event EventHandler? MainWindowClosed;
}
}
@@ -0,0 +1,82 @@
using System;
namespace Artemis.UI.Shared.Services
{
internal class WindowService : IWindowService
{
private IMainWindowManager? _mainWindowManager;
protected virtual void OnMainWindowOpened()
{
MainWindowOpened?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnMainWindowClosed()
{
MainWindowClosed?.Invoke(this, EventArgs.Empty);
}
private void SyncWithManager()
{
if (_mainWindowManager == null)
return;
if (IsMainWindowOpen && !_mainWindowManager.IsMainWindowOpen)
{
IsMainWindowOpen = false;
OnMainWindowClosed();
}
if (!IsMainWindowOpen && _mainWindowManager.IsMainWindowOpen)
{
IsMainWindowOpen = true;
OnMainWindowOpened();
}
}
private void HandleMainWindowOpened(object? sender, EventArgs e)
{
SyncWithManager();
}
private void HandleMainWindowClosed(object? sender, EventArgs e)
{
SyncWithManager();
}
public bool IsMainWindowOpen { get; private set; }
public void ConfigureMainWindowManager(IMainWindowManager mainWindowManager)
{
if (mainWindowManager == null) throw new ArgumentNullException(nameof(mainWindowManager));
if (_mainWindowManager != null)
{
_mainWindowManager.MainWindowOpened -= HandleMainWindowOpened;
_mainWindowManager.MainWindowClosed -= HandleMainWindowClosed;
}
_mainWindowManager = mainWindowManager;
_mainWindowManager.MainWindowOpened += HandleMainWindowOpened;
_mainWindowManager.MainWindowClosed += HandleMainWindowClosed;
// Sync up with the new manager's state
SyncWithManager();
}
public void OpenMainWindow()
{
IsMainWindowOpen = true;
OnMainWindowOpened();
}
public void CloseMainWindow()
{
IsMainWindowOpen = false;
OnMainWindowClosed();
}
public event EventHandler? MainWindowOpened;
public event EventHandler? MainWindowClosed;
}
}