Files
qController/qController.Standard/Views/qConnectionPage.xaml.cs
T
jwetzell 31a10d9b16 * IconConstants.cs: Relocate
* QWorkspaceInfo.cs:
* QParser.cs:
* WorkspacePrompt.cs:
* QEventArgs.cs: Remove redundant QWorkspaceInfo class

* QRecentWorkspaceInfo.cs: Add bundle info class for recent workspace
  info

* ControlPage.xaml.cs:
* QBrowserPage.xaml.cs:
* QButton.cs:
* qConnectionPage.xaml.cs:
* QLevelsCell.cs:
* QCueListCell.cs:
* QInstanceCell.cs:
* QControlsBlock.cs:
* ShadowButton.cs:
* QLevelsButton.cs:
* QSelectedCueCell.cs: Move Cells classess under UI

* AppDelegate.cs:
* packages.config:
* MainActivity.cs:
* packages.config:
* qController.iOS.csproj:
* qController.Droid.csproj:
* qController.csproj: Update dependencies

* App.xaml.cs: Add AppAction code for recent workspace

* QStorage.cs: Add recent workspace to persistent storage

* QCueGrid.cs: Start on interactivity with cue list grid

* QCueViewModel.cs: debug for children updated start on reactive
  QCueGrid

* WorkspacePage.xaml.cs: Start handling a "no selected cue" state and
  recent workspace

* QInstance.cs:
* IPHelper.cs: move reachable check to IPHelper - TODO: implement
2020-11-29 14:22:01 -06:00

115 lines
3.8 KiB
C#

using Xamarin.Forms;
using System;
using Acr.UserDialogs;
using Zeroconf;
using System.Collections.Generic;
using Serilog;
using qController.QItems;
using qController.Dialogs;
using qController.UI.Cells;
using Xamarin.Essentials;
namespace qController
{
public partial class QConnectionPage : ContentPage
{
public QConnectionPage()
{
InitializeComponent();
InitGUI();
App.rootPage.MenuItemSelected += OnMenuItemSelected;
}
private void OnMenuItemSelected(object source, MenuEventArgs args)
{
if(args.Command == "scan")
{
Scan();
}
else if(args.Command == "add")
{
AddWorkspace();
}
else if (args.Command == "feedback")
{
Launcher.OpenAsync(new Uri("mailto:feedback@jwetzell.com?subject=qController%20feedback"));
}
else if(args.Command == "support")
{
UserDialogs.Instance.Confirm(new DonatePrompt());
}
}
private void InitGUI()
{
NavigationPage.SetHasNavigationBar(this, false);
//ListView Setup
listView.ItemsSource = QStorage.qInstances;
listView.ItemTemplate = new DataTemplate(typeof(QInstanceCell));
listView.ItemTapped += (object sender, ItemTappedEventArgs e) =>
{
// don't do anything if we just de-selected the row
if (e.Item == null) return;
// do something with e.SelectedItem
((ListView)sender).SelectedItem = null; // de-select the row
};
//Platform Specific Setup
switch (Device.RuntimePlatform)
{
case Device.iOS:
topBar.HeightRequest = App.Height * .09;
menuButton.FontSize = App.Height * .04;
menuButton.Margin = new Thickness(App.WidthUnit * 2, 0, 0, App.WidthUnit * 2);
break;
case Device.Android:
topBar.HeightRequest = App.Height * .09;
menuButton.FontSize = App.Height * .05;
menuButton.Margin = new Thickness(App.WidthUnit * 2, 0, 0, App.WidthUnit * 2);
break;
}
BackgroundColor = Color.FromHex("4A4A4A");
//MenuButton Setup
var menuButtonGesture = new TapGestureRecognizer();
menuButtonGesture.Tapped += App.ShowMenu;
menuButton.GestureRecognizers.Add(menuButtonGesture);
}
void AddWorkspace(){
UserDialogs.Instance.Prompt(new AddInstancePrompt());
}
async void Scan(){
bool workspacesFound = false;
App.showToast("Scanning for Instances...");
Log.Debug("QCONNECTIONPAGE - Begin Scanning");
IReadOnlyList<IZeroconfHost> results = await ZeroconfResolver.ResolveAsync("_qlab._udp.local.",TimeSpan.FromSeconds(3));
if(results != null){
foreach (var result in results)
{
if (result != null)
{
QInstance instance = new QInstance(result.DisplayName, result.IPAddress);
if(QStorage.AddInstance(instance)){
Log.Debug($"QCONNECTIONPAGE - {result.DisplayName} @ {result.IPAddress} added");
workspacesFound = true;
}
}
}
}
if(workspacesFound){
App.showToast("Instance Found and Added!");
}else{
App.showToast("No New Instances Found!");
}
}
}
}