WeatherInformation WP8: using nullable types
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Sun, 17 Aug 2014 20:58:54 +0000 (22:58 +0200)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Sun, 17 Aug 2014 20:58:54 +0000 (22:58 +0200)
I do not trust data coming from remote API.

22 files changed:
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Clouds.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Coord.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/CurrentWeather.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Main.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Rain.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Snow.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Sys.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Weather.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Model/CurrentWeatherParser/Wind.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/City.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/Coord.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/ForecastWeather.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/List.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/Temp.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Model/ForecastWeatherParser/Weather.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf
WindowsPhone/WP8/WeatherInformation/WeatherInformation/Resources/AppResources.resx
WindowsPhone/WP8/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs
WindowsPhone/WP8/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs

index d3e9557..d87c7b4 100644 (file)
@@ -3,7 +3,7 @@ namespace WeatherInformation.Model.CurrentWeatherParser
 {
     public class Clouds
     {
-        public int all { get; set; }
+        public double? all { get; set; }
     }
 }
 
index 78aeee3..947cb13 100644 (file)
@@ -3,8 +3,8 @@ namespace WeatherInformation.Model.CurrentWeatherParser
 {
     public class Coord
     {
-        public double lon { get; set; }
-        public double lat { get; set; }
+        public double? lon { get; set; }
+        public double? lat { get; set; }
     }
 }
 
index d2e1479..f3f9371 100644 (file)
@@ -13,10 +13,10 @@ namespace WeatherInformation.Model.CurrentWeatherParser
         public Snow snow { get; set; }
         public Rain rain { get; set; }
         public Clouds clouds { get; set; }
-        public int dt { get; set; }
-        public int id { get; set; }
+        public long? dt { get; set; }
+        public long? id { get; set; }
         public string name { get; set; }
-        public int cod { get; set; }
+        public long? cod { get; set; }
     }
 }
 
index 78ad137..a77b9fe 100644 (file)
@@ -3,11 +3,11 @@ namespace WeatherInformation.Model.CurrentWeatherParser
 {
     public class Main
     {
-        public double temp { get; set; }
-        public double pressure { get; set; }
-        public int humidity { get; set; }
-        public double temp_min { get; set; }
-        public double temp_max { get; set; }
+        public double? temp { get; set; }
+        public double? pressure { get; set; }
+        public double? humidity { get; set; }
+        public double? temp_min { get; set; }
+        public double? temp_max { get; set; }
     }
 }
 
