Added settings page
This commit is contained in:
@@ -111,6 +111,7 @@
|
||||
<Compile Include="SettingsView.xaml.cs">
|
||||
<DependentUpon>SettingsView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="SettingsViewModel.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AppxManifest Include="Package.appxmanifest">
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<RelativePanel Grid.Row="0">
|
||||
<TextBlock RelativePanel.AlignLeftWithPanel="True" FontSize="24" Margin="20,10,0,0">Hue Lights</TextBlock>
|
||||
<StackPanel Orientation="Horizontal" RelativePanel.AlignRightWithPanel="True">
|
||||
<Button Name="RegisterButton" Click="RegisterButton_Click" FontFamily="Segoe MDL2 Assets" FontSize="18" Margin="10" Content="" />
|
||||
<Button Name="SettingsButton" Click="SettingsButton_Click" FontFamily="Segoe MDL2 Assets" FontSize="18" Margin="10" Content="" />
|
||||
<Button Name="RefreshButton" Click="RefreshButton_Click" FontFamily="Segoe MDL2 Assets" FontSize="18" Margin="10" Content="" />
|
||||
</StackPanel>
|
||||
</RelativePanel>
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace HueUWP
|
||||
|
||||
private ObservableCollection<Light> _lightsViewModel = LightDataSource.GetLights();
|
||||
|
||||
private APIHandler api;
|
||||
public APIHandler api;
|
||||
|
||||
public ObservableCollection<Light> LightsViewModel
|
||||
{
|
||||
@@ -42,8 +42,8 @@ namespace HueUWP
|
||||
public MainPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
LOCAL_SETTINGS.Values["ip"] = "localhost";
|
||||
LOCAL_SETTINGS.Values["port"] = 8000;
|
||||
//LOCAL_SETTINGS.Values["ip"] = "localhost";
|
||||
//LOCAL_SETTINGS.Values["port"] = 8000;
|
||||
NetworkHandler nwh = new NetworkHandler();
|
||||
api = new APIHandler(nwh);
|
||||
_lightsViewModel.Clear();
|
||||
@@ -75,10 +75,10 @@ namespace HueUWP
|
||||
light.UpdateColor(0, 38, 255);
|
||||
}
|
||||
|
||||
private void RegisterButton_Click(object sender, RoutedEventArgs e)
|
||||
private void SettingsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
api.Register();
|
||||
Debug.WriteLine(LOCAL_SETTINGS.Values["id"]);
|
||||
Frame rootframe = Window.Current.Content as Frame;
|
||||
rootframe.Navigate(typeof(SettingsView), api);
|
||||
}
|
||||
|
||||
private void RefreshButton_Click(object sender, RoutedEventArgs e)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
<!--DataContext="{Binding SettingsViewModel, RelativeSource={RelativeSource Self}}"-->
|
||||
|
||||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<Grid.RowDefinitions>
|
||||
@@ -16,5 +17,25 @@
|
||||
<RelativePanel Grid.Row="0">
|
||||
<TextBlock RelativePanel.AlignLeftWithPanel="True" FontSize="24" Margin="20,10,0,0">Settings</TextBlock>
|
||||
</RelativePanel>
|
||||
|
||||
<StackPanel Grid.Row="1">
|
||||
<StackPanel Margin="10">
|
||||
<TextBlock FontSize="16">Server IP</TextBlock>
|
||||
<TextBox Margin="0,10,0,10" Text="{x:Bind SettingsViewModel.IP, Mode=TwoWay}" />
|
||||
</StackPanel>
|
||||
<StackPanel Margin="10">
|
||||
<TextBlock FontSize="16">Server Port</TextBlock>
|
||||
<TextBox Margin="0,10,0,10" Text="{x:Bind SettingsViewModel.PORT, Mode=TwoWay}" />
|
||||
</StackPanel>
|
||||
<StackPanel Margin="10">
|
||||
<TextBlock FontSize="16">User ID</TextBlock>
|
||||
<TextBox Margin="0,10,0,10" Text="{x:Bind SettingsViewModel.ID, Mode=OneWay}" IsEnabled="False"/>
|
||||
<Button Margin="0,10,0,10" Name="UpdateID" Click="UpdateID_Click">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock FontFamily="Segoe MDL2 Assets" FontSize="10" Margin="10" Text="" /><TextBlock FontSize="10" Margin="10" Text="Request new" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Page>
|
||||
|
||||
@@ -22,9 +22,25 @@ namespace HueUWP
|
||||
/// </summary>
|
||||
public sealed partial class SettingsView : Page
|
||||
{
|
||||
public SettingsViewModel SettingsViewModel = new SettingsViewModel();
|
||||
|
||||
private APIHandler api;
|
||||
|
||||
public SettingsView()
|
||||
{
|
||||
{
|
||||
this.InitializeComponent();
|
||||
//SettingsViewModel = new SettingsViewModel();
|
||||
}
|
||||
|
||||
private void UpdateID_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
api.Register();
|
||||
SettingsViewModel.Update();
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
api = e.Parameter as APIHandler;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace HueUWP
|
||||
{
|
||||
public class SettingsViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private static ApplicationDataContainer LOCAL_SETTINGS = ApplicationData.Current.LocalSettings;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void NotifyPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public string IP
|
||||
{
|
||||
get { Debug.WriteLine(LOCAL_SETTINGS.Values["ip"]); return LOCAL_SETTINGS.Values["ip"] as string; }
|
||||
set { LOCAL_SETTINGS.Values["ip"] = value; NotifyPropertyChanged(nameof(IP)); }
|
||||
}
|
||||
|
||||
public string PORT
|
||||
{
|
||||
get { Debug.WriteLine(LOCAL_SETTINGS.Values["port"]); return Convert.ToInt32(LOCAL_SETTINGS.Values["port"]).ToString(); }
|
||||
set { LOCAL_SETTINGS.Values["port"] = int.Parse(value); NotifyPropertyChanged(nameof(PORT)); }
|
||||
}
|
||||
|
||||
public string ID
|
||||
{
|
||||
get { Debug.WriteLine(LOCAL_SETTINGS.Values["id"]); return LOCAL_SETTINGS.Values["id"] as string; }
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
NotifyPropertyChanged(nameof(ID));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user