From 6818a14940923c34aba75a3dda59e2799d409bcb Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Fri, 12 Feb 2021 22:55:01 -0500 Subject: [PATCH] * QCueGrid.cs: Rebuild cue grid when children cue change * QCueGridListHelper.cs: Helper class for linking cue id with cue grid * QCueViewModel.cs: Revoe unused import * QBrowserPage.xaml.cs: * ControlPage.xaml.cs: * QWorkspaceViewModel.cs: * qConnectionPage.xaml.cs: Remove unused import * QWorkspacePage.xaml.cs: Fix scrolling to select cue and handle no selected cue --- qController.Standard/Classes/UI/QCueGrid.cs | 57 ++++++++++++++++--- .../Classes/UI/QCueGridListHelper.cs | 41 ++++++++++++- .../ViewModels/QCueViewModel.cs | 3 +- .../ViewModels/QWorkspaceViewModel.cs | 5 +- .../Views/Old/ControlPage.xaml.cs | 2 +- .../Views/Old/qConnectionPage.xaml.cs | 2 +- .../Views/QBrowserPage.xaml.cs | 4 +- .../Views/QWorkspacePage.xaml.cs | 51 ++++++++++++----- 8 files changed, 134 insertions(+), 31 deletions(-) diff --git a/qController.Standard/Classes/UI/QCueGrid.cs b/qController.Standard/Classes/UI/QCueGrid.cs index 453e5f2..3663042 100644 --- a/qController.Standard/Classes/UI/QCueGrid.cs +++ b/qController.Standard/Classes/UI/QCueGrid.cs @@ -2,19 +2,29 @@ using qController.ViewModels; using QControlKit; using Serilog; +using System.Linq; namespace qController.UI { public class QCueGrid : Grid { private QCueViewModel qCueViewModel; + public QCueGrid(QCue cue) { qCueViewModel = new QCueViewModel(cue, true); - + qCueViewModel.PropertyChanged += QCueViewModel_PropertyChanged; RowSpacing = 0; + + BuildGrid(cue); + + } + + private void BuildGrid(QCue cue) + { RowDefinitions.Add( - new RowDefinition { + new RowDefinition + { Height = new GridLength(40), BindingContext = qCueViewModel } @@ -34,9 +44,9 @@ namespace qController.UI BorderColor = Color.Black, Margin = qCueViewModel.nestPadding }; - Children.Add(cueFrame,1,0); + Children.Add(cueFrame, 1, 0); Grid.SetRowSpan(cueFrame, cue.cues.Count + 1); - Grid.SetColumnSpan(cueFrame, ColumnDefinitions.Count-1); + Grid.SetColumnSpan(cueFrame, ColumnDefinitions.Count - 1); } var cueLabel = new Label @@ -60,7 +70,7 @@ namespace qController.UI VerticalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, Padding = 0, - Margin = new Thickness(10,0,0,0), + Margin = new Thickness(10, 0, 0, 0), //BackgroundColor = Color.Red }; @@ -77,7 +87,7 @@ namespace qController.UI cueTypeLabel.SetBinding(Label.TextProperty, "type", BindingMode.OneWay); cueTypeLabel.SetDynamicResource(Label.TextColorProperty, "IconTextColor"); - + if (!cue.IsCueList) { //Section for selecting a cue by tapping the name Label @@ -102,7 +112,7 @@ namespace qController.UI for (var i = 1; i < RowDefinitions.Count; i++) { RowDefinitions[i].Height = qCueViewModel.IsCollapsed ? 0 : GridLength.Auto; - + } if (Device.RuntimePlatform.Equals(Device.Android)) @@ -154,7 +164,8 @@ namespace qController.UI foreach (var aCue in cue.cues) { this.RowDefinitions.Add( - new RowDefinition { + new RowDefinition + { Height = GridLength.Auto, BindingContext = new QCueViewModel(aCue, false) } @@ -162,10 +173,40 @@ namespace qController.UI var aCueGrid = new QCueGrid(aCue); //cueGridDict.Add(aCue.uid, aCueGrid); aCueGrid.Margin = new Thickness(0, 0, 0, 0); + QCueGridListHelper.insert(aCue.uid, aCueGrid); Children.Add(aCueGrid, 0, aCue.sortIndex + 1); Grid.SetColumnSpan(aCueGrid, this.ColumnDefinitions.Count); } } } + + private void ReloadGrid() + { + Device.BeginInvokeOnMainThread(() => + { + //Nuke current grid + var children = this.Children.ToList(); + foreach (var child in children) + { + this.Children.Remove(child); + } + + RowDefinitions = new RowDefinitionCollection(); + + //rebuild + BuildGrid(qCueViewModel.cue); + + //TODO: check if this is working + qCueViewModel.cue.workspace.fetchPlaybackPositionForCue(qCueViewModel.cue); + }); + } + + private void QCueViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (e.PropertyName.Equals("cues")) + { + ReloadGrid(); + } + } } } diff --git a/qController.Standard/Classes/UI/QCueGridListHelper.cs b/qController.Standard/Classes/UI/QCueGridListHelper.cs index 2bdd0fa..c8066ea 100644 --- a/qController.Standard/Classes/UI/QCueGridListHelper.cs +++ b/qController.Standard/Classes/UI/QCueGridListHelper.cs @@ -1,10 +1,45 @@ -using System; -namespace qController +// Allows the "storage" of links between cue ids and QCueGrids +// a little hacky but works with the recursive nature of QCueGrids +// used mainly for scrolling to the appropriate QCueGrid when selected cue changes + +using System.Collections.Generic; + +namespace qController.UI { public class QCueGridListHelper { - public QCueGridListHelper() + private static Dictionary cueGridDict; + static QCueGridListHelper() { + cueGridDict = new Dictionary(); + } + + public static void reset() + { + cueGridDict.Clear(); + } + + public static void insert(string cueID, QCueGrid cueGrid) + { + if (cueGridDict.ContainsKey(cueID)) + { + cueGridDict[cueID] = cueGrid; + } + else + { + cueGridDict.Add(cueID, cueGrid); + } + } + + public static QCueGrid get(string cueID) + { + if (cueGridDict.ContainsKey(cueID)) + { + return cueGridDict[cueID]; + } + else { + return null; + } } } } diff --git a/qController.Standard/ViewModels/QCueViewModel.cs b/qController.Standard/ViewModels/QCueViewModel.cs index 0a56d51..a67a5d5 100644 --- a/qController.Standard/ViewModels/QCueViewModel.cs +++ b/qController.Standard/ViewModels/QCueViewModel.cs @@ -1,5 +1,4 @@ -using Serilog; -using System.ComponentModel; +using System.ComponentModel; using System.Runtime.CompilerServices; using Xamarin.Forms; diff --git a/qController.Standard/ViewModels/QWorkspaceViewModel.cs b/qController.Standard/ViewModels/QWorkspaceViewModel.cs index edd8f7a..df69a86 100644 --- a/qController.Standard/ViewModels/QWorkspaceViewModel.cs +++ b/qController.Standard/ViewModels/QWorkspaceViewModel.cs @@ -1,4 +1,7 @@ -using QControlKit; +using System; +using System.Threading.Tasks; +using QControlKit; +using Xamarin.Forms; namespace qController.ViewModels { diff --git a/qController.Standard/Views/Old/ControlPage.xaml.cs b/qController.Standard/Views/Old/ControlPage.xaml.cs index c83eebc..b48ac4a 100644 --- a/qController.Standard/Views/Old/ControlPage.xaml.cs +++ b/qController.Standard/Views/Old/ControlPage.xaml.cs @@ -4,7 +4,7 @@ using Xamarin.Forms; using Serilog; using Acr.UserDialogs; -using qController.Dialogs; +using qController.UI.Dialogs; using qController.QItems; using qController.UI.Cells; using qController.UI.Buttons; diff --git a/qController.Standard/Views/Old/qConnectionPage.xaml.cs b/qController.Standard/Views/Old/qConnectionPage.xaml.cs index 73dc520..f1a7fc3 100644 --- a/qController.Standard/Views/Old/qConnectionPage.xaml.cs +++ b/qController.Standard/Views/Old/qConnectionPage.xaml.cs @@ -5,7 +5,7 @@ using Zeroconf; using System.Collections.Generic; using Serilog; using qController.QItems; -using qController.Dialogs; +using qController.UI.Dialogs; using qController.UI.Cells; using Xamarin.Essentials; diff --git a/qController.Standard/Views/QBrowserPage.xaml.cs b/qController.Standard/Views/QBrowserPage.xaml.cs index faeb3d7..122a49e 100644 --- a/qController.Standard/Views/QBrowserPage.xaml.cs +++ b/qController.Standard/Views/QBrowserPage.xaml.cs @@ -3,7 +3,7 @@ using Xamarin.Forms; using Serilog; using qController.UI.Cells; using Acr.UserDialogs; -using qController.Dialogs; +using qController.UI.Dialogs; using Xamarin.Essentials; using System; using qController.ViewModels; @@ -110,5 +110,5 @@ namespace qController.Pages } } - + } \ No newline at end of file diff --git a/qController.Standard/Views/QWorkspacePage.xaml.cs b/qController.Standard/Views/QWorkspacePage.xaml.cs index 327f36f..5a42586 100644 --- a/qController.Standard/Views/QWorkspacePage.xaml.cs +++ b/qController.Standard/Views/QWorkspacePage.xaml.cs @@ -19,14 +19,16 @@ namespace qController { private QWorkspace connectedWorkspace; private string passcode; - private Dictionary cueGridDict = new Dictionary(); + public QWorkspacePage(QWorkspace workspace, string passcode = null) { InitializeComponent(); - connectedWorkspace = workspace; this.passcode = passcode; + + QCueGridListHelper.reset(); + SetupTopBar(); connectedWorkspace.WorkspaceUpdated += Workspace_WorkspaceUpdated; @@ -90,49 +92,69 @@ namespace qController QCue selectedCue = connectedWorkspace.cueWithID(args.cueID); if(selectedCue != null) { + //update properties for selected cue to ensure latest data for cue preview connectedWorkspace.fetchDefaultPropertiesForCue(selectedCue); + selectedCueFrame.BindingContext = new QCueViewModel(selectedCue, false); - if (cueGridDict.ContainsKey(args.cueID)) + + //Find cue grid for selected cue and scroll to it if it exists + QCueGrid gridToScrollTo = QCueGridListHelper.get(args.cueID); + if(gridToScrollTo != null) { - var cueGrid = cueGridDict[args.cueID]; //element to scroll to - //TODO: FIX THIS - cueListScrollView.ScrollToAsync(cueGrid, ScrollToPosition.Center, true); + cueListScrollView.ScrollToAsync(gridToScrollTo, ScrollToPosition.Center,true); } } + else + { + //Setup and "empty" cue for when no cue is selected + QCue emptyCue = new QCue(); + emptyCue.workspace = connectedWorkspace; + emptyCue.type = "Memo"; + emptyCue.listName = "No Cue Selected"; + + selectedCueFrame.BindingContext = new QCueViewModel(emptyCue, false); + } }); } void Workspace_WorkspaceUpdated(object source, QWorkspaceUpdatedArgs args) { Log.Debug("[workspacepage] Workspace Updated"); + + //Workspace updated means we connected so update the recent workspace App.SetRecentWorkspace(connectedWorkspace); + if (connectedWorkspace.cueLists.Count > 0) { List cueAddTasks = new List(); + + foreach (var aCue in connectedWorkspace.cueLists) { + if(aCue.cues.Count > 0) { - QCueGrid cueGrid = new QCueGrid(aCue); - - cueGridDict.Add(aCue.uid, cueGrid); - + QCueGrid mainCueGrid = new QCueGrid(aCue); MainThread.InvokeOnMainThreadAsync(() => { + QCueGridListHelper.insert(aCue.uid, mainCueGrid); cueListsGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); - cueListsGrid.Children.Add(cueGrid, 0, aCue.sortIndex); + cueListsGrid.Children.Add(mainCueGrid, 0, aCue.sortIndex); }).Wait(); } + break; //TODO: Make the displayed cue list selectable } - connectedWorkspace.valueForKey(connectedWorkspace.firstCueList, QOSCKey.PlaybackPositionId); //fetch playback position for cueList once all cue loading is done. + //TODO: fetch playback position for first cue list once all cue loading is done. + connectedWorkspace.valueForKey(connectedWorkspace.firstCueList, QOSCKey.PlaybackPositionId); + + //Display cuelist and selected cue info Device.BeginInvokeOnMainThread(() => { selectedCueFrame.IsVisible = true; cueListScrollView.IsVisible = true; }); - //break; //only load first cue list with cues. } } @@ -148,6 +170,9 @@ namespace qController if (connectedWorkspace.connected) connectedWorkspace.disconnect(); //TODO: This might not be implemented? + //purge QCueGridListHelper + QCueGridListHelper.reset(); + //unsubscribe from events App.rootPage.MenuItemSelected -= OnMenuItemSelected; connectedWorkspace.WorkspaceUpdated -= Workspace_WorkspaceUpdated;