Added auto refreshing

This commit is contained in:
2015-12-11 13:48:05 +01:00
parent 5860432c7e
commit dbf529123f
3 changed files with 46 additions and 3 deletions
+1
View File
@@ -37,6 +37,7 @@ namespace HueUWP.Lights
foreach(Light l in _lights)
{
await l.Update();
await Task.Delay(TimeSpan.FromMilliseconds(100));
}
return "success";
+1 -1
View File
@@ -24,7 +24,7 @@ namespace HueUWP.Lights
public override void SetColor(bool instant = false)
{
App.api.SetLightColor(this);
App.api.SetLightColor(this, instant);
}
public override async Task<String> Update()
+44 -2
View File
@@ -12,6 +12,7 @@ using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
@@ -37,6 +38,10 @@ namespace HueUWP.Views
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Enabled;
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
Application.Current.Suspending += Current_Suspending;
Application.Current.Resuming += Current_Resuming;
_lightsViewModel = new LightListDataSource();
timer = new DispatcherTimer();
@@ -44,14 +49,51 @@ namespace HueUWP.Views
timer.Tick += Timer_Tick;
}
private void Current_Resuming(object sender, object e)
{
if ((bool)DiscoButton.IsChecked)
App.api.DiscoMode(_lightsViewModel.GetLights());
}
private void Current_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
{
App.api.DiscoMode(false);
}
private void OnBackRequested(object sender, BackRequestedEventArgs e)
{
if((bool)GroupButton.IsChecked)
{
GroupButton.IsChecked = false;
GroupButton_Click(this, new RoutedEventArgs());
e.Handled = true;
}
}
private void Timer_Tick(object sender, object e)
{
QuietReloadLights();
}
private void StartTimer()
{
if ((bool)App.LOCAL_SETTINGS.Values["autorefresh"])
{
QuietReloadLights();
timer.Start();
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ReloadLights();
if (e.NavigationMode == NavigationMode.New)
ReloadLights();
else
{
LightsList.SelectedItems.Clear();
StartTimer();
}
this.DataContext = LightsViewModel;
}
@@ -82,7 +124,7 @@ namespace HueUWP.Views
else
{
FeedbackPanel.Visibility = Visibility.Collapsed;
timer.Start();
StartTimer();
}
Loading.IsActive = false;