index ec9b570..e69fc71 100644 (file)
@@ -3,14 +3,14 @@ namespace WeatherInformation.Model.CurrentWeatherParser
 {
     public class Rain
     {
-        private double threeHours;
+        private double? threeHours;
 
         public void set3h(double three)
         {
             this.threeHours = three;
         }
 
-        public double get3h()
+        public double? get3h()
         {
             return this.threeHours;
         }
index 01108fb..dc88c24 100644 (file)
@@ -3,14 +3,14 @@ namespace WeatherInformation.Model.CurrentWeatherParser
 {
     public class Snow
     {
-        private double threeHours;
+        private double? threeHours;
 
         public void set3h(double three)
         {
             this.threeHours = three;
         }
 
-        public double get3h()
+        public double? get3h()
         {
             return this.threeHours;
         }
index b707f46..910df3b 100644 (file)
@@ -3,10 +3,10 @@ namespace WeatherInformation.Model.CurrentWeatherParser
 {
     public class Sys
     {
-        public double message { get; set; }
+        public double? message { get; set; }
         public string country { get; set; }
-        public int sunrise { get; set; }
-        public int sunset { get; set; }
+        public long? sunrise { get; set; }
+        public long? sunset { get; set; }
     }
 }
 
index 281d68a..7d22d00 100644 (file)
@@ -3,7 +3,7 @@ namespace WeatherInformation.Model.CurrentWeatherParser
 {
     public class Weather
     {
-        public int id { get; set; }
+        public long? id { get; set; }
         public string main { get; set; }
         public string description { get; set; }
         public string icon { get; set; }
index a48b82c..255e512 100644 (file)
@@ -3,8 +3,8 @@ namespace WeatherInformation.Model.CurrentWeatherParser
 {
     public class Wind
     {
-        public double speed { get; set; }
-        public double deg { get; set; }
+        public double? speed { get; set; }
+        public double? deg { get; set; }
     }
 }
 
index 519ee00..391450c 100644 (file)
@@ -3,11 +3,11 @@ namespace WeatherInformation.Model.ForecastWeatherParser
 {
     public class City
     {
-        public int id { get; set; }
+        public double? id { get; set; }
         public string name { get; set; }
         public Coord coord { get; set; }
         public string country { get; set; }
-        public int population { get; set; }
+        public double? population { get; set; }
     }
 }
 
index d5556ac..e416d66 100644 (file)
@@ -3,8 +3,8 @@ namespace WeatherInformation.Model.ForecastWeatherParser
 {
     public class Coord
     {
-        public double lon { get; set; }
-        public double lat { get; set; }
+        public double? lon { get; set; }
+        public double? lat { get; set; }
     }
 }
 
index 0395b3f..66bc6c7 100644 (file)
@@ -5,9 +5,9 @@ namespace WeatherInformation.Model.ForecastWeatherParser
     public class ForecastWeather
     {
         public string cod { get; set; }
-        public double message { get; set; }
+        public double? message { get; set; }
         public City city { get; set; }
-        public int cnt { get; set; }
+        public int? cnt { get; set; }
         public List<WeatherInformation.Model.ForecastWeatherParser.List> list { get; set; }
     }
 }
index c57e3c7..1fdc460 100644 (file)
@@ -4,15 +4,15 @@ namespace WeatherInformation.Model.ForecastWeatherParser
 {
     public class List
     {
-        public int dt { get; set; }
+        public long? dt { get; set; }
         public Temp temp { get; set; }
-        public double pressure { get; set; }
-        public int humidity { get; set; }
+        public double? pressure { get; set; }
+        public double? humidity { get; set; }
         public List<Weather> weather { get; set; }
-        public double speed { get; set; }
-        public int deg { get; set; }
-        public int clouds { get; set; }
-        public double rain { get; set; }
+        public double? speed { get; set; }
+        public double? deg { get; set; }
+        public double? clouds { get; set; }
+        public double? rain { get; set; }
     }
 }
 
index 6c1eac5..c5b2531 100644 (file)
@@ -3,12 +3,12 @@ namespace WeatherInformation.Model.ForecastWeatherParser
 {
     public class Temp
     {
-        public double day { get; set; }
-        public double min { get; set; }
-        public double max { get; set; }
-        public double night { get; set; }
-        public double eve { get; set; }
-        public double morn { get; set; }
+        public double? day { get; set; }
+        public double? min { get; set; }
+        public double? max { get; set; }
+        public double? night { get; set; }
+        public double? eve { get; set; }
+        public double? morn { get; set; }
     }
 }
 
index fbca69b..4215320 100644 (file)
@@ -3,7 +3,7 @@ namespace WeatherInformation.Model.ForecastWeatherParser
 {
     public class Weather
     {
-        public int id { get; set; }
+        public long? id { get; set; }
         public string main { get; set; }
         public string description { get; set; }
         public string icon { get; set; }
index 35806cd..e87e4bb 100644 (file)
@@ -160,6 +160,15 @@ namespace WeatherInformation.Resources {
         }
         
         /// <summary>
+        ///   Busca una cadena traducida similar a no description available.
+        /// </summary>
+        public static string MainPageCurrentDefaultDescription {
+            get {
+                return ResourceManager.GetString("MainPageCurrentDefaultDescription", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Busca una cadena traducida similar a FEELS LIKE.
         /// </summary>
         public static string MainPageCurrentFeelsLike {
@@ -367,6 +376,15 @@ namespace WeatherInformation.Resources {
         }
         
         /// <summary>
+        ///   Busca una cadena traducida similar a no description available.
+        /// </summary>
+        public static string SelectedDatePageDefaultDescription {
+            get {
+                return ResourceManager.GetString("SelectedDatePageDefaultDescription", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Busca una cadena traducida similar a EVENING.
         /// </summary>
         public static string SelectedDatePageEvening {
index 64e05c9..4691c53 100644 (file)
     <value>Ciudad no encontrada</value>
     <comment>City, default value.</comment>
   </data>
+  <data name="MainPageCurrentDefaultDescription" xml:space="preserve">
+    <value>descripción no disponible</value>
+  </data>
+  <data name="SelectedDatePageDefaultDescription" xml:space="preserve">
+    <value>descripción no disponible</value>
+  </data>
 </root>
\ No newline at end of file
index 5ca1bae..73d1ca4 100644 (file)
           <target state="translated">País no encontrado</target>
           <note from="MultilingualBuild" annotates="source" priority="2">Country, default value.</note>
           </trans-unit>
+        <trans-unit id="Resx/MainPageCurrentDefaultDescription" translate="yes" xml:space="preserve">
+          <source>no description available</source>
+          <target state="translated">descripción no disponible</target>
+        </trans-unit>
+        <trans-unit id="Resx/SelectedDatePageDefaultDescription" translate="yes" xml:space="preserve">
+          <source>no description available</source>
+          <target state="translated">descripción no disponible</target>
+        </trans-unit>
         <trans-unit id="Resx/DefaultCity" translate="yes" xml:space="preserve">
           <source>City not found</source>
           <target state="translated">Ciudad no encontrada</target>
index d40fbf3..235ed58 100644 (file)
           <target state="new">Country not found</target>
           <note from="MultilingualBuild" annotates="source" priority="2">Country, default value.</note>
         </trans-unit>
+        <trans-unit id="Resx/MainPageCurrentDefaultDescription" translate="yes" xml:space="preserve">
+          <source>no description available</source>
+          <target state="new">no description available</target>
+        </trans-unit>
+        <trans-unit id="Resx/SelectedDatePageDefaultDescription" translate="yes" xml:space="preserve">
+          <source>no description available</source>
+          <target state="new">no description available</target>
+        </trans-unit>
         <trans-unit id="Resx/DefaultCity" translate="yes" xml:space="preserve">
           <source>City not found</source>
           <target state="new">City not found</target>
index 232519c..f5959fe 100644 (file)
     <value>Country not found</value>
     <comment>Country, default value.</comment>
   </data>
+  <data name="MainPageCurrentDefaultDescription" xml:space="preserve">
+    <value>no description available</value>
+  </data>
+  <data name="SelectedDatePageDefaultDescription" xml:space="preserve">
+    <value>no description available</value>
+  </data>
 </root>
\ No newline at end of file
index 09735b3..4510f86 100644 (file)
@@ -3,6 +3,8 @@ using System.Collections.ObjectModel;
 using System.ComponentModel;
 using System.Globalization;
 using WeatherInformation.Model;
+using WeatherInformation.Model.CurrentWeatherParser;
+using WeatherInformation.Model.ForecastWeatherParser;
 using WeatherInformation.Model.Images;
 using WeatherInformation.Resources;
 
@@ -60,23 +62,52 @@ namespace WeatherInformation.ViewModels
         public String CurrentSunSet { get; private set; }
 
         /// <summary>
-        /// Crear y agregar unos pocos objetos ItemViewModel a la colección Items.
+        /// Update UI
         /// </summary>
         public void LoadData(WeatherData weatherData)
         {
             // TODO: there must be a better way than using the index value :(
+            bool isFahrenheit = true;
+            int temperatureUnitsSelection = _settings.TemperaruteUnitsSelectionSetting;
+            if (temperatureUnitsSelection != 0)
+            {
+                isFahrenheit = false;
+            }
+            double tempUnits = isFahrenheit ? 0 : 273.15;
+            string symbol = isFahrenheit ? AppResources.TemperatureUnitsFahrenheitSymbol : AppResources.TemperatureUnitsCentigradeSymbol;
+            DateTime baseUnixTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+
+            string country = weatherData.Country;
+            string city = weatherData.City;
+            string cityCountry = String.Format(CultureInfo.InvariantCulture, "{0}, {1}", city, country);
+            this.TitleTextCityCountry = cityCountry;
+            NotifyPropertyChanged("TitleTextCityCountry");
+
+            if (weatherData.Forecast != null)
+            {
+                UpdateForecastUI(weatherData.Forecast, baseUnixTime, symbol, tempUnits);
+            }
+
+            if (weatherData.Current != null)
+            {
+                UpdateCurrentUI(weatherData.Current, baseUnixTime, symbol, tempUnits);
+            }
+        }
 
-            int forecastDayNumbers = _settings.ForecastDayNumbersSelectionSetting;     
+        private void UpdateForecastUI(ForecastWeather forecast, DateTime baseUnixTime, string symbol, double tempUnits)
+        {
+            // TODO: there must be a better way than using the index value :(
+            int forecastDayNumbers = _settings.ForecastDayNumbersSelectionSetting;
             int count;
-            switch(forecastDayNumbers)
+            switch (forecastDayNumbers)
             {
-                case(0):
+                case (0):
                     count = 5;
                     break;
-                case(1):
+                case (1):
                     count = 10;
                     break;
-                case(2):
+                case (2):
                     count = 14;
                     break;
                 default:
@@ -84,224 +115,220 @@ namespace WeatherInformation.ViewModels
                     break;
             }
 
-            // TODO: there must be a better way than using the index value :(
-            bool isFahrenheit = true;
-            int temperatureUnitsSelection = _settings.TemperaruteUnitsSelectionSetting;
-            if (temperatureUnitsSelection != 0)
-            {
-                isFahrenheit = false;
-            }
-            double tempUnits = isFahrenheit ? 0 : 273.15;
-            string symbol = isFahrenheit ? AppResources.TemperatureUnitsFahrenheitSymbol : AppResources.TemperatureUnitsCentigradeSymbol;
-            DateTime unixTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+            this.ForecastItems.Clear();
 
-            var remoteForecastWeatherData = weatherData.Forecast;
-            if (remoteForecastWeatherData != null)
+            foreach (WeatherInformation.Model.ForecastWeatherParser.List item in forecast.list)
             {
-                this.ForecastItems.Clear();
-                
-                foreach (WeatherInformation.Model.ForecastWeatherParser.List item in remoteForecastWeatherData.list)
+                var lineOne = "";
+                var lineTwo = "";
+                if (item.dt != null)
                 {
-                    DateTime date = unixTime.AddSeconds(item.dt);
+                    var date = baseUnixTime.AddSeconds(item.dt.Value);
+                    lineOne = date.ToString("ddd", CultureInfo.InvariantCulture);
+                    lineTwo = date.ToString("dd", CultureInfo.InvariantCulture);
+                }
 
-                    // 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
-                    // double has no null value)
-                    // I need something that is not 0 value in order to find out if OpenWeatherMap sent me values or not :/
-                    // I guess; I am going to need nullable but I will have to modify my Json Parser :(
-                    double maxTemp = item.temp.max;
+                string lineThree = symbol;
+                if (item.temp.max != null)
+                {
+                    var maxTemp = item.temp.max;
                     maxTemp = maxTemp - tempUnits;
+                    lineThree = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", maxTemp) + symbol;
+                }
 
-                    double minTemp = item.temp.min;
+                string lineFour = symbol;
+                if (item.temp.min != null)
+                {
+                    var minTemp = item.temp.min;
                     minTemp = minTemp - tempUnits;
-
-                    string weatherImage;
-                    if (item.weather.Count > 0 &&
-                        item.weather[0].icon != null &&
-                        RemoteImagesTranslation.GetTransaltedImage(item.weather[0].icon) != null)
-                    {
-                        weatherImage = RemoteImagesTranslation.GetTransaltedImage(item.weather[0].icon);
-                    }
-                    else
-                    {
-                        weatherImage = "weather_severe_alert";
-                    }
-                    string weatherImagePath = String.Format(CultureInfo.InvariantCulture, "/Images/{0}.png", weatherImage);
-
-                    this.ForecastItems.Add(new ItemViewModel()
-                    {
-                        LineOne = date.ToString("ddd", CultureInfo.InvariantCulture),
-                        LineTwo = date.ToString("dd", CultureInfo.InvariantCulture),
-                        LineThree = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", maxTemp) + symbol,
-                        LineFour = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", minTemp) + symbol,
-                        LineFive = weatherImagePath
-                    });
-
-                    count--;
-                    if (count == 0)
-                    {
-                        break;
-                    }
+                    lineFour = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", minTemp) + symbol;
                 }
-            }
-
-            // TODO: nullables?
-            // TODO: nullables para distinguir cuando hay datos o no. Ahora me llega 0 si no datos (supongo) cuando double/integer
 
-            var remoteCurrentWeatherData = weatherData.Current;
-            if (remoteCurrentWeatherData != null)
-            {
-                string weatherImage;
-                if (remoteCurrentWeatherData.weather.Count > 0 &&
-                    remoteCurrentWeatherData.weather[0].icon != null &&
-                    RemoteImagesTranslation.GetTransaltedImage(remoteCurrentWeatherData.weather[0].icon) != null)
+                string lineFive;
+                if (item.weather.Count > 0 &&
+                    item.weather[0].icon != null &&
+                    RemoteImagesTranslation.GetTransaltedImage(item.weather[0].icon) != null)
                 {
-                    weatherImage = RemoteImagesTranslation.GetTransaltedImage(remoteCurrentWeatherData.weather[0].icon);
+                    lineFive = RemoteImagesTranslation.GetTransaltedImage(item.weather[0].icon);
                 }
                 else
                 {
-                    weatherImage = "weather_severe_alert";
+                    lineFive = "weather_severe_alert";
                 }
-                this.CurrentWeatherImagePath = String.Format(CultureInfo.InvariantCulture, "/Images/{0}.png", weatherImage);
-                NotifyPropertyChanged("CurrentWeatherImagePath");
 
-                var currentMaxTemp = "";
-                if (remoteCurrentWeatherData.main != null)
+                this.ForecastItems.Add(new ItemViewModel()
                 {
-                    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");
+                    LineOne = lineOne,
+                    LineTwo = lineTwo,
+                    LineThree = lineThree,
+                    LineFour = lineFour,
+                    LineFive = String.Format(CultureInfo.InvariantCulture, "/Images/{0}.png", lineFive),
+                });
 
-                var currentMinTemp = "";
-                if (remoteCurrentWeatherData.main != null)
+                count--;
+                if (count == 0)
                 {
-                    var conversion = remoteCurrentWeatherData.main.temp_min;
-                    conversion -= tempUnits;
-                    currentMinTemp = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", conversion);
+                    break;
                 }
-                this.CurrentMinTemp = currentMinTemp;
-                this.CurrentMinTempUnits = symbol;
-                NotifyPropertyChanged("CurrentMinTemp");
-                NotifyPropertyChanged("CurrentMinTempUnits");
+            }
+        }
 
-                // TODO: static resource :(
-                var currentConditions = "no description available";
-                if (remoteCurrentWeatherData.weather.Count > 0)
-                {
-                    currentConditions = remoteCurrentWeatherData.weather[0].description;
-                }
-                this.CurrentConditions = currentConditions;
-                NotifyPropertyChanged("CurrentConditions");
+        private void UpdateCurrentUI(CurrentWeather current, DateTime baseUnixTime, string symbol, double tempUnits)
+        {
+            string weatherImage;
+            if (current.weather.Count > 0 &&
+                current.weather[0].icon != null &&
+                RemoteImagesTranslation.GetTransaltedImage(current.weather[0].icon) != null)
+            {
+                weatherImage = RemoteImagesTranslation.GetTransaltedImage(current.weather[0].icon);
+            }
+            else
+            {
+                weatherImage = "weather_severe_alert";
+            }
+            this.CurrentWeatherImagePath = String.Format(CultureInfo.InvariantCulture, "/Images/{0}.png", weatherImage);
+            NotifyPropertyChanged("CurrentWeatherImagePath");
 
-                this.CurrentFeelsLikeText = AppResources.MainPageCurrentFeelsLike;
-                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");
-                NotifyPropertyChanged("CurrentFeelsLikeText");
+            var currentMaxTemp = "";
+            if (current.main != null && current.main.temp_max != null)
+            {
+                var conversion = current.main.temp_max;
+                conversion -= tempUnits;
+                currentMaxTemp = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", conversion);
+            }
+            this.CurrentMaxTemp = currentMaxTemp;
+            this.CurrentMaxTempUnits = symbol;
+            NotifyPropertyChanged("CurrentMaxTemp");
+            NotifyPropertyChanged("CurrentMaxTempUnits");
 
-                this.CurrentHumidityText = AppResources.MainPageCurrentHumidity;
-                var currentHumidity = "";
-                if (remoteCurrentWeatherData.main != null)
-                {
-                    currentHumidity = remoteCurrentWeatherData.main.humidity.ToString(CultureInfo.InvariantCulture);
-                }
-                this.CurrentHumidity = currentHumidity;
-                this.CurrentHumidityUnits = AppResources.MainPageCurrentHumidityUnits;
-                NotifyPropertyChanged("CurrentHumidity");
-                NotifyPropertyChanged("CurrentHumidityUnits");
-                NotifyPropertyChanged("CurrentHumidityText");
+            var currentMinTemp = "";
+            if (current.main != null && current.main.temp_min != null)
+            {
+                var conversion = current.main.temp_min;
+                conversion -= tempUnits;
+                currentMinTemp = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", conversion);
+            }
+            this.CurrentMinTemp = currentMinTemp;
+            this.CurrentMinTempUnits = symbol;
+            NotifyPropertyChanged("CurrentMinTemp");
+            NotifyPropertyChanged("CurrentMinTempUnits");
 
-                this.CurrentRainText = AppResources.MainPageCurrentRain;
-                var currentRain = "";
-                if (remoteCurrentWeatherData.rain != null)
-                {
-                    currentRain = remoteCurrentWeatherData.rain.get3h().ToString(CultureInfo.InvariantCulture);
-                }
-                this.CurrentRain = currentRain;
-                this.CurrentRainUnits = AppResources.MainPageCurrentRainUnits;
-                NotifyPropertyChanged("CurrentRain");
-                NotifyPropertyChanged("CurrentRainUnits");
-                NotifyPropertyChanged("CurrentRainText");
+            var currentConditions = AppResources.MainPageCurrentDefaultDescription;
+            if (current.weather.Count > 0 && !String.IsNullOrEmpty(current.weather[0].description))
+            {
+                currentConditions = current.weather[0].description;
+            }
+            this.CurrentConditions = currentConditions;
+            NotifyPropertyChanged("CurrentConditions");
 
-                this.CurrentSnowText = AppResources.MainPageCurrentSnow;
-                var currentSnow = "";
-                if (remoteCurrentWeatherData.snow != null)
-                {
-                    currentSnow = remoteCurrentWeatherData.snow.get3h().ToString(CultureInfo.InvariantCulture);
-                }
-                this.CurrentSnow = currentSnow;
-                this.CurrentSnowUnits = AppResources.MainPageCurrentSnowUnits;
-                NotifyPropertyChanged("CurrentSnow");
-                NotifyPropertyChanged("CurrentSnowUnits");
-                NotifyPropertyChanged("CurrentSnowText");
+            this.CurrentFeelsLikeText = AppResources.MainPageCurrentFeelsLike;
+            var currentFeelsLikeTemp = "";
+            if (current.main != null && current.main.temp != null)
+            {
+                var conversion = current.main.temp;
+                conversion -= tempUnits;
+                currentFeelsLikeTemp = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", conversion);
+            }
+            this.CurrentFeelsLikeTemp = currentFeelsLikeTemp;
+            this.CurrentFeelsLikeTempUnits = symbol;
+            NotifyPropertyChanged("CurrentFeelsLikeTemp");
+            NotifyPropertyChanged("CurrentFeelsLikeTempUnits");
+            NotifyPropertyChanged("CurrentFeelsLikeText");
 
-                this.CurrentWindText = AppResources.MainPageCurrentWind;
-                var currentWind = "";
-                if (remoteCurrentWeatherData.wind != null)
-                {
-                    currentWind = remoteCurrentWeatherData.wind.speed.ToString(CultureInfo.InvariantCulture);
-                }
-                this.CurrentWind = currentWind;
-                this.CurrentWindUnits = AppResources.MainPageCurrentWindUnits;
-                NotifyPropertyChanged("CurrentWind");
-                NotifyPropertyChanged("CurrentWindUnits");
-                NotifyPropertyChanged("CurrentWindText");
+            this.CurrentHumidityText = AppResources.MainPageCurrentHumidity;
+            var currentHumidity = "";
+            if (current.main != null && current.main.humidity != null)
+            {
+                currentHumidity = current.main.humidity.Value.ToString(CultureInfo.InvariantCulture);
+            }
+            this.CurrentHumidity = currentHumidity;
+            this.CurrentHumidityUnits = AppResources.MainPageCurrentHumidityUnits;
+            NotifyPropertyChanged("CurrentHumidity");
+            NotifyPropertyChanged("CurrentHumidityUnits");
+            NotifyPropertyChanged("CurrentHumidityText");
 
-                this.CurrentCloudsText = AppResources.MainPageCurrentClouds;
-                var currentClouds = "";
-                if (remoteCurrentWeatherData.clouds != null)
-                {
-                    currentClouds = remoteCurrentWeatherData.clouds.all.ToString(CultureInfo.InvariantCulture);
-                }
-                this.CurrentClouds = currentClouds;
-                this.CurrentCloudsUnits = AppResources.MainPageCurrentCloudsUnits;
-                NotifyPropertyChanged("CurrentClouds");
-                NotifyPropertyChanged("CurrentCloudsUnits");
-                NotifyPropertyChanged("CurrentCloudsText");
+            this.CurrentRainText = AppResources.MainPageCurrentRain;
+            var currentRain = "";
+            if (current.rain != null && current.rain.get3h() != null)
+            {
+                currentRain = current.rain.get3h().Value.ToString(CultureInfo.InvariantCulture);
+            }
+            this.CurrentRain = currentRain;
+            this.CurrentRainUnits = AppResources.MainPageCurrentRainUnits;
+            NotifyPropertyChanged("CurrentRain");
+            NotifyPropertyChanged("CurrentRainUnits");
+            NotifyPropertyChanged("CurrentRainText");
 
-                this.CurrentPressureText = AppResources.MainPageCurrentPressure;
-                var currentPressure = "";
-                if (remoteCurrentWeatherData.main != null)
-                {
-                    currentPressure = remoteCurrentWeatherData.main.pressure.ToString(CultureInfo.InvariantCulture);
-                }
-                this.CurrentPressure = currentPressure;
-                this.CurrentPressureUnits = AppResources.MainPageCurrentPressureUnits;
-                NotifyPropertyChanged("CurrentPressure");
-                NotifyPropertyChanged("CurrentPressureUnits");
-                NotifyPropertyChanged("CurrentPressureText");
+            this.CurrentSnowText = AppResources.MainPageCurrentSnow;
+            var currentSnow = "";
+            if (current.snow != null && current.snow.get3h() != null)
+            {
+                currentSnow = current.snow.get3h().Value.ToString(CultureInfo.InvariantCulture);
+            }
+            this.CurrentSnow = currentSnow;
+            this.CurrentSnowUnits = AppResources.MainPageCurrentSnowUnits;
+            NotifyPropertyChanged("CurrentSnow");
+            NotifyPropertyChanged("CurrentSnowUnits");
+            NotifyPropertyChanged("CurrentSnowText");
 
-                this.CurrentSunRiseText = AppResources.MainPageCurrentSunRise;
-                var sunRiseTime = unixTime.AddSeconds(remoteCurrentWeatherData.sys.sunrise);
-                this.CurrentSunRise = sunRiseTime.ToString("MM/dd/yy H:mm:ss", CultureInfo.InvariantCulture);
-                NotifyPropertyChanged("CurrentSunRise");
-                NotifyPropertyChanged("CurrentSunRiseText");
+            this.CurrentWindText = AppResources.MainPageCurrentWind;
+            var currentWind = "";
+            if (current.wind != null && current.wind.speed != null)
+            {
+                currentWind = current.wind.speed.Value.ToString(CultureInfo.InvariantCulture);
+            }
+            this.CurrentWind = currentWind;
+            this.CurrentWindUnits = AppResources.MainPageCurrentWindUnits;
+            NotifyPropertyChanged("CurrentWind");
+            NotifyPropertyChanged("CurrentWindUnits");
+            NotifyPropertyChanged("CurrentWindText");
+
+            this.CurrentCloudsText = AppResources.MainPageCurrentClouds;
+            var currentClouds = "";
+            if (current.clouds != null && current.clouds.all != null)
+            {
+                currentClouds = current.clouds.all.Value.ToString(CultureInfo.InvariantCulture);
+            }
+            this.CurrentClouds = currentClouds;
+            this.CurrentCloudsUnits = AppResources.MainPageCurrentCloudsUnits;
+            NotifyPropertyChanged("CurrentClouds");
+            NotifyPropertyChanged("CurrentCloudsUnits");
+            NotifyPropertyChanged("CurrentCloudsText");
+
+            this.CurrentPressureText = AppResources.MainPageCurrentPressure;
+            var currentPressure = "";
+            if (current.main != null && current.main.pressure != null)
+            {
+                currentPressure = current.main.pressure.Value.ToString(CultureInfo.InvariantCulture);
+            }
+            this.CurrentPressure = currentPressure;
+            this.CurrentPressureUnits = AppResources.MainPageCurrentPressureUnits;
+            NotifyPropertyChanged("CurrentPressure");
+            NotifyPropertyChanged("CurrentPressureUnits");
+            NotifyPropertyChanged("CurrentPressureText");
 
-                this.CurrentSunSetText = AppResources.MainPageCurrentSunSet;
-                var sunSetTime = unixTime.AddSeconds(remoteCurrentWeatherData.sys.sunset);
-                this.CurrentSunSet = sunSetTime.ToString("MM/dd/yy H:mm:ss", CultureInfo.InvariantCulture);
-                NotifyPropertyChanged("CurrentSunSet");
-                NotifyPropertyChanged("CurrentSunSetText");
+            this.CurrentSunRiseText = AppResources.MainPageCurrentSunRise;
+            string sunRise = "";
+            if (current.sys.sunrise != null)
+            {
+                var sunRiseTime = baseUnixTime.AddSeconds(current.sys.sunrise.Value);
+                sunRise = sunRiseTime.ToString("MM/dd/yy H:mm:ss", CultureInfo.InvariantCulture);
+            }
+            this.CurrentSunRise = sunRise;
+            NotifyPropertyChanged("CurrentSunRise");
+            NotifyPropertyChanged("CurrentSunRiseText");
 
-                string country = weatherData.Country;
-                string city = weatherData.City;
-                string cityCountry = String.Format(CultureInfo.InvariantCulture, "{0}, {1}", city, country);
-                this.TitleTextCityCountry = cityCountry;
-                NotifyPropertyChanged("TitleTextCityCountry");
+            this.CurrentSunSetText = AppResources.MainPageCurrentSunSet;
+            string sunSet = "";
+            if (current.sys.sunset != null)
+            {
+                var sunSetTime = baseUnixTime.AddSeconds(current.sys.sunset.Value);
+                sunSet = sunSetTime.ToString("MM/dd/yy H:mm:ss", CultureInfo.InvariantCulture);
             }
 
+            this.CurrentSunSet = sunSet;
+            NotifyPropertyChanged("CurrentSunSet");
+            NotifyPropertyChanged("CurrentSunSetText");
         }
 
         public event PropertyChangedEventHandler PropertyChanged;
index c07f474..ece1e6a 100644 (file)
@@ -58,9 +58,14 @@ namespace WeatherInformation.ViewModels
             var remoteForecastWeatherData = weatherData.Forecast;
 
             WeatherInformation.Model.ForecastWeatherParser.List forecast = remoteForecastWeatherData.list[index];
-            DateTime unixTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
-            DateTime date = unixTime.AddSeconds(forecast.dt).ToLocalTime();
-            this.SelectedDate = date.ToString("m", CultureInfo.InvariantCulture);
+            DateTime baseUnixTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+            string selectedDate = "";
+            if (forecast.dt != null)
+            {
+                var date = baseUnixTime.AddSeconds(forecast.dt.Value).ToLocalTime();
+                selectedDate = date.ToString("m", CultureInfo.InvariantCulture);
+            }
+            this.SelectedDate = selectedDate;
             NotifyPropertyChanged("SelectedDate");
 
             bool isFahrenheit = true;
@@ -88,7 +93,7 @@ namespace WeatherInformation.ViewModels
 
             var selectedDateMaxTemp = "";
             var selectedDateTempUnits = "";
-            if (forecast.temp != null)
+            if (forecast.temp != null && forecast.temp.max != null)
             {
                 var conversion = forecast.temp.max;
                 conversion -= tempUnits;
@@ -102,7 +107,7 @@ namespace WeatherInformation.ViewModels
 
             var selectedDateMinTemp = "";
             selectedDateTempUnits = "";
-            if (forecast.temp != null)
+            if (forecast.temp != null && forecast.temp.min != null)
             {
                 var conversion = forecast.temp.min;
                 conversion -= tempUnits;
@@ -114,46 +119,69 @@ namespace WeatherInformation.ViewModels
             this.SelectedDateMaxTempUnits = selectedDateTempUnits;
             NotifyPropertyChanged("SelectedDateMinTempUnits");
 
-            // TODO: static resource :(
-            var selectedDateConditions = "no description available";
-            if (forecast.weather.Count > 0)
+            var selectedDateConditions = AppResources.SelectedDatePageDefaultDescription;
+            if (forecast.weather.Count > 0 && !String.IsNullOrEmpty(forecast.weather[0].description))
             {
                 selectedDateConditions = forecast.weather[0].description;
             }
             this.SelectedDateConditions = selectedDateConditions;
             NotifyPropertyChanged("SelectedDateConditions");
 
-            // TODO: nullables para distinguir cuando hay datos o no. Ahora me llega 0 si no datos (supongo) cuando double/integer
             this.SelectedDateHumidityText = AppResources.MainPageCurrentHumidity;
-            this.SelectedDateHumidity = forecast.humidity.ToString(CultureInfo.InvariantCulture);
+            var selectedDateHumidity = "";
+            if (forecast.humidity != null)
+            {
+                selectedDateHumidity = forecast.humidity.Value.ToString(CultureInfo.InvariantCulture);
+            }
+            this.SelectedDateHumidity = selectedDateHumidity;
             this.SelectedDateHumidityUnits = AppResources.MainPageCurrentHumidityUnits;
             NotifyPropertyChanged("SelectedDateHumidity");
             NotifyPropertyChanged("SelectedDateHumidityUnits");
             NotifyPropertyChanged("SelectedDateHumidityText");
 
             this.SelectedDateRainText = AppResources.MainPageCurrentRain;
-            this.SelectedDateRain = forecast.rain.ToString(CultureInfo.InvariantCulture);
+            var selectedDateRain = "";
+            if (forecast.rain != null)
+            {
+                selectedDateRain = forecast.rain.Value.ToString(CultureInfo.InvariantCulture);
+            }
+            this.SelectedDateRain = selectedDateRain;
             this.SelectedDateRainUnits = AppResources.MainPageCurrentRainUnits;
             NotifyPropertyChanged("SelectedDateRain");
             NotifyPropertyChanged("SelectedDateRainUnits");
             NotifyPropertyChanged("SelectedDateRainText");
 
             this.SelectedDateWindText = AppResources.MainPageCurrentWind;
-            this.SelectedDateWind = forecast.speed.ToString(CultureInfo.InvariantCulture);
+            var selectedDateSpeed = "";
+            if (forecast.speed != null)
+            {
+                selectedDateSpeed = forecast.speed.Value.ToString(CultureInfo.InvariantCulture);
+            }
+            this.SelectedDateWind = selectedDateSpeed;
             this.SelectedDateWindUnits = AppResources.MainPageCurrentWindUnits;
             NotifyPropertyChanged("SelectedDateWind");
             NotifyPropertyChanged("SelectedDateWindUnits");
             NotifyPropertyChanged("SelectedDateWindText");
 
             this.SelectedDateCloudsText = AppResources.MainPageCurrentClouds;
-            this.SelectedDateClouds = forecast.clouds.ToString(CultureInfo.InvariantCulture);
+            var selectedDateClouds = "";
+            if (forecast.clouds != null)
+            {
+                selectedDateClouds = forecast.clouds.Value.ToString(CultureInfo.InvariantCulture);
+            }
+            this.SelectedDateClouds = selectedDateClouds;
             this.SelectedDateCloudsUnits = AppResources.MainPageCurrentCloudsUnits;
             NotifyPropertyChanged("SelectedDateClouds");
             NotifyPropertyChanged("SelectedDateCloudsUnits");
             NotifyPropertyChanged("SelectedDateCloudsText");
 
             this.SelectedDatePressureText = AppResources.MainPageCurrentPressure;
-            this.SelectedDatePressure = forecast.pressure.ToString(CultureInfo.InvariantCulture);
+            var selectedDatePressure = "";
+            if (forecast.pressure != null)
+            {
+                selectedDatePressure = forecast.pressure.Value.ToString(CultureInfo.InvariantCulture);
+            }
+            this.SelectedDatePressure = selectedDatePressure;
             this.SelectedDatePressureUnits = AppResources.MainPageCurrentPressureUnits;
             NotifyPropertyChanged("SelectedDatePressure");
             NotifyPropertyChanged("SelectedDatePressureUnits");