From: gu.martinm@gmail.com Date: Sun, 17 Aug 2014 08:02:30 +0000 (+0200) Subject: WeatherInformation WP8: selected date index improvements X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=07bbef5040ed9286f1654391956853a0f5859f52;p=CSharpForFun%2F.git WeatherInformation WP8: selected date index improvements --- diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SelectedDatePage.xaml.cs b/WindowsPhone/WeatherInformation/WeatherInformation/SelectedDatePage.xaml.cs index a20ba1d..4706982 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/SelectedDatePage.xaml.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/SelectedDatePage.xaml.cs @@ -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); } } } diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs index 36e1afe..06cecf9 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs @@ -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);