Reorganization
This commit is contained in:
39
Aurora/Design/Components/HostSelector/HostSelector.xaml
Normal file
39
Aurora/Design/Components/HostSelector/HostSelector.xaml
Normal file
@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentView
|
||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Aurora.Design.Components.HostSelector.HostSelector">
|
||||
<ContentView.Content>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition
|
||||
Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<StackLayout
|
||||
Grid.Row="0"
|
||||
x:Name="CredentialEditorLayout"
|
||||
Orientation="Horizontal"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="Start">
|
||||
<Label
|
||||
Text="Hostname"
|
||||
VerticalOptions="Center"/>
|
||||
<Entry
|
||||
x:Name="HostnameEntry"/>
|
||||
<Label
|
||||
Text="Port"
|
||||
VerticalOptions="Center"/>
|
||||
<Entry
|
||||
x:Name="PortEntry"/>
|
||||
<Button
|
||||
HorizontalOptions="Center"
|
||||
x:Name="buttonHost"
|
||||
Text="Host"/>
|
||||
<Button
|
||||
HorizontalOptions="Center"
|
||||
x:Name="buttonClient"
|
||||
Text="Join"/>
|
||||
</StackLayout>
|
||||
</Grid>
|
||||
</ContentView.Content>
|
||||
</ContentView>
|
152
Aurora/Design/Components/HostSelector/HostSelector.xaml.cs
Normal file
152
Aurora/Design/Components/HostSelector/HostSelector.xaml.cs
Normal file
@ -0,0 +1,152 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Aurora.Design.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 != newVal)
|
||||
{
|
||||
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
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user