Move CueGrid and SelectedCueGrid to own class

This commit is contained in:
2020-09-10 19:25:18 -05:00
parent f47c625e59
commit 3d61619081
4 changed files with 237 additions and 66 deletions
@@ -0,0 +1,70 @@
using Xamarin.Forms;
using qController.ViewModels;
using QControlKit;
namespace qController.UI
{
public class QCueGrid : Grid
{
public QCueGrid(QCue cue)
{
QCueViewModel qCueViewModel = new QCueViewModel(cue, true);
RowSpacing = 0;
RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) });
//Group List "Frame" added early so other children or "on top"
if (cue.cues.Count > 0)
{
var cueFrame = new Frame
{
BackgroundColor = Color.Transparent,
BorderColor = Color.Black
};
Children.Add(cueFrame);
Grid.SetRowSpan(cueFrame, cue.cues.Count + 1);
}
var cueLabel = new Label
{
BindingContext = qCueViewModel,
HorizontalOptions = LayoutOptions.StartAndExpand,
VerticalTextAlignment = TextAlignment.Center,
Padding = new Thickness(10,0,0,0)
};
cueLabel.SetBinding(Label.TextProperty, "name", BindingMode.OneWay);
//Section for selecting a cue by tapping the name Label
var selectCueGesture = new TapGestureRecognizer();
selectCueGesture.Tapped += (sender, e) =>
{
cue.workspace.firstCueList.playbackPositionID = cue.uid;
};
cueLabel.GestureRecognizers.Add(selectCueGesture);
var cueBackground = new Frame
{
BindingContext = qCueViewModel,
Opacity = 0.50,
HasShadow = false,
CornerRadius = 0,
BorderColor = Color.Black
};
cueBackground.SetBinding(BackgroundColorProperty, "color", BindingMode.OneWay);
var cueSelectedIndicator = new Frame
{
BindingContext = qCueViewModel,
BackgroundColor = Color.Blue,
HasShadow = false
};
cueSelectedIndicator.SetBinding(IsVisibleProperty, "IsSelected");
Children.Add(cueSelectedIndicator, 0, 0);
Children.Add(cueBackground, 0, 0);
Children.Add(cueLabel, 0, 0);
}
}
}
@@ -0,0 +1,161 @@
using Acr.UserDialogs;
using qController.ViewModels;
using Xamarin.Forms;
namespace qController.UI
{
public class QSelectedCueFrame : Frame
{
public QSelectedCueFrame()
{
//Colored border size
Padding = 8;
CornerRadius = 0;
this.SetBinding(Frame.BackgroundColorProperty, "color", BindingMode.OneWay);
this.SetBinding(Frame.BorderColorProperty, "color", BindingMode.OneWay);
Frame frameInt = new Frame
{
Padding = 0,
BackgroundColor = Color.FromHex("#D8D8D8")
};
Grid selectedCueGrid = new Grid
{
Margin = 0,
Padding = 0,
RowSpacing = 0,
ColumnSpacing = 0,
BackgroundColor = Color.Transparent,
RowDefinitions = {
new RowDefinition { Height = GridLength.Star },
new RowDefinition { Height = GridLength.Star },
new RowDefinition { Height = new GridLength(2, GridUnitType.Star) }
},
ColumnDefinitions = {
new ColumnDefinition { Width = GridLength.Star },
new ColumnDefinition { Width = GridLength.Star },
new ColumnDefinition { Width = GridLength.Star },
new ColumnDefinition { Width = GridLength.Star },
new ColumnDefinition { Width = GridLength.Star }
}
};
Label number = new Label
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalTextAlignment = TextAlignment.Start,
VerticalTextAlignment = TextAlignment.Center,
Margin = 0,
Padding = new Thickness(15,5,0,0),
FontSize = App.HeightUnit * 3
};
number.SetBinding(Label.TextProperty, "number", BindingMode.OneWay);
selectedCueGrid.Children.Add(number,0,0);
Grid.SetColumnSpan(number, 2);
Label type = new Label
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalTextAlignment = TextAlignment.End,
VerticalTextAlignment = TextAlignment.Center,
Margin = 0,
Padding = new Thickness(0,0,15,0),
FontSize = App.HeightUnit * 4,
FontFamily = App.QFont
};
type.SetBinding(Label.TextProperty, "type", BindingMode.OneWay);
selectedCueGrid.Children.Add(type, 4, 0);
Label name = new Label
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalTextAlignment = TextAlignment.Center,
VerticalTextAlignment = TextAlignment.Center,
BackgroundColor = Color.Transparent,
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label))
};
name.SetBinding(Label.TextProperty, "name", BindingMode.TwoWay);
selectedCueGrid.Children.Add(name, 0, 1);
Grid.SetColumnSpan(name, 5);
Editor notes = new Editor
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
Margin = 5,
BackgroundColor = Color.Transparent,
FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Editor))
};
notes.SetBinding(Editor.TextProperty, "notes", BindingMode.TwoWay);
selectedCueGrid.Children.Add(notes, 0, 2);
Grid.SetColumnSpan(notes, 5);
//Double tap to edit name/number
var nameDoubleTap = new TapGestureRecognizer();
nameDoubleTap.NumberOfTapsRequired = 2;
nameDoubleTap.Tapped += (s, e) =>
{
UserDialogs.Instance.Prompt(new PromptConfig
{
Title = "Update Name",
Message = "Change name to update",
OkText = "Update",
Text = name.Text,
OnAction = (qName) =>
{
if (!qName.Ok)
return;
name.Text = qName.Text;
}
});
};
name.GestureRecognizers.Add(nameDoubleTap);
var numberDoubleTap = new TapGestureRecognizer();
numberDoubleTap.NumberOfTapsRequired = 2;
numberDoubleTap.Tapped += (s, e) =>
{
UserDialogs.Instance.Prompt(new PromptConfig
{
Title = "Update Number",
Message = "Change number to update",
OkText = "Update",
Text = number.Text,
OnAction = (qNumber) =>
{
if (!qNumber.Ok)
return;
//This bypasses the label .Text property because the number might not be valid (no duplicates)
((QCueViewModel)BindingContext).number = qNumber.Text;
}
});
};
number.GestureRecognizers.Add(numberDoubleTap);
//BACKGROUND COLORS FOR TESTING ONLY
//notes.BackgroundColor = Color.Red;
//number.BackgroundColor = Color.Blue;
//name.BackgroundColor = Color.Green;
//type.BackgroundColor = Color.Yellow;
//setup contents
frameInt.Content = selectedCueGrid;
Content = frameInt;
}
}
}
@@ -6,6 +6,7 @@ using Xamarin.Forms;
using Acr.UserDialogs;
using qController.ViewModels;
using qController.UI;
using QControlKit;
using QControlKit.Events;
@@ -63,7 +64,7 @@ namespace qController
{
QCue selectedCue = connectedWorkspace.cueWithID(args.cueID);
connectedWorkspace.fetchDefaultPropertiesForCue(selectedCue);
selectedCueGrid.BindingContext = new QCueViewModel(selectedCue, false);
selectedCueFrame.BindingContext = new QCueViewModel(selectedCue, false);
if (cueGridDict.ContainsKey(args.cueID))
{
var cueGrid = cueGridDict[args.cueID]; //element to scroll to
@@ -83,7 +84,7 @@ namespace qController
List<Task> cueAddTasks = new List<Task>();
foreach (var aCue in cue.cues)
{
Grid cueGrid = cueToGrid(aCue);
QCueGrid cueGrid = cueToGrid(aCue);
cueGridDict.Add(aCue.uid, cueGrid);
MainThread.InvokeOnMainThreadAsync(() =>
{
@@ -110,67 +111,9 @@ namespace qController
}
Grid cueToGrid(QCue cue)
QCueGrid cueToGrid(QCue cue)
{
Grid cueGrid = new Grid { RowSpacing = 0 };
QCueViewModel qCueViewModel = new QCueViewModel(cue, true);
cueGrid.RowDefinitions = new RowDefinitionCollection();
cueGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) });
//Group List "Frame" added early so other children or "on top"
if (cue.cues.Count > 0)
{
var cueFrame = new Frame
{
BackgroundColor = Color.Transparent,
BorderColor = Color.Black
};
cueGrid.Children.Add(cueFrame);
Grid.SetRowSpan(cueFrame, cue.cues.Count + 1);
}
var cueLabel = new Label
{
BindingContext = qCueViewModel,
HorizontalOptions = LayoutOptions.StartAndExpand,
VerticalTextAlignment = TextAlignment.Center,
};
cueLabel.SetBinding(Label.TextProperty, "name", BindingMode.OneWay);
//System.Console.WriteLine($"Cue has continue mode: {cue.}" );
//Section for selecting a cue by tapping the name Label
var selectCueGesture = new TapGestureRecognizer();
selectCueGesture.Tapped += (sender, e) =>
{
connectedWorkspace.firstCueList.playbackPositionID = cue.uid;
};
cueLabel.GestureRecognizers.Add(selectCueGesture);
var cueBackground = new Frame
{
BindingContext = qCueViewModel,
Opacity = 0.50,
HasShadow = false,
CornerRadius = 0,
BorderColor = Color.Black
};
cueBackground.SetBinding(BackgroundColorProperty, "color", BindingMode.OneWay);
var cueSelectedIndicator = new Frame
{
BindingContext = qCueViewModel,
BackgroundColor = Color.Blue,
HasShadow = false
};
cueSelectedIndicator.SetBinding(IsVisibleProperty, "IsSelected");
cueGrid.Children.Add(cueSelectedIndicator, 0, 0);
cueGrid.Children.Add(cueBackground, 0, 0);
cueGrid.Children.Add(cueLabel, 0, 0);
QCueGrid cueGrid = new QCueGrid(cue);
if (cue.cues.Count > 0)
{
@@ -182,9 +125,6 @@ namespace qController
aCueGrid.Margin = new Thickness(10, 0, 0, 0);
cueGrid.Children.Add(aCueGrid, 0, aCue.sortIndex + 1);
}
}
return cueGrid;
}
@@ -27,7 +27,7 @@ namespace qController.ViewModels
{
foreach (var property in args.properties)
{
if (property.Equals(QOSCKey.Name))
if (property.Equals(QOSCKey.Name) || property.Equals(QOSCKey.ListName))
{
OnPropertyChanged("name");
}