From: gu.martinm@gmail.com Date: Mon, 21 Jul 2014 01:13:11 +0000 (+0200) Subject: WeatherInformation: current weather page X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=4961aa71cc065d4280bbe7bef7a0a6b088f9b725;p=CSharpForFun%2F.git WeatherInformation: current weather page --- diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs index 9301865..a0fe39e 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs @@ -16,6 +16,7 @@ using WeatherInformation.Model.Services; using System.Threading.Tasks; using WeatherInformation.Model.ForecastWeatherParser; using WeatherInformation.Model.JsonDataParser; +using WeatherInformation.Model.CurrentWeatherParser; namespace WeatherInformation { @@ -154,10 +155,10 @@ namespace WeatherInformation { // This method loads the data from isolated storage, if it is available. string JSONRemoteForecastWeatherData = sr.ReadLine(); - // string remoteCurrentWeatherData = sr.ReadLine(); - var weatherData = WeatherParser(JSONRemoteForecastWeatherData, null); + string JSONRemoteCurrentWeatherData = sr.ReadLine(); + var weatherData = WeatherParser(JSONRemoteForecastWeatherData, JSONRemoteCurrentWeatherData); weatherData.JSONRemoteForecastWeatherData = JSONRemoteForecastWeatherData; - weatherData.JSONRemoteCurrentWeatherData = null; + weatherData.JSONRemoteCurrentWeatherData = JSONRemoteCurrentWeatherData; weatherData.WasThereRemoteError = false; ApplicationDataObject = weatherData; } @@ -205,21 +206,29 @@ namespace WeatherInformation (double)IsolatedStorageSettings.ApplicationSettings["CurrentLongitude"], resultsNumber); string JSONRemoteForecastWeatherData = await httpClient.GetWeatherDataAsync(formattedForecastURL); - var weatherData = WeatherParser(JSONRemoteForecastWeatherData, null); + string formattedCurrentURL = String.Format( + CultureInfo.InvariantCulture, AppResources.URIAPIOpenWeatherMapCurrent, + AppResources.APIVersionOpenWeatherMap, (double)IsolatedStorageSettings.ApplicationSettings["CurrentLatitude"], + (double)IsolatedStorageSettings.ApplicationSettings["CurrentLongitude"], resultsNumber); + string JSONRemoteCurrentWeatherData = await httpClient.GetWeatherDataAsync(formattedCurrentURL); + + var weatherData = WeatherParser(JSONRemoteForecastWeatherData, JSONRemoteCurrentWeatherData); weatherData.WasThereRemoteError = false; weatherData.JSONRemoteForecastWeatherData = JSONRemoteForecastWeatherData; - weatherData.JSONRemoteCurrentWeatherData = null; + weatherData.JSONRemoteCurrentWeatherData = JSONRemoteCurrentWeatherData; ApplicationDataObject = weatherData; } private WeatherData WeatherParser(string remoteForecastWeatherData, string remoteCurrentWeatherData) { - ForecastWeather weather = new ServiceParser(new JsonParser()).GetForecastWeather(remoteForecastWeatherData); + ServiceParser parser = new ServiceParser(new JsonParser()); + ForecastWeather remoteForecastWeather = parser.GetForecastWeather(remoteForecastWeatherData); + CurrentWeather remoteCurrentWeather = parser.GetCurrentWeather(remoteCurrentWeatherData); return new WeatherData { - RemoteForecastWeatherData = weather, - RemoteCurrentWeatherData = null + RemoteForecastWeatherData = remoteForecastWeather, + RemoteCurrentWeatherData = remoteCurrentWeather }; } @@ -236,6 +245,7 @@ namespace WeatherInformation using (StreamWriter sw = new StreamWriter(fileStream)) { sw.Write(value.JSONRemoteForecastWeatherData); + sw.Write(value.JSONRemoteCurrentWeatherData); fileStream.Flush(true); } @@ -422,8 +432,8 @@ namespace WeatherInformation // determine the locale. //if (Debugger.IsAttached && String.IsNullOrWhiteSpace(appForceCulture) == false) //{ - // Thread.CurrentThread.CurrentCulture = new CultureInfo(appForceCulture); - // Thread.CurrentThread.CurrentUICulture = new CultureInfo(appForceCulture); + Thread.CurrentThread.CurrentCulture = new CultureInfo(appForceCulture); + Thread.CurrentThread.CurrentUICulture = new CultureInfo(appForceCulture); //} // Establecer la fuente para que coincida con el idioma definido por diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml index 1d66b22..ce1185f 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml @@ -82,6 +82,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Coord.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Coord.cs index 21a07b8..cd1d487 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Coord.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Coord.cs @@ -5,7 +5,7 @@ namespace WeatherInformation.Model.CurrentWeatherParser public class Coord { public double lon { get; set; } - public int lat { get; set; } + public double lat { get; set; } } } diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/CurrentWeather.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/CurrentWeather.cs index 05d0c21..2302261 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/CurrentWeather.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/CurrentWeather.cs @@ -11,6 +11,7 @@ namespace WeatherInformation.Model.CurrentWeatherParser public string @base { get; set; } public Main main { get; set; } public Wind wind { get; set; } + public Snow snow { get; set; } public Rain rain { get; set; } public Clouds clouds { get; set; } public int dt { get; set; } diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Main.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Main.cs index 2840930..9caf9df 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Main.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Main.cs @@ -5,7 +5,7 @@ namespace WeatherInformation.Model.CurrentWeatherParser public class Main { public double temp { get; set; } - public int pressure { get; set; } + public double pressure { get; set; } public int humidity { get; set; } public double temp_min { get; set; } public double temp_max { get; set; } diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Snow.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Snow.cs new file mode 100644 index 0000000..94dc1a2 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Snow.cs @@ -0,0 +1,20 @@ +using System; + +namespace WeatherInformation.Model.CurrentWeatherParser +{ + public class Snow + { + private double threeHours; + + public void set3h(double three) + { + this.threeHours = three; + } + + public double get3h() + { + return this.threeHours; + } + } +} + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Wind.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Wind.cs index 6668990..67cf441 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Wind.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Wind.cs @@ -5,7 +5,7 @@ namespace WeatherInformation.Model.CurrentWeatherParser public class Wind { public double speed { get; set; } - public int deg { get; set; } + public double deg { get; set; } } } diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs index 40ca9f1..9118bb7 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs @@ -133,6 +133,33 @@ namespace WeatherInformation.Resources { } /// + /// Busca una cadena traducida similar a CLOUDS. + /// + public static string MainPageCurrentClouds { + get { + return ResourceManager.GetString("MainPageCurrentClouds", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a %. + /// + public static string MainPageCurrentCloudsUnits { + get { + return ResourceManager.GetString("MainPageCurrentCloudsUnits", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a FEELS LIKE. + /// + public static string MainPageCurrentFeelsLike { + get { + return ResourceManager.GetString("MainPageCurrentFeelsLike", resourceCulture); + } + } + + /// /// Busca una cadena traducida similar a current. /// public static string MainPageCurrentHeader { @@ -142,6 +169,114 @@ namespace WeatherInformation.Resources { } /// + /// Busca una cadena traducida similar a HUMIDITY. + /// + public static string MainPageCurrentHumidity { + get { + return ResourceManager.GetString("MainPageCurrentHumidity", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a %. + /// + public static string MainPageCurrentHumidityUnits { + get { + return ResourceManager.GetString("MainPageCurrentHumidityUnits", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a PRESSURE. + /// + public static string MainPageCurrentPressure { + get { + return ResourceManager.GetString("MainPageCurrentPressure", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a hpa. + /// + public static string MainPageCurrentPressureUnits { + get { + return ResourceManager.GetString("MainPageCurrentPressureUnits", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a RAIN. + /// + public static string MainPageCurrentRain { + get { + return ResourceManager.GetString("MainPageCurrentRain", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a mm 3h. + /// + public static string MainPageCurrentRainUnits { + get { + return ResourceManager.GetString("MainPageCurrentRainUnits", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a SNOW. + /// + public static string MainPageCurrentSnow { + get { + return ResourceManager.GetString("MainPageCurrentSnow", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a mm 3h. + /// + public static string MainPageCurrentSnowUnits { + get { + return ResourceManager.GetString("MainPageCurrentSnowUnits", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a SUN RISE. + /// + public static string MainPageCurrentSunRise { + get { + return ResourceManager.GetString("MainPageCurrentSunRise", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a SUN SET. + /// + public static string MainPageCurrentSunSet { + get { + return ResourceManager.GetString("MainPageCurrentSunSet", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a WIND. + /// + public static string MainPageCurrentWind { + get { + return ResourceManager.GetString("MainPageCurrentWind", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a m/s. + /// + public static string MainPageCurrentWindUnits { + get { + return ResourceManager.GetString("MainPageCurrentWindUnits", resourceCulture); + } + } + + /// /// Busca una cadena traducida similar a forecast. /// public static string MainPageForecastHeader { @@ -313,6 +448,15 @@ namespace WeatherInformation.Resources { } /// + /// Busca una cadena traducida similar a http://api.openweathermap.org/data/{0}/weather?lat={1}&lon={2}&cnt=1. + /// + public static string URIAPIOpenWeatherMapCurrent { + get { + return ResourceManager.GetString("URIAPIOpenWeatherMapCurrent", resourceCulture); + } + } + + /// /// Busca una cadena traducida similar a http://api.openweathermap.org/data/{0}/forecast/daily?lat={1}&lon={2}&cnt={3}&mode=json. /// public static string URIAPIOpenWeatherMapForecast { diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx index 761e583..87c9de6 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx @@ -125,13 +125,120 @@ es Controls the Language and ensures that the font for all elements in the RootFrame aligns with the app's language. Set to the language code of this resource file's language. - - - - - - - - - -MI APLICACIÓNagregarElemento de menúIdiomaText in settings page as headerUnidades de temperaturaText in settings pageinglésSettings page, select English languageespañolSettings page, select Spanish languagecelsiusSettings page, select tempereature units centigradefahrenheitSettings page, select temperature units fahrenheitLocalizaciónAsk for location consent in map windowNo hay localizaciones almacenadas.Main window, notice message, no available locationsDetección automática de la ubicación parece ser desactivado en el teléfonoMap window, notice message, error while location autodetectionPrevision, numero díasText in settings page as headerPrevisión 10 díasSettings page, select forecast day numbersPrevisión 14 díasSettings page, select forecast day numbersPrevisión 5 díasSettings page, select forecast day numbersº FCiudad, paísSubtitle in location pageSelecciona tu localizaciónTitle in location pageprevisiónForecast header in main pageconfiguración deHeader settings in settings pageactualCurrent header in main pageº CEsta aplicación accede a los datos de tu localización. ¿Estás de acuerdo?Ask for location consent in map windowCiudad, paísTitle in main page \ No newline at end of file + + MI APLICACIÓN + + + agregar + + + Elemento de menú + + + Idioma + Text in settings page as header + + + Unidades de temperatura + Text in settings page + + + inglés + Settings page, select English language + + + español + Settings page, select Spanish language + + + celsius + Settings page, select tempereature units centigrade + + + fahrenheit + Settings page, select temperature units fahrenheit + + + Localización + Ask for location consent in map window + + + No hay localizaciones almacenadas. + Main window, notice message, no available locations + + + Detección automática de la ubicación parece estar desactivada en el teléfono + Map window, notice message, error while location autodetection + + + Prevision, numero días + Text in settings page as header + + + Previsión 10 días + Settings page, select forecast day numbers + + + Previsión 14 días + Settings page, select forecast day numbers + + + Previsión 5 días + Settings page, select forecast day numbers + + + Ciudad, país + Subtitle in location page + + + Selecciona tu localización + Title in location page + + + previsión + Forecast header in main page + + + configuración de + Header settings in settings page + + + actual + Current header in main page + + + Esta aplicación accede a los datos de tu localización. ¿Estás de acuerdo? + Ask for location consent in map window + + + Ciudad, país + Title in main page + + + VIENTO + + + SOL SE PONE + + + SOL SALE + + + NIEVE + + + LLUVIA + + + PRESIÓN + + + HUMEDAD + + + NUBES + + + SIENTE COMO + + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf index f9e7910..8ac4022 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf @@ -2,7 +2,7 @@
- +
@@ -70,7 +70,7 @@ Location autodetection seems to be disabled in your phone - Detección automática de la ubicación parece ser desactivado en el teléfono + Detección automática de la ubicación parece estar desactivada en el teléfono Map window, notice message, error while location autodetection @@ -93,9 +93,9 @@ Previsión 5 días Settings page, select forecast day numbers - + ºF - º F + º F City, country @@ -122,12 +122,80 @@ Ciudad, país Title in main page + + WIND + VIENTO + + + http://api.openweathermap.org/data/{0}/weather?lat={1}%%amp;lon={2}%%amp;cnt=1 + http://api.openweathermap.org/data/{0}/weather?lat={1}%%amp;lon={2}%%amp;cnt=1 + Not to be translated + + + m/s + m/s + + + hpa + hpa + Not to be translated. + + + mm 3h + mm 3h + + + mm 3h + mm 3h + + + % + % + Not to be translated. + + + % + % + Not to be translated. + + + SUN SET + SOL SE PONE + + + SUN RISE + SOL SALE + + + SNOW + NIEVE + + + RAIN + LLUVIA + + + PRESSURE + PRESIÓN + + + HUMIDITY + HUMEDAD + + + FEELS LIKE + SIENTE COMO + + + CLOUDS + NUBES + current actual Current header in main page - + ºC º C diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf index d3e7ea3..1aa0c42 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf @@ -2,7 +2,7 @@
- +
@@ -107,6 +107,74 @@ City, country Title in main page
+ + WIND + WIND + + + http://api.openweathermap.org/data/{0}/weather?lat={1}%%amp;lon={2}%%amp;cnt=1 + http://api.openweathermap.org/data/{0}/weather?lat={1}%%amp;lon={2}%%amp;cnt=1 + Not to be translated + + + m/s + m/s + + + hpa + hpa + Not to be translated. + + + mm 3h + mm 3h + + + mm 3h + mm 3h + + + % + % + Not to be translated. + + + % + % + Not to be translated. + + + SUN SET + SUN SET + + + SUN RISE + SUN RISE + + + SNOW + SNOW + + + RAIN + RAIN + + + PRESSURE + PRESSURE + + + HUMIDITY + HUMIDITY + + + FEELS LIKE + FEELS LIKE + + + CLOUDS + CLOUDS + current current diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx index 0ab3453..62525d9 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx @@ -228,4 +228,56 @@ City, country Title in main page + + CLOUDS + + + FEELS LIKE + + + HUMIDITY + + + PRESSURE + + + RAIN + + + SNOW + + + SUN RISE + + + SUN SET + + + WIND + + + http://api.openweathermap.org/data/{0}/weather?lat={1}&lon={2}&cnt=1 + Not to be translated + + + % + Not to be translated. + + + % + Not to be translated. + + + mm 3h + + + mm 3h + + + m/s + + + hpa + Not to be translated. + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml index f284267..99d2581 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml @@ -1,7 +1,28 @@  + xmlns:vm="clr-namespace:WeatherInformation.ViewModels" + CurrentMaxTemp="25" + CurrentMaxTempUnits="ºC" + CurrentMinTemp="15" + CurrentFeelsLikeTemp="20" + CurrentPressure="1015" + CurrentRain="10" + CurrentSnow="10" + CurrentSunRise="2014.07.19 07:01:54" + CurrentSunSet="2014.07.19 21:41:40" + CurrentWind="1.03" + CurrentConditions="Sky is Clear" + CurrentClouds="10" + CurrentHumidity="50" + CurrentMinTempUnits="ºC" + CurrentPressureUnits="hpa" + CurrentRainUnits="mm 3h" + CurrentSnowUnits="mm 3h" + CurrentWindUnits="m/s" + CurrentHumidityUnits="%" + CurrentFeelsLikeTempUnits="ºC" + CurrentCloudsUnits="%"> @@ -20,5 +41,6 @@ + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs index 265e2e4..bd0550e 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs @@ -13,7 +13,7 @@ using WeatherInformation.Resources; namespace WeatherInformation.ViewModels { - public class MainViewModel + public class MainViewModel : INotifyPropertyChanged { // The key names of _settings // TODO: reuse settings object instead of using the same code here again... @@ -44,7 +44,27 @@ namespace WeatherInformation.ViewModels /// public ObservableCollection ForecastItems{ get; private set; } public ObservableCollection CurrentItems { get; private set; } - + public String CurrentMaxTemp { get; set; } + public String CurrentMaxTempUnits { get; set; } + public String CurrentMinTemp { get; private set; } + public String CurrentMinTempUnits { get; set; } + public String CurrentConditions { get; private set; } + public String CurrentFeelsLikeTemp { get; private set; } + public String CurrentFeelsLikeTempUnits { get; set; } + public String CurrentHumidity { get; private set; } + public String CurrentHumidityUnits { get; private set; } + public String CurrentRain { get; private set; } + public String CurrentRainUnits { get; private set; } + public String CurrentSnow { get; private set; } + public String CurrentSnowUnits { get; private set; } + public String CurrentWind { get; private set; } + public String CurrentWindUnits { get; private set; } + public String CurrentClouds { get; private set; } + public String CurrentCloudsUnits { get; private set; } + public String CurrentPressure { get; private set; } + public String CurrentPressureUnits { get; private set; } + public String CurrentSunRise { get; private set; } + public String CurrentSunSet { get; private set; } /// /// Crear y agregar unos pocos objetos ItemViewModel a la colección Items. @@ -84,9 +104,9 @@ namespace WeatherInformation.ViewModels var remoteForecastWeatherData = weatherData.RemoteForecastWeatherData; this.ForecastItems.Clear(); + DateTime unixTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); foreach (WeatherInformation.Model.ForecastWeatherParser.List item in remoteForecastWeatherData.list) { - DateTime unixTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); DateTime date = unixTime.AddSeconds(item.dt).ToLocalTime(); // TODO: if I do not receive max temp or min temp... Am I going to receive item.temp.max=0 or item.temp.min=0 (I guess because @@ -114,6 +134,122 @@ namespace WeatherInformation.ViewModels break; } } + + // TODO: nullables? + + var remoteCurrentWeatherData = weatherData.RemoteCurrentWeatherData; + + var currentMaxTemp = ""; + if (remoteCurrentWeatherData.main != null) + { + var conversion = remoteCurrentWeatherData.main.temp_max; + conversion -= tempUnits; + currentMaxTemp = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", conversion); + } + this.CurrentMaxTemp = currentMaxTemp; + this.CurrentMaxTempUnits = symbol; + NotifyPropertyChanged("CurrentMaxTemp"); + NotifyPropertyChanged("CurrentMaxTempUnits"); + + var currentMinTemp = ""; + if (remoteCurrentWeatherData.main != null) + { + var conversion = remoteCurrentWeatherData.main.temp_min; + conversion -= tempUnits; + currentMinTemp = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", conversion); + } + this.CurrentMinTemp = currentMinTemp; + this.CurrentMinTempUnits = symbol; + NotifyPropertyChanged("CurrentMinTemp"); + NotifyPropertyChanged("CurrentMinTempUnits"); + + var currentConditions = "no description available"; + if (remoteCurrentWeatherData.weather.Count > 0) + { + currentConditions = remoteCurrentWeatherData.weather[0].description; + } + this.CurrentConditions = currentConditions; + NotifyPropertyChanged("CurrentConditions"); + + var currentFeelsLikeTemp = ""; + if (remoteCurrentWeatherData.main != null) + { + var conversion = remoteCurrentWeatherData.main.temp; + conversion -= tempUnits; + currentFeelsLikeTemp = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", conversion); + } + this.CurrentFeelsLikeTemp = currentFeelsLikeTemp; + this.CurrentFeelsLikeTempUnits = symbol; + NotifyPropertyChanged("CurrentFeelsLikeTemp"); + NotifyPropertyChanged("CurrentFeelsLikeTempUnits"); + + var currentHumidity = ""; + if (remoteCurrentWeatherData.main != null) + { + currentHumidity = remoteCurrentWeatherData.main.humidity.ToString(CultureInfo.InvariantCulture); + } + this.CurrentHumidity = currentHumidity; + this.CurrentHumidityUnits = AppResources.MainPageCurrentHumidityUnits; + NotifyPropertyChanged("CurrentHumidity"); + NotifyPropertyChanged("CurrentHumidityUnits"); + + var currentRain = ""; + if (remoteCurrentWeatherData.rain != null) + { + currentRain = remoteCurrentWeatherData.rain.get3h().ToString(CultureInfo.InvariantCulture); + } + this.CurrentRain = currentRain; + this.CurrentRainUnits = AppResources.MainPageCurrentRainUnits; + NotifyPropertyChanged("CurrentRain"); + NotifyPropertyChanged("CurrentRainUnits"); + + var currentSnow = ""; + if (remoteCurrentWeatherData.snow != null) + { + currentSnow = remoteCurrentWeatherData.snow.get3h().ToString(CultureInfo.InvariantCulture); + } + this.CurrentSnow = currentSnow; + this.CurrentSnowUnits = AppResources.MainPageCurrentSnowUnits; + NotifyPropertyChanged("CurrentSnow"); + NotifyPropertyChanged("CurrentSnowUnits"); + + var currentWind = ""; + if (remoteCurrentWeatherData.wind != null) + { + currentWind = remoteCurrentWeatherData.wind.speed.ToString(CultureInfo.InvariantCulture); + } + this.CurrentWind = currentWind; + this.CurrentWindUnits = AppResources.MainPageCurrentWindUnits; + NotifyPropertyChanged("CurrentWind"); + NotifyPropertyChanged("CurrentWindUnits"); + + var currentClouds = ""; + if (remoteCurrentWeatherData.clouds != null) + { + currentClouds = remoteCurrentWeatherData.clouds.all.ToString(CultureInfo.InvariantCulture); + } + this.CurrentClouds = currentClouds; + this.CurrentCloudsUnits = AppResources.MainPageCurrentCloudsUnits; + NotifyPropertyChanged("CurrentClouds"); + NotifyPropertyChanged("CurrentCloudsUnits"); + + var currentPressure = ""; + if (remoteCurrentWeatherData.main != null) + { + currentPressure = remoteCurrentWeatherData.main.pressure.ToString(CultureInfo.InvariantCulture); + } + this.CurrentPressure = currentPressure; + this.CurrentPressureUnits = AppResources.MainPageCurrentPressureUnits; + NotifyPropertyChanged("CurrentPressure"); + NotifyPropertyChanged("CurrentPressureUnits"); + + var sunRiseTime = unixTime.AddSeconds(remoteCurrentWeatherData.sys.sunrise).ToLocalTime(); + this.CurrentSunRise = sunRiseTime.ToString("MM/dd/yy H:mm:ss", CultureInfo.InvariantCulture); + NotifyPropertyChanged("CurrentSunRise"); + + var sunSetTime = unixTime.AddSeconds(remoteCurrentWeatherData.sys.sunset).ToLocalTime(); + this.CurrentSunSet = sunSetTime.ToString("MM/dd/yy H:mm:ss", CultureInfo.InvariantCulture); + NotifyPropertyChanged("CurrentSunSet"); } public bool IsThereCurrentLocation() @@ -158,5 +294,15 @@ namespace WeatherInformation.ViewModels } return value; } + + public event PropertyChangedEventHandler PropertyChanged; + private void NotifyPropertyChanged(String propertyName) + { + PropertyChangedEventHandler handler = PropertyChanged; + if (null != handler) + { + handler(this, new PropertyChangedEventArgs(propertyName)); + } + } } } \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj b/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj index e0795ba..53220e0 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj +++ b/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj @@ -107,6 +107,7 @@ +