From 60e43e4193cfb9b5ed9330d0ea2c46a498a03032 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Fri, 19 Jun 2020 19:02:05 -0500 Subject: [PATCH] Implement Cue Properties Updating --- QSharp/Events/QEventArgs.cs | 5 ++ QSharp/Events/QEventHandlers.cs | 4 +- QSharp/QBrowser.cs | 1 - QSharp/QClient.cs | 5 +- QSharp/QColor.cs | 8 +-- QSharp/QCue.cs | 20 ++++++- QSharp/QDefines.cs | 6 +- QSharp/QMessage.cs | 4 -- .../QSharpXamDemo/CueListPage.xaml.cs | 5 +- .../QSharpXamDemo/ViewModels/QCueViewModel.cs | 22 ++++++- .../ViewModels/SelectedQCueViewModel.cs | 59 ------------------- 11 files changed, 49 insertions(+), 90 deletions(-) delete mode 100644 QSharpXamDemo/QSharpXamDemo/ViewModels/SelectedQCueViewModel.cs diff --git a/QSharp/Events/QEventArgs.cs b/QSharp/Events/QEventArgs.cs index 1b5dadf..6b90aae 100644 --- a/QSharp/Events/QEventArgs.cs +++ b/QSharp/Events/QEventArgs.cs @@ -61,6 +61,11 @@ namespace QSharp public JToken data { get; set; } } + public class QCuePropertiesUpdatedArgs : EventArgs + { + public List properties { get; set; } + } + public class QCueListsUpdatedArgs : EventArgs { public JToken data { get; set; } diff --git a/QSharp/Events/QEventHandlers.cs b/QSharp/Events/QEventHandlers.cs index dd32b53..bf1c0c2 100644 --- a/QSharp/Events/QEventHandlers.cs +++ b/QSharp/Events/QEventHandlers.cs @@ -1,5 +1,4 @@ - -namespace QSharp +namespace QSharp { public delegate void QServerFoundHandler(object source, QServerFoundArgs args); public delegate void QServerUpdatedHandler(object source, QServerUpdatedArgs args); @@ -16,6 +15,7 @@ namespace QSharp public delegate void QCueUpdatedHandler(object source, QCueUpdatedArgs args); + public delegate void QCuePropertiesUpdatedHandler(object source, QCuePropertiesUpdatedArgs args); public delegate void QCueListsUpdatesHandler(object source, QCueListsUpdatedArgs args); public delegate void QCueNeedsUpdatedHandler(object source, QCueNeedsUpdatedArgs args); public delegate void QCueListChangedPlaybackPositionHandler(object source, QCueListChangedPlaybackPositionArgs args); diff --git a/QSharp/QBrowser.cs b/QSharp/QBrowser.cs index 51405bf..fdf6267 100644 --- a/QSharp/QBrowser.cs +++ b/QSharp/QBrowser.cs @@ -1,5 +1,4 @@ using Zeroconf; -using System; using System.Collections.ObjectModel; using Serilog; diff --git a/QSharp/QClient.cs b/QSharp/QClient.cs index dbeed63..554a8aa 100644 --- a/QSharp/QClient.cs +++ b/QSharp/QClient.cs @@ -1,12 +1,9 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using SharpOSC; using Serilog; -using System.Collections.Concurrent; -using System.ComponentModel; namespace QSharp { diff --git a/QSharp/QColor.cs b/QSharp/QColor.cs index c8dcf58..b8c2806 100644 --- a/QSharp/QColor.cs +++ b/QSharp/QColor.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Security.Cryptography.X509Certificates; -using System.Text; - -namespace QSharp +namespace QSharp { public class QColor { diff --git a/QSharp/QCue.cs b/QSharp/QCue.cs index 9cec61a..1100ff1 100644 --- a/QSharp/QCue.cs +++ b/QSharp/QCue.cs @@ -22,6 +22,8 @@ namespace QSharp public bool ignoreUpdates; + public event QCuePropertiesUpdatedHandler CuePropertiesUpdated; + public QCue() { init(); @@ -540,6 +542,7 @@ namespace QSharp //TODO JObject dictObj = (JObject)dict; + List propertiesUpdated = new List(); foreach (var obj in dictObj) { JToken value = obj.Value; @@ -553,16 +556,17 @@ namespace QSharp { bool didSetProptery = setProperty(value, obj.Key, false); if (didSetProptery) + { cueUpdated = true; + propertiesUpdated.Add(obj.Key); + } } } if (!cueUpdated) return false; - Log.Debug($"[cue] <{nonEmptyName}> has been updated."); - //something about notifying cueUpdated ? OnCueUpdated event handler maybe? - + OnCuePropertiesUpdated(propertiesUpdated); return true; } @@ -820,6 +824,16 @@ namespace QSharp #endregion + + #region Event Handling + void OnCuePropertiesUpdated(List properties) + { + Log.Debug($"[cue] <{nonEmptyName}> properties have been updated."); + CuePropertiesUpdated?.Invoke(this, new QCuePropertiesUpdatedArgs { properties = properties }); + } + #endregion + + #region Printing public void Print() { diff --git a/QSharp/QDefines.cs b/QSharp/QDefines.cs index b432a62..07656f9 100644 --- a/QSharp/QDefines.cs +++ b/QSharp/QDefines.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace QSharp +namespace QSharp { static class QBonjour { diff --git a/QSharp/QMessage.cs b/QSharp/QMessage.cs index d8afa64..368953c 100644 --- a/QSharp/QMessage.cs +++ b/QSharp/QMessage.cs @@ -1,9 +1,5 @@ using System; using System.Collections.Generic; -using System.Dynamic; -using System.Linq; -using System.Reflection; -using System.Text.RegularExpressions; using Newtonsoft.Json.Linq; using SharpOSC; diff --git a/QSharpXamDemo/QSharpXamDemo/CueListPage.xaml.cs b/QSharpXamDemo/QSharpXamDemo/CueListPage.xaml.cs index f98b70d..dcf0624 100644 --- a/QSharpXamDemo/QSharpXamDemo/CueListPage.xaml.cs +++ b/QSharpXamDemo/QSharpXamDemo/CueListPage.xaml.cs @@ -1,6 +1,5 @@  using System.Collections.Generic; -using System.Security; using System.Threading.Tasks; using QSharp; using QSharpXamDemo.ViewModels; @@ -29,7 +28,7 @@ namespace QSharpXamDemo { Device.BeginInvokeOnMainThread(() => { - selectedCueGrid.BindingContext = new SelectedQCueViewModel(connectedWorkspace.cueWithID(args.cueID)); + selectedCueGrid.BindingContext = new QCueViewModel(connectedWorkspace.cueWithID(args.cueID), false); if (cueGridDict.ContainsKey(args.cueID)) { @@ -65,7 +64,7 @@ namespace QSharpXamDemo Grid cueToGrid(QCue cue) { Grid cueGrid = new Grid { RowSpacing = 0 }; - QCueViewModel qCueViewModel = new QCueViewModel(cue); + QCueViewModel qCueViewModel = new QCueViewModel(cue, true); cueGrid.RowDefinitions = new RowDefinitionCollection(); cueGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) }); var cueLabel = new Label diff --git a/QSharpXamDemo/QSharpXamDemo/ViewModels/QCueViewModel.cs b/QSharpXamDemo/QSharpXamDemo/ViewModels/QCueViewModel.cs index a8a6ea8..6efc47c 100644 --- a/QSharpXamDemo/QSharpXamDemo/ViewModels/QCueViewModel.cs +++ b/QSharpXamDemo/QSharpXamDemo/ViewModels/QCueViewModel.cs @@ -1,4 +1,5 @@ using QSharp; +using Serilog; using System.ComponentModel; using System.Runtime.CompilerServices; using Xamarin.Forms; @@ -10,10 +11,27 @@ namespace QSharpXamDemo.ViewModels bool isSelected = false; public event PropertyChangedEventHandler PropertyChanged; - public QCueViewModel(QCue cue) + public QCueViewModel(QCue cue, bool checkPlayback) { this.cue = cue; - this.cue.workspace.CueListChangedPlaybackPosition += Workspace_CueListChangedPlaybackPosition; + if(checkPlayback) + this.cue.workspace.CueListChangedPlaybackPosition += Workspace_CueListChangedPlaybackPosition; + this.cue.CuePropertiesUpdated += OnCuePropertiesUpdated; + } + + private void OnCuePropertiesUpdated(object source, QCuePropertiesUpdatedArgs args) + { + foreach(var property in args.properties) + { + Log.Debug($"[cueviewmodel] property <{property}> has been updated."); + if (property.Equals(QOSCKey.Name)) + { + OnPropertyChanged("name"); + }else if (property.Equals(QOSCKey.ColorName)) + { + OnPropertyChanged("color"); + } + } } void OnPropertyChanged([CallerMemberName] string name = "") diff --git a/QSharpXamDemo/QSharpXamDemo/ViewModels/SelectedQCueViewModel.cs b/QSharpXamDemo/QSharpXamDemo/ViewModels/SelectedQCueViewModel.cs deleted file mode 100644 index eca8e43..0000000 --- a/QSharpXamDemo/QSharpXamDemo/ViewModels/SelectedQCueViewModel.cs +++ /dev/null @@ -1,59 +0,0 @@ -using QSharp; -using System.ComponentModel; -using System.Runtime.CompilerServices; -using Xamarin.Forms; -namespace QSharpXamDemo.ViewModels -{ - public class SelectedQCueViewModel : INotifyPropertyChanged - { - QCue cue; - public event PropertyChangedEventHandler PropertyChanged; - - public SelectedQCueViewModel(QCue cue) - { - this.cue = cue; - } - - void OnPropertyChanged([CallerMemberName] string name = "") - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); - } - - public string name { - get - { - return cue.nonEmptyName; - } - - set - { - cue.name = value; - } - } - - public string number - { - get - { - return cue.number; - } - - set - { - cue.number = value; - } - } - - public Color color - { - get - { - return Color.FromHex(cue.color.Hex); - } - set - { - cue.color = new QColor("none"); - } - } - } -}