This repository has been archived on 2020-12-20. You can view files and clone it, but cannot push or open issues or pull requests.
aurora-sharp-desktop/Aurora/Frontend/Components/HostSelector/HostSelector.xaml.cs
2019-06-25 21:17:52 -04:00

153 lines
4.4 KiB
C#

using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace Aurora.Frontend.Components.HostSelector
{
public enum ConnectionType
{
Host,
Client,
}
public enum SelectorState
{
SelectingHost,
EnteringCredentials,
}
public partial class HostSelector : ContentView
{
public HostSelector()
{
InitializeComponent();
//Set initial conditions
CredentialEditorLayout.IsVisible = true;
buttonHost.Clicked += OnButtonHostClicked;
buttonClient.Clicked += OnButtonClientClicked;
HostnameEntry.TextChanged += (sender, e) =>
{
Hostname = e.NewTextValue;
};
PortEntry.TextChanged += (sender, e) =>
{
Port = e.NewTextValue;
};
}
/// <summary>
/// On the host button clicked.
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="e">E.</param>
void OnButtonHostClicked(object sender, EventArgs e)
{
if (HostCommand.CanExecute(null))
{
HostCommand.Execute(null);
}
}
/// <summary>
/// On the client button clicked.
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="e">E.</param>
void OnButtonClientClicked(object sender, EventArgs e)
{
if (JoinCommand.CanExecute(null))
{
JoinCommand.Execute(null);
}
}
#region Host Selected Command
public static readonly BindableProperty HostCommandProperty =
BindableProperty.Create(propertyName: "HostSelectedCommand",
returnType: typeof(Command),
declaringType: typeof(HostSelector));
public Command HostCommand
{
get { return (Command)GetValue(HostCommandProperty); }
set { SetValue(HostCommandProperty, value); }
}
#endregion Host Selected Command
#region Client Selected Command
public static readonly BindableProperty JoinCommandProperty =
BindableProperty.Create(propertyName: "JoinSelectedCommand",
returnType: typeof(Command),
declaringType: typeof(HostSelector));
public Command JoinCommand
{
get { return (Command)GetValue(JoinCommandProperty); }
set { SetValue(JoinCommandProperty, value); }
}
#endregion Client Selected Command
#region Hostname property
public static readonly BindableProperty HostnameProperty =
BindableProperty.Create(propertyName: "Hostname",
returnType: typeof(string),
declaringType: typeof(HostSelector),
defaultBindingMode: BindingMode.TwoWay,
propertyChanged: OnHostNameChanged);
public string Hostname
{
get { return (string)GetValue(HostnameProperty); }
set { SetValue(HostnameProperty, value); }
}
private static void OnHostNameChanged(BindableObject bindable, object oldValue, object newValue)
{
string newVal = newValue as string;
HostSelector instance = bindable as HostSelector;
if (instance.HostnameEntry.Text != newValue)
{
instance.HostnameEntry.Text = newVal;
}
}
#endregion Hostname property
#region Port property
public static readonly BindableProperty PortProperty =
BindableProperty.Create(propertyName: "Port",
returnType: typeof(string),
declaringType: typeof(HostSelector),
defaultBindingMode: BindingMode.TwoWay,
propertyChanged: OnPortChanged);
public string Port
{
get { return (string)GetValue(PortProperty); }
set { SetValue(PortProperty, value); }
}
private static void OnPortChanged(BindableObject bindable, object oldValue, object newValue)
{
string newVal = newValue as string;
HostSelector instance = bindable as HostSelector;
if (instance.PortEntry.Text != newVal)
{
instance.PortEntry.Text = newVal;
}
}
#endregion Port property
}
}