diff --git a/HueUWP/HueUWP.csproj b/HueUWP/HueUWP.csproj index b8c36ff..8d7e882 100644 --- a/HueUWP/HueUWP.csproj +++ b/HueUWP/HueUWP.csproj @@ -111,6 +111,7 @@ SettingsView.xaml + diff --git a/HueUWP/MainPage.xaml b/HueUWP/MainPage.xaml index 8a4752e..e230437 100644 --- a/HueUWP/MainPage.xaml +++ b/HueUWP/MainPage.xaml @@ -23,7 +23,7 @@ Hue Lights - + + diff --git a/HueUWP/SettingsView.xaml.cs b/HueUWP/SettingsView.xaml.cs index 5d0ae35..98bfff1 100644 --- a/HueUWP/SettingsView.xaml.cs +++ b/HueUWP/SettingsView.xaml.cs @@ -22,9 +22,25 @@ namespace HueUWP /// 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; } } } diff --git a/HueUWP/SettingsViewModel.cs b/HueUWP/SettingsViewModel.cs new file mode 100644 index 0000000..9dc9d02 --- /dev/null +++ b/HueUWP/SettingsViewModel.cs @@ -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)); + } + } +}