From f714f60d75e4926ed509a96e48e3a7657990f6b2 Mon Sep 17 00:00:00 2001 From: mallibone Date: Sun, 2 Sep 2018 16:29:53 +0200 Subject: [PATCH] Show correct unit in weather sample --- Ooui/UI.cs | 2 +- Samples/WeatherApp/Core.cs | 30 ++++++++++++++++++++++++-- Samples/WeatherApp/Weather.cs | 8 +++++-- Samples/WeatherApp/WeatherPage.xaml | 2 +- Samples/WeatherApp/WeatherPage.xaml.cs | 8 +++++-- 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/Ooui/UI.cs b/Ooui/UI.cs index d351b1f..50bf1a8 100644 --- a/Ooui/UI.cs +++ b/Ooui/UI.cs @@ -193,7 +193,7 @@ namespace Ooui public static string GetUrl (string path) { var localhost = host == "*" ? "localhost" : host; - var url = Path.Combine($"http://{localhost}:{port}{path}"); + var url = $"http://{localhost}:{port}{path}"; return url; } diff --git a/Samples/WeatherApp/Core.cs b/Samples/WeatherApp/Core.cs index 1d61701..be0ee02 100644 --- a/Samples/WeatherApp/Core.cs +++ b/Samples/WeatherApp/Core.cs @@ -16,11 +16,13 @@ namespace WeatherApp if (results["weather"] != null) { + string tempUnit = GetTempUnit(units); + string speedUnit = GetSpeedUnit(units); Weather weather = new Weather { Title = (string)results["name"], - Temperature = (string)results["main"]["temp"] + " F", - Wind = (string)results["wind"]["speed"] + " mph", + Temperature = (string)results["main"]["temp"] + tempUnit, + Wind = (string)results["wind"]["speed"] + speedUnit, Humidity = (string)results["main"]["humidity"] + " %", Visibility = (string)results["weather"][0]["main"] }; @@ -37,5 +39,29 @@ namespace WeatherApp return null; } } + + private static string GetSpeedUnit(string units) + { + switch (units) + { + case "imperial": + return " mph"; + default: + return " kph"; + } + } + + private static string GetTempUnit(string units) + { + switch (units) + { + case "metric": + return " °C"; + case "imperial": + return " °F"; + default: + return " °K"; + } + } } } diff --git a/Samples/WeatherApp/Weather.cs b/Samples/WeatherApp/Weather.cs index e6e30f4..a97b39f 100644 --- a/Samples/WeatherApp/Weather.cs +++ b/Samples/WeatherApp/Weather.cs @@ -1,4 +1,6 @@ -namespace WeatherApp +using System.Collections.Generic; + +namespace WeatherApp { public class Weather { @@ -9,6 +11,7 @@ public string Visibility { get; set; } public string Sunrise { get; set; } public string Sunset { get; set; } + public List UnitOfMeasures { get; set; } public Weather() { @@ -21,6 +24,7 @@ this.Visibility = " "; this.Sunrise = " "; this.Sunset = " "; + this.UnitOfMeasures = new List{"kelvin", "metric", "imperial"}; } } -} \ No newline at end of file +} diff --git a/Samples/WeatherApp/WeatherPage.xaml b/Samples/WeatherApp/WeatherPage.xaml index 5de42b2..e6cfe03 100644 --- a/Samples/WeatherApp/WeatherPage.xaml +++ b/Samples/WeatherApp/WeatherPage.xaml @@ -35,7 +35,7 @@