Server Listing Work and Passcode connection

This commit is contained in:
2020-09-10 09:40:01 -05:00
parent 3675272316
commit c90b26bf2a
6 changed files with 223 additions and 96 deletions
+101 -54
View File
@@ -3,73 +3,120 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
mc:Ignorable="d" mc:Ignorable="d"
x:Class="qController.Pages.QBrowserPage"> x:Class="qController.Pages.QBrowserPage">
<ContentPage.Content> <ContentPage.Content>
<StackLayout x:Name="sLayout"> <StackLayout x:Name="sLayout" Spacing="0">
<!--Old "Instance" listview -->
<ListView x:Name="storageListView" <ListView x:Name="storageListView"
HasUnevenRows="true" HasUnevenRows="true"
BackgroundColor="#4A4A4A" BackgroundColor="#4a4a4a"
SeparatorVisibility="None"> SeparatorVisibility="None">
</ListView> </ListView>
<ListView x:Name="serverListView"
GroupDisplayBinding="{Binding name}" <!--Beginning of new style of "server" view-->
<BoxView HeightRequest="10" BackgroundColor="DarkGray"/>
<Frame BackgroundColor="SlateGray"
CornerRadius="0"
HasShadow="False"
Margin="0"
Padding="0">
<!--Need to try and remove the group spacing caused by ios:GroupHeaderStyle-->
<ListView x:Name="serverListView"
ios:ListView.GroupHeaderStyle="Grouped"
GroupDisplayBinding="{Binding name}"
IsGroupingEnabled="True" IsGroupingEnabled="True"
d:IsGroupingEnabled="False" d:IsGroupingEnabled="False"
BackgroundColor="#4A4A4A" BackgroundColor="Transparent"
SeparatorVisibility="None" SeparatorVisibility="None"
ItemsSource="{Binding ServersGrouped}"> ItemsSource="{Binding ServersGrouped}"
<ListView.GroupHeaderTemplate> Margin="0">
<DataTemplate> <ListView.GroupHeaderTemplate>
<ViewCell Height="25"> <DataTemplate>
<Grid BackgroundColor="#ffffff" VerticalOptions="FillAndExpand"> <ViewCell>
<Label Text="{Binding GroupName}" <Frame BackgroundColor="#ffffff"
HorizontalOptions="FillAndExpand" Margin="0,0,0,0"
VerticalOptions="FillAndExpand" Padding="10,0,10,0"
VerticalTextAlignment="Center" CornerRadius="0">
HorizontalTextAlignment="Start"/> <Grid BackgroundColor="Transparent" VerticalOptions="FillAndExpand"
</Grid> RowSpacing="0"
</ViewCell> ColumnSpacing="0">
</DataTemplate> <Grid.RowDefinitions>
</ListView.GroupHeaderTemplate> <RowDefinition Height="*"/>
<ListView.ItemTemplate> </Grid.RowDefinitions>
<DataTemplate> <Grid.ColumnDefinitions>
<ViewCell> <ColumnDefinition Width="*"/>
<Grid Margin="20,0,0,0" BackgroundColor="#D8D8D8"> <ColumnDefinition Width="Auto"/>
<Grid.RowDefinitions> </Grid.ColumnDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Text="{Binding Name}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
VerticalTextAlignment="Center"
HorizontalTextAlignment="Start"/>
<Label Grid.Column="1" Text="&#xf1184;" <Label Grid.Column="0"
FontFamily="{StaticResource MaterialFontFamily}" Text="{Binding GroupName}"
FontSize="Large" HorizontalOptions="FillAndExpand"
IsVisible="{Binding HasPasscode}" VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand" VerticalTextAlignment="Center"
VerticalOptions="FillAndExpand" HorizontalTextAlignment="Start"/>
VerticalTextAlignment="Center" <Label Grid.Column="1"
HorizontalTextAlignment="End"/> Text="{Binding version}"
</Grid> HorizontalOptions="FillAndExpand"
</ViewCell> VerticalOptions="FillAndExpand"
</DataTemplate> VerticalTextAlignment="Center"
</ListView.ItemTemplate> HorizontalTextAlignment="End"/>
</ListView> </Grid>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame BackgroundColor="#D8D8D8"
BorderColor="Black"
Margin="5,0,5,0"
Padding="10,0,10,0"
CornerRadius="0"
HasShadow="False">
<Grid Margin="0"
BackgroundColor="Transparent"
RowSpacing="0"
ColumnSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Text="{Binding Name}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
VerticalTextAlignment="Center"
HorizontalTextAlignment="Start"/>
<Label Grid.Column="1" Text="&#xf1184;"
FontFamily="{StaticResource MaterialFontFamily}"
FontSize="Large"
IsVisible="{Binding HasPasscode}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
VerticalTextAlignment="Center"
HorizontalTextAlignment="End"/>
</Grid>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Frame>
</StackLayout> </StackLayout>
</ContentPage.Content> </ContentPage.Content>
</ContentPage> </ContentPage>
@@ -18,12 +18,8 @@ namespace qController.Pages
App.rootPage.MenuItemSelected += OnMenuItemSelected; App.rootPage.MenuItemSelected += OnMenuItemSelected;
serverListView.BindingContext = new QBrowserViewModel(new QBrowser()); serverListView.BindingContext = new QBrowserViewModel(new QBrowser());
serverListView.ItemSelected += QWorkspaceSelected; serverListView.ItemSelected += QWorkspaceSelected;
storageListView.ItemsSource = QStorage.qInstances; storageListView.ItemsSource = QStorage.qInstances;
storageListView.ItemTemplate = new DataTemplate(typeof(QInstanceCell)); storageListView.ItemTemplate = new DataTemplate(typeof(QInstanceCell));
storageListView.ItemTapped += (object sender, ItemTappedEventArgs e) => storageListView.ItemTapped += (object sender, ItemTappedEventArgs e) =>
@@ -53,10 +49,15 @@ namespace qController.Pages
Title = "Workspace Requires Passcode", Title = "Workspace Requires Passcode",
OkText = "Connect", OkText = "Connect",
IsCancellable = true, IsCancellable = true,
OnTextChanged = args =>
{
args.IsValid = args.Value != null && !args.Value.Equals("") && args.Value.Length == 4;
},
OnAction = async (resp) => OnAction = async (resp) =>
{ {
if (resp.Ok) if (resp.Ok)
{ {
Console.WriteLine($"Passcode is null: {resp.Value == null}");
await Navigation.PushAsync(new WorkspacePage(selectedWorkspace, resp.Value)); await Navigation.PushAsync(new WorkspacePage(selectedWorkspace, resp.Value));
} }
} }
+14 -10
View File
@@ -7,20 +7,13 @@
x:Class="qController.WorkspacePage"> x:Class="qController.WorkspacePage">
<Grid RowSpacing="0"> <Grid RowSpacing="0">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="200"/> <RowDefinition Height="150"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<ScrollView x:Name="cueListScrollView"
Grid.Row="1">
<Grid x:Name="cueListsGrid"
RowSpacing="0"
ColumnSpacing="0"
BackgroundColor="#808080">
<Grid.RowDefinitions></Grid.RowDefinitions>
</Grid>
</ScrollView>
<Grid x:Name="selectedCueGrid" <Grid x:Name="selectedCueGrid"
Grid.Row="0" Grid.Row="0"
@@ -60,5 +53,16 @@
HorizontalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"
FontSize="Large"/> FontSize="Large"/>
</Grid> </Grid>
<ScrollView x:Name="cueListScrollView"
Grid.Row="1">
<Grid x:Name="cueListsGrid"
RowSpacing="0"
ColumnSpacing="0"
BackgroundColor="#808080">
<Grid.RowDefinitions></Grid.RowDefinitions>
</Grid>
</ScrollView>
</Grid> </Grid>
</ContentPage> </ContentPage>
@@ -6,6 +6,7 @@ using Serilog;
using Xamarin.Essentials; using Xamarin.Essentials;
using Xamarin.Forms; using Xamarin.Forms;
using Acr.UserDialogs; using Acr.UserDialogs;
using System.Windows.Input;
namespace qController namespace qController
{ {
@@ -13,29 +14,44 @@ namespace qController
{ {
private QWorkspace connectedWorkspace; private QWorkspace connectedWorkspace;
private Dictionary<string, Grid> cueGridDict = new Dictionary<string, Grid>(); private Dictionary<string, Grid> cueGridDict = new Dictionary<string, Grid>();
public WorkspacePage(QWorkspace workspace, string passcode = null)
public WorkspacePage(QWorkspace workspace)
{ {
InitializeComponent(); InitializeComponent();
connectedWorkspace = workspace; connectedWorkspace = workspace;
connectedWorkspace.WorkspaceUpdated += Workspace_WorkspaceUpdated; connectedWorkspace.WorkspaceUpdated += Workspace_WorkspaceUpdated;
connectedWorkspace.WorkspaceConnectionError += ConnectedWorkspace_WorkspaceConnectionError;
connectedWorkspace.defaultSendUpdatesOSC = true; connectedWorkspace.defaultSendUpdatesOSC = true;
connectedWorkspace.CueListChangedPlaybackPosition += ConnectedWorkspace_CueListChangedPlaybackPosition; connectedWorkspace.CueListChangedPlaybackPosition += ConnectedWorkspace_CueListChangedPlaybackPosition;
connectedWorkspace.connect(passcode);
} }
public WorkspacePage(QWorkspace workspace, string passcode) private void ConnectedWorkspace_WorkspaceConnectionError(object source, QWorkspaceConnectionErrorArgs connectionErrorArgs)
{ {
InitializeComponent(); System.Console.WriteLine("WorkspaceConnectionError Called");
if (connectionErrorArgs.status.Equals("badpass"))
connectedWorkspace = workspace; {
connectedWorkspace.WorkspaceUpdated += Workspace_WorkspaceUpdated; UserDialogs.Instance.Prompt(new PromptConfig
connectedWorkspace.connectWithPasscode(passcode); {
InputType = InputType.Number,
MaxLength = 4,
connectedWorkspace.defaultSendUpdatesOSC = true; Title = "Incorrect Passcode!",
connectedWorkspace.CueListChangedPlaybackPosition += ConnectedWorkspace_CueListChangedPlaybackPosition; OkText = "Connect",
IsCancellable = true,
OnTextChanged = args =>
{
args.IsValid = args.Value != null && !args.Value.Equals("") && args.Value.Length == 4;
},
OnAction = (resp) =>
{
if (resp.Ok)
{
connectedWorkspace.connect(resp.Value);
}
}
});
}
} }
void ConnectedWorkspace_CueListChangedPlaybackPosition(object source, QCueListChangedPlaybackPositionArgs args) void ConnectedWorkspace_CueListChangedPlaybackPosition(object source, QCueListChangedPlaybackPositionArgs args)
@@ -84,6 +100,7 @@ namespace qController
//unsubscribe from events //unsubscribe from events
connectedWorkspace.WorkspaceUpdated -= Workspace_WorkspaceUpdated; connectedWorkspace.WorkspaceUpdated -= Workspace_WorkspaceUpdated;
connectedWorkspace.CueListChangedPlaybackPosition -= ConnectedWorkspace_CueListChangedPlaybackPosition; connectedWorkspace.CueListChangedPlaybackPosition -= ConnectedWorkspace_CueListChangedPlaybackPosition;
connectedWorkspace.WorkspaceConnectionError -= ConnectedWorkspace_WorkspaceConnectionError;
//disconnect //disconnect
connectedWorkspace.disconnect(); connectedWorkspace.disconnect();
@@ -95,6 +112,20 @@ namespace qController
QCueViewModel qCueViewModel = new QCueViewModel(cue, true); QCueViewModel qCueViewModel = new QCueViewModel(cue, true);
cueGrid.RowDefinitions = new RowDefinitionCollection(); cueGrid.RowDefinitions = new RowDefinitionCollection();
cueGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) }); 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 var cueLabel = new Label
{ {
BindingContext = qCueViewModel, BindingContext = qCueViewModel,
@@ -102,6 +133,17 @@ namespace qController
VerticalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center,
}; };
cueLabel.SetBinding(Label.TextProperty, "name", BindingMode.OneWay); 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 var cueBackground = new Frame
{ {
BindingContext = qCueViewModel, BindingContext = qCueViewModel,
@@ -110,6 +152,7 @@ namespace qController
CornerRadius = 0, CornerRadius = 0,
BorderColor = Color.Black BorderColor = Color.Black
}; };
cueBackground.SetBinding(BackgroundColorProperty, "color", BindingMode.OneWay); cueBackground.SetBinding(BackgroundColorProperty, "color", BindingMode.OneWay);
var cueSelectedIndicator = new Frame var cueSelectedIndicator = new Frame
@@ -118,13 +161,13 @@ namespace qController
BackgroundColor = Color.Blue, BackgroundColor = Color.Blue,
HasShadow = false HasShadow = false
}; };
cueSelectedIndicator.SetBinding(IsVisibleProperty, "IsSelected"); cueSelectedIndicator.SetBinding(IsVisibleProperty, "IsSelected");
cueGrid.Children.Add(cueSelectedIndicator, 0, 0); cueGrid.Children.Add(cueSelectedIndicator, 0, 0);
cueGrid.Children.Add(cueBackground, 0, 0); cueGrid.Children.Add(cueBackground, 0, 0);
cueGrid.Children.Add(cueLabel, 0, 0); cueGrid.Children.Add(cueLabel, 0, 0);
int rows = 1;
if (cue.cues.Count > 0) if (cue.cues.Count > 0)
{ {
foreach (var aCue in cue.cues) foreach (var aCue in cue.cues)
@@ -134,17 +177,9 @@ namespace qController
cueGridDict.Add(aCue.uid, aCueGrid); cueGridDict.Add(aCue.uid, aCueGrid);
aCueGrid.Margin = new Thickness(10, 0, 0, 0); aCueGrid.Margin = new Thickness(10, 0, 0, 0);
cueGrid.Children.Add(aCueGrid, 0, aCue.sortIndex + 1); cueGrid.Children.Add(aCueGrid, 0, aCue.sortIndex + 1);
rows++;
} }
var cueFrame = new Frame
{
BackgroundColor = Color.Transparent,
BorderColor = Color.Black
};
cueGrid.Children.Add(cueFrame);
Grid.SetRowSpan(cueFrame, rows);
} }
return cueGrid; return cueGrid;
@@ -2,6 +2,7 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Xamarin.Forms;
namespace qController.ViewModels namespace qController.ViewModels
{ {
@@ -22,8 +23,11 @@ namespace qController.ViewModels
private void OnServerFound(object source, QServerFoundArgs args) private void OnServerFound(object source, QServerFoundArgs args)
{ {
ServersGrouped.Add(new QServerViewModel(args.server)); Device.BeginInvokeOnMainThread(() =>
{
System.Console.WriteLine($"[QBrowserViewModel] adding server: {args.server.description}");
ServersGrouped.Add(new QServerViewModel(args.server));
});
} }
void OnPropertyChanged([CallerMemberName] string name = "") void OnPropertyChanged([CallerMemberName] string name = "")
@@ -1,11 +1,15 @@
using QControlKit; using QControlKit;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Xamarin.Forms;
namespace qController.ViewModels namespace qController.ViewModels
{ {
public class QServerViewModel : ObservableCollection<QWorkspaceViewModel> public class QServerViewModel : ObservableCollection<QWorkspaceViewModel>, INotifyPropertyChanged
{ {
QServer server; QServer server;
public new event PropertyChangedEventHandler PropertyChanged;
public string name public string name
{ {
get get
@@ -26,6 +30,22 @@ namespace qController.ViewModels
} }
} }
public string version
{
get
{
if (server.version == null)
{
return "";
}
else
{
return $"v{server.version}";
}
}
}
public string GroupName public string GroupName
{ {
get get
@@ -40,19 +60,35 @@ namespace qController.ViewModels
name = this.server.name; name = this.server.name;
foreach (var workspace in this.server.workspaces) foreach (var workspace in this.server.workspaces)
{ {
this.Add(new QWorkspaceViewModel(workspace)); Device.BeginInvokeOnMainThread(() =>
{
this.Add(new QWorkspaceViewModel(workspace));
});
} }
this.server.ServerUpdated += OnServerUpdated; this.server.ServerUpdated += OnServerUpdated;
} }
private void OnServerUpdated(object source, QServerUpdatedArgs args) private void OnServerUpdated(object source, QServerUpdatedArgs args)
{ {
OnPropertyChanged("GroupName");
OnPropertyChanged("version");
foreach (var workspace in this.server.workspaces) foreach (var workspace in this.server.workspaces)
{ {
QWorkspaceViewModel workspaceViewModel = new QWorkspaceViewModel(workspace); QWorkspaceViewModel workspaceViewModel = new QWorkspaceViewModel(workspace);
if (!Contains(workspaceViewModel)) if (!Contains(workspaceViewModel))
Add(workspaceViewModel); {
Device.BeginInvokeOnMainThread(() =>
{
Add(workspaceViewModel);
});
}
} }
} }
void OnPropertyChanged([CallerMemberName] string name = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
} }
} }