From 7658a8546a9c33a76376dff3ab646f2aceaf0a01 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 17 Jun 2018 19:06:13 +0300 Subject: Working on PPC !!! --- .../Tango.PPC.Jobs/ViewModels/JobsViewVM.cs | 16 +- .../Notifications/INotificationProvider.cs | 42 ++++ .../Notifications/NotificationItem.cs | 69 ++++++ .../Tango.PPC.Common/Properties/AssemblyInfo.cs | 3 + .../PPC/Tango.PPC.Common/Tango.PPC.Common.csproj | 1 + .../Converters/NotificationItemConverter.cs | 41 ++++ .../PPC/Tango.PPC.UI/Images/warning-test.png | Bin 0 -> 2121 bytes .../Notifications/DefaultNotificationProvider.cs | 101 +++++++++ .../EmptyCartridgesNotification.cs | 34 +++ .../EmptyCartridgesNotificationView.xaml | 15 ++ .../EmptyCartridgesNotificationView.xaml.cs | 28 +++ .../PPC/Tango.PPC.UI/Tango.PPC.UI.csproj | 10 + .../PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs | 36 +++- .../PPC/Tango.PPC.UI/Views/LayoutView.xaml | 36 +++- .../PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs | 3 + .../ObservableCollectionExtensions.cs | 12 ++ .../Tango.DragAndDrop/DragAndDropService.cs | 8 +- .../Tango.Touch/Controls/LightTouchDataGrid.cs | 11 +- .../Tango.Touch/Controls/TouchNotificationBar.cs | 238 +++++++++++++++++++++ .../Tango.Touch/Controls/TouchNotificationBar.xaml | 53 +++++ .../Visual_Studio/Tango.Touch/Tango.Touch.csproj | 5 + .../Visual_Studio/Tango.Touch/Themes/Generic.xaml | 1 + 22 files changed, 740 insertions(+), 23 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItem.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Converters/NotificationItemConverter.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Images/warning-test.png create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotification.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml.cs create mode 100644 Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs create mode 100644 Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.xaml (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs index f03c7070a..dde587b84 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs @@ -203,12 +203,16 @@ namespace Tango.PPC.Jobs.ViewModels _jobsContext = ObservablesContext.CreateDefault(); - Jobs = _jobsContext.Jobs.Where(x => x.Machine.SerialNumber == Settings.MachineSerialNumber).ToObservableCollection(); - JobsCollectionView = CollectionViewSource.GetDefaultView(Jobs); - JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); - FilterJobCategory(FilterCategory); + var jobs = _jobsContext.Jobs.Where(x => x.Machine.Guid == ApplicationManager.Machine.Guid).ToObservableCollection(); - IsLoadingJobs = false; + InvokeUI(() => + { + Jobs = _jobsContext.Jobs.Where(x => x.Machine.Guid == ApplicationManager.Machine.Guid).ToObservableCollection(); + JobsCollectionView = CollectionViewSource.GetDefaultView(Jobs); + JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); + FilterJobCategory(FilterCategory); + IsLoadingJobs = false; + }); }); } @@ -227,7 +231,7 @@ namespace Tango.PPC.Jobs.ViewModels /// The job category. public void FilterJobCategory(JobCategories jobCategory) { - JobsCollectionView.Filter = (job) => + JobsCollectionView.Filter = (job) => { return (job as Job).JobCategories.Contains(jobCategory); }; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs index 9fc42c155..303392a68 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; +using Tango.Core.Commands; namespace Tango.PPC.Common.Notifications { @@ -14,6 +15,16 @@ namespace Tango.PPC.Common.Notifications /// public interface INotificationProvider { + /// + /// Gets the collection of notification items. + /// + ObservableCollection NotificationItems { get; } + + /// + /// Gets a value indicating whether this instance has notification items. + /// + bool HasNotificationItems { get; } + /// /// Gets the current message box. /// @@ -47,5 +58,36 @@ namespace Tango.PPC.Common.Notifications /// /// The message. Task ShowQuestion(String message); + + /// + /// Inserts the notification item to the bottom of the notifications collection. + /// + /// The item. + NotificationItem PushNotification(NotificationItem item); + + /// + /// Inserts the notification item to the bottom of the notifications collection. + /// + /// The item. + /// A condition which determines if this item is still relevant. + /// Determines whether to perform automatic checking of the condition. + /// Determines how frequently the condition function will be invoked. (Default 1 second) + NotificationItem PushNotification(NotificationItem item, Func condition, bool autoCheck = true, TimeSpan? checkInterval = null); + + /// + /// Removed the specified notification item. + /// + /// The item. + void PopNotification(NotificationItem item); + + /// + /// Invokes the notification items conditions. + /// + void InvokeNotificationItemsConditions(); + + /// + /// Gets the pop notification command. + /// + RelayCommand PopNotificationCommand { get; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItem.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItem.cs new file mode 100644 index 000000000..f5e319fa0 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItem.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Timers; +using System.Windows.Media; +using Tango.Core; + +namespace Tango.PPC.Common.Notifications +{ + /// + /// Represents a base notification item. + /// + /// + public abstract class NotificationItem : ExtendedObject, IDisposable + { + /// + /// Gets or sets the condition. + /// + internal Func Condition { get; set; } + + /// + /// Gets or sets a value indicating whether [automatic check]. + /// + internal bool AutoCheck { get; set; } + + /// + /// Gets or sets the automatic check interval. + /// + internal TimeSpan AutoCheckInterval { get; set; } + + /// + /// Gets or sets the remove action. + /// + internal Action RemoveAction { get; set; } + + /// + /// Gets or sets the check timer. + /// + internal Timer Timer { get; set; } + + private String _message; + /// + /// Gets or sets the notification message. + /// + public String Message + { + get { return _message; } + set { _message = value; RaisePropertyChangedAuto(); } + } + + /// + /// Gets or sets the type of the view associated with this notification item. + /// + public abstract Type ViewType { get; } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + if (RemoveAction != null) + { + RemoveAction(); + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Properties/AssemblyInfo.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Properties/AssemblyInfo.cs index 636916a53..47bb0427f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Properties/AssemblyInfo.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Properties/AssemblyInfo.cs @@ -17,3 +17,6 @@ using System.Windows; //(used if a resource is not found in the page, // app, or any theme specific resource dictionaries) )] + +//Friends With +[assembly: InternalsVisibleTo("Tango.PPC.UI")] diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index c64e56b44..9b530be9c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -95,6 +95,7 @@ + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Converters/NotificationItemConverter.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Converters/NotificationItemConverter.cs new file mode 100644 index 000000000..4e3291b97 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Converters/NotificationItemConverter.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; +using Tango.PPC.Common.Notifications; + +namespace Tango.PPC.UI.Converters +{ + public class NotificationItemConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + NotificationItem item = value as NotificationItem; + + if (item != null) + { + var view = Activator.CreateInstance(item.ViewType) as FrameworkElement; + + if (view == null) + { + throw new InvalidOperationException("The type " + item.ViewType + " is not a framework element."); + } + + view.DataContext = item; + return view; + } + + return null; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/warning-test.png b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/warning-test.png new file mode 100644 index 000000000..a845b1226 Binary files /dev/null and b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/warning-test.png differ 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 5e4bd7c30..cbdbab848 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs @@ -11,6 +11,8 @@ using Tango.Core; using System.Collections.Concurrent; using System.Windows.Media.Imaging; using Tango.SharedUI.Helpers; +using System.Timers; +using Tango.Core.Commands; namespace Tango.PPC.UI.Notifications { @@ -21,6 +23,11 @@ namespace Tango.PPC.UI.Notifications /// public class DefaultNotificationProvider : ExtendedObject, INotificationProvider { + /// + /// Gets the collection of notification items. + /// + public ObservableCollection NotificationItems { get; private set; } + /// /// Represents a pending message box. /// @@ -44,7 +51,10 @@ namespace Tango.PPC.UI.Notifications /// public DefaultNotificationProvider() { + NotificationItems = new ObservableCollection(); _pendingMessageBoxes = new ConcurrentQueue(); + + PopNotificationCommand = new RelayCommand((x) => PopNotification(x)); } private MessageBoxVM _currentMessageBox; @@ -182,5 +192,96 @@ namespace Tango.PPC.UI.Notifications } } } + + /// + /// Inserts the notification item to the bottom of the notifications collection. + /// + /// The item. + /// + public NotificationItem PushNotification(NotificationItem item) + { + return PushNotification(item, null, false, null); + } + + /// + /// Inserts the notification item to the bottom of the notifications collection. + /// + /// The item. + /// A condition which determines if this item is still relevant. + /// Determines whether to perform automatic checking of the condition. + /// Determines how frequently the condition function will be invoked. (Default 1 second) + /// + public NotificationItem PushNotification(NotificationItem item, Func condition, bool autoCheck = true, TimeSpan? checkInterval = default(TimeSpan?)) + { + item.Condition = condition; + item.AutoCheck = autoCheck; + item.AutoCheckInterval = checkInterval != null ? checkInterval.Value : TimeSpan.FromSeconds(1); + item.RemoveAction = () => { PopNotification(item); }; + NotificationItems.Insert(0, item); + + if (autoCheck && condition != null) + { + Timer timer = new Timer(); + item.Timer = timer; + timer.Interval = item.AutoCheckInterval.TotalMilliseconds; + timer.Elapsed += (x, y) => + { + if (!item.Condition()) + { + PopNotification(item); + } + }; + timer.Start(); + } + + RaisePropertyChanged(nameof(HasNotificationItems)); + + return item; + } + + /// + /// Removed the specified notification item. + /// + /// The item. + public void PopNotification(NotificationItem item) + { + if (item.Timer != null) + { + item.Timer.Stop(); + } + + NotificationItems.Remove(item); + + RaisePropertyChanged(nameof(HasNotificationItems)); + } + + /// + /// Invokes the notification items conditions. + /// + public void InvokeNotificationItemsConditions() + { + var list = NotificationItems.ToList(); + + foreach (var item in list.Where(x => x.Condition != null)) + { + if (!item.Condition()) + { + PopNotification(item); + } + } + } + + /// + /// Gets a value indicating whether this instance has notification items. + /// + public bool HasNotificationItems + { + get + { + return NotificationItems.Count > 0; + } + } + + public RelayCommand PopNotificationCommand { get; private set; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotification.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotification.cs new file mode 100644 index 000000000..49a0c03eb --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotification.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.BL.Enumerations; +using Tango.PPC.Common.Notifications; + +namespace Tango.PPC.UI.Notifications.NotificationItems +{ + public class EmptyCartridgesNotification : NotificationItem + { + public List LiquidTypes { get; set; } + + public EmptyCartridgesNotification() + { + Message = "Cartridges are empty, please replace cartridges"; + } + + public EmptyCartridgesNotification(IEnumerable liquidTypes) : this() + { + LiquidTypes = liquidTypes.ToList(); + } + + public override Type ViewType + { + get + { + return typeof(EmptyCartridgesNotificationView); + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml new file mode 100644 index 000000000..7ce525337 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml.cs new file mode 100644 index 000000000..5fab4ab44 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml.cs @@ -0,0 +1,28 @@ +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 +{ + /// + /// Interaction logic for EmptyCartridgesNotification.xaml + /// + public partial class EmptyCartridgesNotificationView : UserControl + { + public EmptyCartridgesNotificationView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index fdeff4fc4..c74e76b50 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -93,12 +93,17 @@ PPCVersionInfo.cs + MessageBox.xaml + + + EmptyCartridgesNotificationView.xaml + @@ -130,6 +135,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -169,6 +178,7 @@ Settings.settings True + ResXFileCodeGenerator Resources.Designer.cs diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs index 99841516e..d65dfc11c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -8,6 +8,7 @@ using Tango.Core.DI; using Tango.PPC.Common; using Tango.PPC.Common.Modules; using Tango.PPC.Common.Navigation; +using Tango.PPC.UI.Notifications.NotificationItems; using Tango.PPC.UI.ViewsContracts; using Tango.SharedUI; @@ -35,6 +36,16 @@ namespace Tango.PPC.UI.ViewModels set { _isMenuOpened = value; RaisePropertyChangedAuto(); } } + private bool _isNotificationsOpened; + /// + /// Gets or sets a value indicating whether to display all notifications. + /// + public bool IsNotificationsOpened + { + get { return _isNotificationsOpened; } + set { _isNotificationsOpened = value; RaisePropertyChangedAuto(); } + } + /// /// Gets or sets the module navigation command. /// @@ -50,6 +61,11 @@ namespace Tango.PPC.UI.ViewModels /// public RelayCommand HomeCommand { get; set; } + /// + /// Gets or sets the notifications area pressed command. + /// + public RelayCommand NotificationsAreaPressedCommand { get; set; } + /// /// Initializes a new instance of the class. /// @@ -58,6 +74,7 @@ namespace Tango.PPC.UI.ViewModels ModuleNavigationCommand = new RelayCommand(NavigateToModule); HomeCommand = new RelayCommand(NavigateHome); MenuOrBackCommand = new RelayCommand(OpenMenuOrNavigateBack); + NotificationsAreaPressedCommand = new RelayCommand(OpenFirstNotificationOrDisplayAll); } /// @@ -73,6 +90,8 @@ namespace Tango.PPC.UI.ViewModels { IsMenuOpened = true; } + + NotificationProvider.PushNotification(new EmptyCartridgesNotification()); } /// @@ -118,7 +137,22 @@ namespace Tango.PPC.UI.ViewModels /// public override void OnViewAttached() { - + + } + + /// + /// Opens the first notification or display all. + /// + private void OpenFirstNotificationOrDisplayAll() + { + if (NotificationProvider.NotificationItems.Count == 1) + { + //Open first + } + else + { + IsNotificationsOpened = true; + } } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml index 2b4c68060..524550b94 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml @@ -8,14 +8,28 @@ xmlns:fa="http://schemas.fontawesome.io/icons/" xmlns:vm="clr-namespace:Tango.PPC.UI.ViewModels" xmlns:global="clr-namespace:Tango.PPC.UI" + xmlns:localConverters="clr-namespace:Tango.PPC.UI.Converters" xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:keyboard="clr-namespace:Tango.Touch.Keyboard;assembly=Tango.Touch" mc:Ignorable="d" d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:LayoutViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.LayoutViewVM}"> - - + + + + + + + + + + + + + + + @@ -59,7 +73,7 @@ - + @@ -98,11 +112,13 @@ - - - DYE - - + + + + DYE + + + @@ -111,12 +127,12 @@ - + - + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs index 18ffa8ab2..9ef698656 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,9 +10,11 @@ using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; +using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Tango.Core.EventArguments; using Tango.Logging; using Tango.PPC.Common; using Tango.PPC.UI.ViewsContracts; diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObservableCollectionExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObservableCollectionExtensions.cs index 948be3c4a..db3ced188 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObservableCollectionExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObservableCollectionExtensions.cs @@ -4,12 +4,14 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Data; /// /// Contains extension methods. /// public static class ObservableCollectionExtensions { + private static object _syncLock = new object(); /// /// Replaces the specified old element with the specified new element. @@ -54,5 +56,15 @@ public static class ObservableCollectionExtensions collection.Remove(dragged); collection.Insert(collection.IndexOf(dropped), dragged); } + + /// + /// Enables cross thread operations on this collection. + /// + /// + /// The collection. + public static void EnableCrossThreadOperations(this ObservableCollection collection) + { + BindingOperations.EnableCollectionSynchronization(collection, _syncLock); + } } diff --git a/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs b/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs index 4473e2879..1ba7907f9 100644 --- a/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs +++ b/Software/Visual_Studio/Tango.DragAndDrop/DragAndDropService.cs @@ -782,8 +782,8 @@ namespace Tango.DragAndDrop /// The instance containing the event data. private static void Element_Unloaded(object sender, RoutedEventArgs e) { - FrameworkElement element = sender as FrameworkElement; - UnRegisterDraggable(element); + //FrameworkElement element = sender as FrameworkElement; + //UnRegisterDraggable(element); } #endregion @@ -797,8 +797,8 @@ namespace Tango.DragAndDrop /// The instance containing the event data. private static void Element_Unloaded1(object sender, RoutedEventArgs e) { - FrameworkElement element = sender as FrameworkElement; - UnRegisterDroppable(element); + //FrameworkElement element = sender as FrameworkElement; + //UnRegisterDroppable(element); } #endregion diff --git a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs index 8d3d2e9f7..11467980a 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs @@ -219,6 +219,8 @@ namespace Tango.Touch.Controls /// The instance containing the event data. private void OnRowMouseTouchUp(object sender, MouseOrTouchEventArgs e) { + if (e.OriginalSource.GetType() == typeof(DragThumb)) return; + var row = (e.Source is LightTouchDataGridRow) ? e.Source as LightTouchDataGridRow : (e.Source as DependencyObject).FindAncestor(); var otherRows = GetRows().Where(x => x != row).ToList(); @@ -266,6 +268,8 @@ namespace Tango.Touch.Controls /// private async void OnRowMouseTouchDown(object sender, MouseOrTouchEventArgs e) { + if (e.OriginalSource.GetType() == typeof(DragThumb)) return; + var row = (e.Source is LightTouchDataGridRow) ? e.Source as LightTouchDataGridRow : (e.Source as DependencyObject).FindAncestor(); var otherRows = GetRows().Where(x => x != row).ToList(); @@ -363,8 +367,11 @@ namespace Tango.Touch.Controls private void LightTouchDataGrid_Loaded(object sender, RoutedEventArgs e) { - _isLoaded = true; - LayoutRows(); + if (!_isLoaded) + { + _isLoaded = true; + LayoutRows(); + } } private void ItemContainerGenerator_StatusChanged(object sender, EventArgs e) diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs new file mode 100644 index 000000000..d544af8c9 --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs @@ -0,0 +1,238 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +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.Animation; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.Core.EventArguments; + +namespace Tango.Touch.Controls +{ + public class TouchNotificationBar : ContentControl + { + private bool _isMouseDown; + private Point _mouseDownLocation; + private bool _isMoving; + private Point _downLocation; + private TouchDevice _touchDevice; + + private Border border_notifications; + private Grid grid_container; + + static TouchNotificationBar() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchNotificationBar), new FrameworkPropertyMetadata(typeof(TouchNotificationBar))); + } + + public double MinNotificationHeight + { + get { return (double)GetValue(MinNotificationHeightProperty); } + set { SetValue(MinNotificationHeightProperty, value); } + } + public static readonly DependencyProperty MinNotificationHeightProperty = + DependencyProperty.Register("MinNotificationHeight", typeof(double), typeof(TouchNotificationBar), new PropertyMetadata(60.0)); + + public double MaxNotificationHeight + { + get { return (double)GetValue(MaxNotificationHeightProperty); } + set { SetValue(MaxNotificationHeightProperty, value); } + } + public static readonly DependencyProperty MaxNotificationHeightProperty = + DependencyProperty.Register("MaxNotificationHeight", typeof(double), typeof(TouchNotificationBar), new PropertyMetadata(100.0)); + + public Thickness NotificationPadding + { + get { return (Thickness)GetValue(NotificationPaddingProperty); } + set { SetValue(NotificationPaddingProperty, value); } + } + public static readonly DependencyProperty NotificationPaddingProperty = + DependencyProperty.Register("NotificationPadding", typeof(Thickness), typeof(TouchNotificationBar), new PropertyMetadata(new Thickness(0))); + + public bool HasNotifications + { + get { return (bool)GetValue(HasNotificationsProperty); } + set { SetValue(HasNotificationsProperty, value); } + } + public static readonly DependencyProperty HasNotificationsProperty = + DependencyProperty.Register("HasNotifications", typeof(bool), typeof(TouchNotificationBar), new PropertyMetadata(false,(d,e) => (d as TouchNotificationBar).OnHasNotificationsChanged())); + + public IList Notifications + { + get { return (IList)GetValue(NotificationsProperty); } + set { SetValue(NotificationsProperty, value); } + } + public static readonly DependencyProperty NotificationsProperty = + DependencyProperty.Register("Notifications", typeof(IList), typeof(TouchNotificationBar), new PropertyMetadata(null)); + + public DataTemplate NotificationTemplate + { + get { return (DataTemplate)GetValue(NotificationTemplateProperty); } + set { SetValue(NotificationTemplateProperty, value); } + } + public static readonly DependencyProperty NotificationTemplateProperty = + DependencyProperty.Register("NotificationTemplate", typeof(DataTemplate), typeof(TouchNotificationBar), new PropertyMetadata(null)); + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + border_notifications = GetTemplateChild("PART_BorderNotifications") as Border; + grid_container = GetTemplateChild("PART_Grid_Container") as Grid; + + border_notifications.RegisterForPreviewMouseOrTouchDown(GridNotificationMouseDown); + border_notifications.RegisterForMouseOrTouchMove(GridNotificationMouseMove); + border_notifications.RegisterForPreviewMouseOrTouchUp(GridNotificationMouseUp); + + border_notifications.SizeChanged += Border_notifications_SizeChanged; + } + + private void Border_notifications_SizeChanged(object sender, SizeChangedEventArgs e) + { + double maxPadding = 20; + NotificationPadding = new Thickness((border_notifications.ActualHeight / ActualHeight) * maxPadding); + } + + private void OnHasNotificationsChanged() + { + DoubleAnimation ani = new DoubleAnimation(); + ani.Duration = TimeSpan.FromSeconds(0.2); + + if (HasNotifications) + { + ani.To = MinNotificationHeight; + } + else + { + ani.To = 0; + CloseNotifications(); + } + + grid_container.BeginAnimation(Grid.MinHeightProperty, ani); + } + + private void OpenNotifications() + { + DoubleAnimation ani = new DoubleAnimation(); + ani.Duration = TimeSpan.FromSeconds(0.2); + + if (double.IsNaN(border_notifications.Height)) + { + border_notifications.Height = border_notifications.ActualHeight; + } + + border_notifications.MaxHeight = this.ActualHeight; + ani.To = this.ActualHeight; + border_notifications.BeginAnimation(Grid.HeightProperty, ani); + } + + private void CloseNotifications() + { + DoubleAnimation ani = new DoubleAnimation(); + ani.Duration = TimeSpan.FromSeconds(0.2); + + ani.From = border_notifications.ActualHeight; + ani.To = MinNotificationHeight; + + ani.Completed += (_, __) => + { + border_notifications.BorderThickness = new Thickness(0); + border_notifications.BeginAnimation(Border.HeightProperty, null); + border_notifications.Height = double.NaN; + }; + + border_notifications.BeginAnimation(Border.MaxHeightProperty, ani); + border_notifications.BeginAnimation(Border.HeightProperty, ani); + + ThicknessAnimation tAni = new ThicknessAnimation(); + tAni.Duration = TimeSpan.FromSeconds(0.3); + tAni.To = new Thickness(0); + border_notifications.BeginAnimation(Border.BorderThicknessProperty, tAni); + } + + private void GridNotificationMouseUp(object sender, MouseOrTouchEventArgs e) + { + _isMouseDown = false; + + if (_isMoving) + { + if (_touchDevice != null) + { + border_notifications.ReleaseTouchCapture(_touchDevice); + _touchDevice = null; + } + else + { + border_notifications.ReleaseMouseCapture(); + } + + e.Handled = true; + _isMoving = false; + DoubleAnimation ani = new DoubleAnimation(); + ani.Duration = TimeSpan.FromSeconds(0.2); + + if (e.GetPosition(this).Y > ActualHeight / 2) + { + OpenNotifications(); + } + else + { + CloseNotifications(); + } + } + } + + private void GridNotificationMouseMove(object sender, MouseOrTouchEventArgs e) + { + if (_isMouseDown) + { + if (Math.Abs(e.Location.Y - _downLocation.Y) > 5) + { + _isMoving = true; + } + + if (_isMoving) + { + if (e.TouchDevice != null) + { + border_notifications.CaptureTouch(e.TouchDevice); + } + else + { + Mouse.Capture(border_notifications); + } + border_notifications.Height = Math.Max(e.Location.Y + _mouseDownLocation.Y, MinNotificationHeight); + border_notifications.MaxHeight = Math.Max(e.Location.Y + _mouseDownLocation.Y, MinNotificationHeight); + border_notifications.BeginAnimation(Border.HeightProperty, null); + border_notifications.BeginAnimation(Border.MaxHeightProperty, null); + + border_notifications.BeginAnimation(Border.BorderThicknessProperty, null); + if (border_notifications.ActualHeight > MinNotificationHeight) + { + border_notifications.BorderThickness = new Thickness(0, 0, 0, 20); + } + else + { + border_notifications.BorderThickness = new Thickness(0); + } + } + } + } + + private void GridNotificationMouseDown(object sender, MouseOrTouchEventArgs e) + { + _mouseDownLocation = new Point(e.Location.X, border_notifications.MaxHeight - e.Location.Y); + _downLocation = e.Location; + _isMouseDown = true; + } + } +} diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.xaml b/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.xaml new file mode 100644 index 000000000..40b0a2779 --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.xaml @@ -0,0 +1,53 @@ + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj b/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj index be6c5add3..c950696d5 100644 --- a/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj +++ b/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj @@ -68,6 +68,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -158,6 +162,7 @@ + diff --git a/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml b/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml index 26faaa754..b18184c9a 100644 --- a/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml +++ b/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml @@ -22,6 +22,7 @@ + -- cgit v1.3.1