aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy@twine-s.com>2020-12-30 15:11:34 +0000
committerRoy Ben Shabat <Roy@twine-s.com>2020-12-30 15:11:34 +0000
commitd33c19b3ac6803de4b5c8d475832efef131c1a45 (patch)
treeea725abc39def99a755b041c13cba1fe0d594ddc /Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications
parent1bdcaa9f51303bbff682507f31fb3b4414692ca4 (diff)
downloadTango-d33c19b3ac6803de4b5c8d475832efef131c1a45.tar.gz
Tango-d33c19b3ac6803de4b5c8d475832efef131c1a45.zip
Revert "Hope it is fine"
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs128
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs52
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml30
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml.cs30
4 files changed, 193 insertions, 47 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs
index 65337a892..e9de2538e 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs
@@ -17,6 +17,8 @@ using Tango.Touch.Controls;
using Tango.SharedUI;
using System.Reflection;
using Tango.Core.DI;
+using System.ComponentModel;
+using System.Windows.Data;
namespace Tango.PPC.UI.Notifications
{
@@ -47,6 +49,16 @@ namespace Tango.PPC.UI.Notifications
public ObservableCollection<NotificationItem> NotificationItems { get; private set; }
/// <summary>
+ /// Gets the application bar items.
+ /// </summary>
+ public ObservableCollection<AppBarItem> AppBarItems { get; private set; }
+
+ /// <summary>
+ /// Gets the notification items view.
+ /// </summary>
+ public ICollectionView NotificationItemsView { get; private set; }
+
+ /// <summary>
/// Gets the collection of taskbar items.
/// </summary>
public ObservableCollection<TaskBarItem> TaskBarItems { get; private set; }
@@ -58,6 +70,10 @@ namespace Tango.PPC.UI.Notifications
{
NotificationsVisible = true;
NotificationItems = new ObservableCollection<NotificationItem>();
+
+ AppBarItems = new ObservableCollection<AppBarItem>();
+ CollectionViewSource.GetDefaultView(AppBarItems).SortDescriptions.Add(new SortDescription(nameof(AppBarItem.Priority), ListSortDirection.Ascending));
+
TaskBarItems = new ObservableCollection<TaskBarItem>();
_pendingMessageBoxes = new ConcurrentQueue<PendingNotification<MessageBoxVM, bool>>();
_pendingDialogs = new ConcurrentQueue<PendingNotification<DialogAndView, DialogViewVM>>();
@@ -66,6 +82,9 @@ namespace Tango.PPC.UI.Notifications
PopNotificationCommand = new RelayCommand<NotificationItem>((x) => PopNotification(x));
NotificationItems.EnableCrossThreadOperations();
+
+ NotificationItemsView = CollectionViewSource.GetDefaultView(NotificationItems);
+ NotificationItemsView.SortDescriptions.Add(new SortDescription(nameof(NotificationItem.Priority), ListSortDirection.Descending));
}
private MessageBoxVM _currentMessageBox;
@@ -322,29 +341,33 @@ namespace Tango.PPC.UI.Notifications
/// <returns></returns>
public async Task<T> ShowDialog<T>(T datacontext, FrameworkElement view) where T : DialogViewVM
{
- view.DataContext = datacontext;
-
- TangoIOC.Default.Inject(datacontext);
+ TaskCompletionSource<DialogViewVM> source = new TaskCompletionSource<DialogViewVM>();
- view.Loaded += (_, __) =>
+ InvokeUI(() =>
{
view.DataContext = datacontext;
- datacontext.OnShow();
- };
- TaskCompletionSource<DialogViewVM> source = new TaskCompletionSource<DialogViewVM>();
+ TangoIOC.Default.Inject(datacontext);
- datacontext.Accepted += () => { OnDialogClosed(); source.SetResult(datacontext); };
- datacontext.Canceled += () => { OnDialogClosed(); source.SetResult(datacontext); };
+ view.Loaded += (_, __) =>
+ {
+ view.DataContext = datacontext;
+ datacontext.OnShow();
+ };
- if (CurrentDialog == null)
- {
- CurrentDialog = view;
- }
- else
- {
- _pendingDialogs.Enqueue(new PendingNotification<DialogAndView, DialogViewVM>(new DialogAndView(datacontext, view), source));
- }
+ datacontext.Accepted += () => { OnDialogClosed(); source.SetResult(datacontext); };
+ datacontext.Canceled += () => { OnDialogClosed(); source.SetResult(datacontext); };
+
+ if (CurrentDialog == null)
+ {
+ CurrentDialog = view;
+ }
+ else
+ {
+ _pendingDialogs.Enqueue(new PendingNotification<DialogAndView, DialogViewVM>(new DialogAndView(datacontext, view), source));
+ }
+
+ });
var result = await source.Task;
return result as T;
@@ -376,23 +399,31 @@ namespace Tango.PPC.UI.Notifications
/// <returns></returns>
public Task<T> ShowDialog<T>(T datacontext) where T : DialogViewVM
{
- var callingAssembly = datacontext.GetType().Assembly;
- String viewName = datacontext.GetType().FullName.Replace("VM", "");
- var viewType = callingAssembly.GetType(viewName);
+ TaskCompletionSource<T> source = new TaskCompletionSource<T>();
- if (viewType == null)
+ InvokeUI(async () =>
{
- throw new NullReferenceException("View type for " + datacontext.GetType().Name + " could not be found!");
- }
+ var callingAssembly = datacontext.GetType().Assembly;
+ String viewName = datacontext.GetType().FullName.Replace("VM", "");
+ var viewType = callingAssembly.GetType(viewName);
- var view = Activator.CreateInstance(viewType) as FrameworkElement;
+ if (viewType == null)
+ {
+ throw new NullReferenceException("View type for " + datacontext.GetType().Name + " could not be found!");
+ }
- if (view == null)
- {
- throw new NullReferenceException("The view " + viewType.ToString() + " is not of type framework element.");
- }
+ var view = Activator.CreateInstance(viewType) as FrameworkElement;
- return ShowDialog<T>(datacontext, view);
+ if (view == null)
+ {
+ throw new NullReferenceException("The view " + viewType.ToString() + " is not of type framework element.");
+ }
+
+ T result = await ShowDialog<T>(datacontext, view);
+ source.SetResult(result);
+ });
+
+ return source.Task;
}
/// <summary>
@@ -404,7 +435,15 @@ namespace Tango.PPC.UI.Notifications
/// <returns></returns>
public Task<T> ShowDialog<T>() where T : DialogViewVM
{
- return ShowDialog<T>(Activator.CreateInstance<T>());
+ TaskCompletionSource<T> source = new TaskCompletionSource<T>();
+
+ InvokeUI(async () =>
+ {
+ var result = await ShowDialog<T>(Activator.CreateInstance<T>());
+ source.SetResult(result);
+ });
+
+ return source.Task;
}
/// <summary>
@@ -442,22 +481,12 @@ namespace Tango.PPC.UI.Notifications
/// </summary>
public bool IsInGlobalBusyState { get; private set; }
- private AppBarItem _currentAppBarItem;
- /// <summary>
- /// Gets the current application bar item.
- /// </summary>
- public AppBarItem CurrentAppBarItem
- {
- get { return _currentAppBarItem; }
- set { _currentAppBarItem = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(HasAppBarItem)); }
- }
-
/// <summary>
/// Gets a value indicating whether this instance has application bar item.
/// </summary>
- public bool HasAppBarItem
+ public bool HasAppBarItems
{
- get { return CurrentAppBarItem != null; }
+ get { return AppBarItems.Count > 0; }
}
/// <summary>
@@ -468,8 +497,9 @@ namespace Tango.PPC.UI.Notifications
public AppBarItem PushAppBarItem(AppBarItem appBarItem)
{
LogManager.Log($"Pushing AppBarItem '{appBarItem.GetType().Name}'.");
- CurrentAppBarItem = appBarItem;
+ AppBarItems.Add(appBarItem);
appBarItem.RemoveAction = () => PopAppBarItem(appBarItem);
+ RaisePropertyChanged(nameof(HasAppBarItems));
return appBarItem;
}
@@ -478,9 +508,9 @@ namespace Tango.PPC.UI.Notifications
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
- public AppBarItem PushAppBarItem<T>() where T : AppBarItem
+ public T PushAppBarItem<T>() where T : AppBarItem
{
- return PushAppBarItem(Activator.CreateInstance<T>());
+ return PushAppBarItem(Activator.CreateInstance<T>()) as T;
}
/// <summary>
@@ -489,8 +519,12 @@ namespace Tango.PPC.UI.Notifications
/// <param name="appBarItem">The application bar item.</param>
public void PopAppBarItem(AppBarItem appBarItem)
{
- LogManager.Log($"Popping out AppBarItem '{appBarItem.GetType().Name}'.");
- CurrentAppBarItem = null;
+ InvokeUI(() =>
+ {
+ LogManager.Log($"Popping out AppBarItem '{appBarItem.GetType().Name}'.");
+ AppBarItems.Remove(appBarItem);
+ RaisePropertyChanged(nameof(HasAppBarItems));
+ });
}
/// <summary>
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs
new file mode 100644
index 000000000..9e336f276
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.PPC.Common.Notifications;
+
+namespace Tango.PPC.UI.Notifications.NotificationItems
+{
+ /// <summary>
+ /// Represents a simple text message notification item which can be inserted into the application notifications panel.
+ /// </summary>
+ /// <seealso cref="Tango.PPC.Common.Notifications.NotificationItem" />
+ public class UpdateAvailableNotificationItem : NotificationItem
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="UpdateAvailableNotificationItem"/> class.
+ /// </summary>
+ public UpdateAvailableNotificationItem()
+ {
+ CanClose = true;
+ }
+
+ private String _version;
+ /// <summary>
+ /// Gets or sets the message.
+ /// </summary>
+ public String Version
+ {
+ get { return _version; }
+ set { _version = value; RaisePropertyChangedAuto(); }
+ }
+
+ private bool _isDatabaseUpdate;
+ /// <summary>
+ /// Gets or sets a value indicating whether this instance is database update.
+ /// </summary>
+ public bool IsDatabaseUpdate
+ {
+ get { return _isDatabaseUpdate; }
+ set { _isDatabaseUpdate = value; RaisePropertyChangedAuto(); }
+ }
+
+ /// <summary>
+ /// Gets or sets the view type.
+ /// </summary>
+ public override Type ViewType
+ {
+ get { return typeof(UpdateAvailableNotificationItemView); }
+ }
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml
new file mode 100644
index 000000000..1d4dd6fc7
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml
@@ -0,0 +1,30 @@
+<UserControl x:Class="Tango.PPC.UI.Notifications.NotificationItems.UpdateAvailableNotificationItemView"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch"
+ xmlns:local="clr-namespace:Tango.PPC.UI.Notifications.NotificationItems"
+ xmlns:common="clr-namespace:Tango.PPC.Common.Converters"
+ mc:Ignorable="d"
+ x:Name="MessageNotificationItemControl"
+ d:DesignHeight="60" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=local:UpdateAvailableNotificationItem, IsDesignTimeCreatable=False}" MinHeight="90" Height="90" MaxHeight="150" Background="{StaticResource TangoPrimaryBackgroundBrush}">
+
+ <Grid>
+ <Border BorderThickness="0 0 0 2" BorderBrush="{StaticResource TangoPrimaryAccentBrush}" Padding="15">
+ <DockPanel>
+ <Image Source="/Images/update_available.png" MaxHeight="50" />
+
+ <Grid>
+ <TextBlock Margin="20 0 0 0" VerticalAlignment="Center" Visibility="{Binding IsDatabaseUpdate,Converter={StaticResource BooleanToVisibilityInverseConverter}}">
+ <Run>Version</Run>
+ <Run Foreground="{StaticResource TangoPrimaryAccentBrush}" FontWeight="SemiBold" Text="{Binding Version,FallbackValue='1.0.0.0',TargetNullValue='1.0.0.0'}"></Run>
+ <Run>is available!</Run>
+ <Run>Tap to start updating your system.</Run>
+ </TextBlock>
+ <TextBlock Margin="20 0 0 0" VerticalAlignment="Center" Text="Database updates are available. Tap to start updating your system." Visibility="{Binding IsDatabaseUpdate,Converter={StaticResource BooleanToVisibilityConverter}}"></TextBlock>
+ </Grid>
+ </DockPanel>
+ </Border>
+ </Grid>
+</UserControl>
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml.cs
new file mode 100644
index 000000000..791d40540
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace Tango.PPC.UI.Notifications.NotificationItems
+{
+ /// <summary>
+ /// Represents the <see cref="UpdateAvailableNotificationItemView"/> view.
+ /// </summary>
+ /// <seealso cref="System.Windows.Controls.UserControl" />
+ /// <seealso cref="System.Windows.Markup.IComponentConnector" />
+ public partial class UpdateAvailableNotificationItemView : UserControl
+ {
+ public UpdateAvailableNotificationItemView()
+ {
+ InitializeComponent();
+ }
+ }
+}