Added progress rings and error feedback
This commit is contained in:
+15
-8
@@ -20,17 +20,21 @@ namespace HueUWP
|
||||
this.nwh = nwh;
|
||||
}
|
||||
|
||||
public async Task Register()
|
||||
public async Task<String> Register()
|
||||
{
|
||||
try {
|
||||
var json = await nwh.RegisterName("Hue", "Kenneth&Yorick");
|
||||
try
|
||||
{
|
||||
var json = await nwh.RegisterName("YK Hue", "YK");
|
||||
json = json.Replace("[", "").Replace("]", "");
|
||||
JObject o = JObject.Parse(json);
|
||||
string id = o["success"]["username"].ToString();
|
||||
MainPage.LOCAL_SETTINGS.Values["id"] = id; }
|
||||
catch(Exception e)
|
||||
MainPage.LOCAL_SETTINGS.Values["id"] = id;
|
||||
return "success";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine("Could not register.");
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,15 +49,17 @@ namespace HueUWP
|
||||
lights.ForEach(l => SetLightState(l));
|
||||
}
|
||||
|
||||
public async void SetLightValues(Light l)
|
||||
public async Task<String> SetLightValues(Light l)
|
||||
{
|
||||
if(l.IsOn)
|
||||
{
|
||||
Debug.WriteLine(l.Hue);
|
||||
var json = await nwh.SetLightInfo(l.ID, $"{{\"bri\": {l.Brightness},\"hue\": {(l.Hue)},\"sat\": {l.Saturation}}}");
|
||||
Debug.WriteLine(json);
|
||||
return "success";
|
||||
}
|
||||
|
||||
return "error";
|
||||
}
|
||||
|
||||
public async void SetLightValues(List<Light> lights)
|
||||
@@ -85,14 +91,15 @@ namespace HueUWP
|
||||
// );
|
||||
|
||||
//lightlist.ForEach(q => alllights.Add(q));
|
||||
|
||||
return "success";
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Debug.WriteLine(e.StackTrace);
|
||||
Debug.WriteLine("Could not get all lights.");
|
||||
return "error";
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+11
-5
@@ -16,6 +16,7 @@
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
@@ -24,10 +25,15 @@
|
||||
<TextBlock RelativePanel.AlignLeftWithPanel="True" FontSize="24" Margin="20,10,0,0">Hue Lights</TextBlock>
|
||||
</RelativePanel>
|
||||
|
||||
<ProgressRing Grid.Row="1" Height="60" Width="60" RelativePanel.AlignHorizontalCenterWithPanel="True" Margin=" 0,10,0,10" IsActive="True" Name="Loading" />
|
||||
<RelativePanel Grid.Row="1" Visibility="Visible" Name="FeedbackPanel">
|
||||
<ProgressRing Height="60" Width="60" RelativePanel.AlignHorizontalCenterWithPanel="True" Margin=" 0,10,0,10" IsActive="True" Name="Loading" />
|
||||
<TextBlock RelativePanel.AlignLeftWithPanel="True" Name="ErrorMessage" Margin="20,10,0,10"/>
|
||||
</RelativePanel>
|
||||
|
||||
|
||||
<StackPanel Grid.Row="1" Margin="0,10,0,0" Name="LightListPanel" Visibility="Collapsed">
|
||||
<ListView x:Name="myListView" ItemsSource="{Binding}" IsItemClickEnabled="True" ItemClick="myListView_ItemClick">
|
||||
<RelativePanel Grid.Row="2" Margin="0,10,0,0" Name="LightListPanel">
|
||||
<ScrollViewer RelativePanel.AlignBottomWithPanel="True" RelativePanel.AlignTopWithPanel="True">
|
||||
<ListView x:Name="myListView" ItemsSource="{Binding}" IsItemClickEnabled="True" ItemClick="myListView_ItemClick" >
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:Name="dataTemplate">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
@@ -48,8 +54,8 @@
|
||||
</ListView.ItemTemplate>
|
||||
|
||||
</ListView>
|
||||
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</RelativePanel>
|
||||
|
||||
</Grid>
|
||||
|
||||
|
||||
+13
-1
@@ -58,9 +58,21 @@ namespace HueUWP
|
||||
|
||||
private async void Load_Lights()
|
||||
{
|
||||
ErrorMessage.Text = "";
|
||||
FeedbackPanel.Visibility = Visibility.Visible;
|
||||
_lightsViewModel.Clear();
|
||||
|
||||
Loading.IsActive = true;
|
||||
await api.GetAllLights(_lightsViewModel);
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(200));
|
||||
string s = await api.GetAllLights(_lightsViewModel);
|
||||
|
||||
if (s == "error")
|
||||
ErrorMessage.Text = "There was a problem connecting...";
|
||||
else if (_lightsViewModel.Count < 1)
|
||||
ErrorMessage.Text = "No lights found...";
|
||||
else
|
||||
FeedbackPanel.Visibility = Visibility.Collapsed;
|
||||
|
||||
Loading.IsActive = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace HueUWP
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
return string.Empty;
|
||||
return "error";
|
||||
}
|
||||
|
||||
string jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
@@ -48,7 +48,7 @@ namespace HueUWP
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(ex.Message);
|
||||
return string.Empty;
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace HueUWP
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
return string.Empty;
|
||||
return "error";
|
||||
}
|
||||
|
||||
string jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
@@ -80,7 +80,7 @@ namespace HueUWP
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(ex.Message);
|
||||
return string.Empty;
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace HueUWP
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
return string.Empty;
|
||||
return "error";
|
||||
}
|
||||
|
||||
string jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
@@ -111,7 +111,7 @@ namespace HueUWP
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(ex.Message);
|
||||
return string.Empty;
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace HueUWP
|
||||
{
|
||||
var response = await Post("",$"{{\"devicetype\":\"{AppName}#{UserName}\"}}");
|
||||
if (string.IsNullOrEmpty(response))
|
||||
await new MessageDialog("Error while setting username. ….").ShowAsync();
|
||||
return "error";
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ namespace HueUWP
|
||||
{
|
||||
var response = await Get($"{(String)MainPage.LOCAL_SETTINGS.Values["id"]}/lights");
|
||||
if (string.IsNullOrEmpty(response))
|
||||
await new MessageDialog("Error while getting all lights. ….").ShowAsync();
|
||||
return "error";
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
</StackPanel>
|
||||
<StackPanel Margin="20">
|
||||
<TextBlock FontSize="16">User ID</TextBlock>
|
||||
<TextBox Margin="0,10,0,10" Text="{x:Bind SettingsViewModel.ID, Mode=OneWay}" IsEnabled="False"/>
|
||||
<TextBox Name="IDBox" Margin="0,10,0,10" Text="{x:Bind SettingsViewModel.ID, Mode=OneWay}" IsEnabled="False"/>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,10,0,10">
|
||||
<Button Name="UpdateID" Click="UpdateID_Click">
|
||||
<Button Click="UpdateID_Click">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock FontFamily="Segoe MDL2 Assets" FontSize="15" Margin="5, 9, 5, 5" Text="" />
|
||||
<TextBlock FontSize="15" Margin="5" Text="Request new" />
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
@@ -35,10 +36,16 @@ namespace HueUWP
|
||||
|
||||
private async void UpdateID_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
IDBox.Background = default(Brush);
|
||||
|
||||
UserIdProgress.IsActive = true;
|
||||
await api.Register();
|
||||
string s = await api.Register();
|
||||
if (s == "error")
|
||||
IDBox.Background = new SolidColorBrush(Colors.Red);
|
||||
else
|
||||
SettingsViewModel.Update();
|
||||
UserIdProgress.IsActive = false;
|
||||
SettingsViewModel.Update();
|
||||
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user