WeatherInformation WP8: selected date index improvements
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Sun, 17 Aug 2014 08:02:30 +0000 (10:02 +0200)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Sun, 17 Aug 2014 08:02:30 +0000 (10:02 +0200)
WindowsPhone/WeatherInformation/WeatherInformation/SelectedDatePage.xaml.cs
WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs

index a20ba1d..4706982 100644 (file)
@@ -32,9 +32,6 @@ namespace WeatherInformation
                 if (_selectedDateViewModel == null)
                 {
                     _selectedDateViewModel = new SelectedDateViewModel();
-                    // I always receive my parameter even if page was tombstoned. :)
-                    string stringIndex = NavigationContext.QueryString["parameter"];
-                    _selectedDateViewModel.SelectedDateIndex = Convert.ToInt32(stringIndex, CultureInfo.InvariantCulture);    
                 }
 
                 DataContext = _selectedDateViewModel;
@@ -43,16 +40,20 @@ namespace WeatherInformation
             // and it has remained in memory, this value will continue to be false.
             _isNewPageInstance = false;
 
-            UpdateApplicationDataUI();
+            // I always receive my parameter even if page was tombstoned. :)
+            string stringIndex = NavigationContext.QueryString["parameter"];
+            int index = Convert.ToInt32(stringIndex, CultureInfo.InvariantCulture);
+
+            UpdateApplicationDataUI(index);
         }
 
-        void UpdateApplicationDataUI()
+        void UpdateApplicationDataUI(int index)
         {
             WeatherData weatherData = (Application.Current as WeatherInformation.App).ApplicationDataObject;
 
             if (weatherData != null)
             {
-                _selectedDateViewModel.LoadData(weatherData);
+                _selectedDateViewModel.LoadData(weatherData, index);
             }
         }
     }
index 36e1afe..06cecf9 100644 (file)
@@ -17,8 +17,6 @@ namespace WeatherInformation.ViewModels
     {
         private readonly SettingsViewModel _settings = new SettingsViewModel();
 
-        [DataMember]
-        public Int32 SelectedDateIndex { get; set; }
 
         public String TitleTextCityCountry { get; private set; }
 
@@ -57,11 +55,11 @@ namespace WeatherInformation.ViewModels
         public String SelectedDatePressure { get; private set; }
         public String SelectedDatePressureUnits { get; private set; }
 
-        public void LoadData(WeatherData weatherData)
+        public void LoadData(WeatherData weatherData, int index)
         {
             var remoteForecastWeatherData = weatherData.RemoteForecast;
 
-            WeatherInformation.Model.ForecastWeatherParser.List forecast = remoteForecastWeatherData.list[this.SelectedDateIndex];
+            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);