From b4f2cd754123ad83e5874920e9dd2548ab9c0d74 Mon Sep 17 00:00:00 2001 From: "gu.martinm@gmail.com" Date: Wed, 30 Jul 2014 00:25:24 +0200 Subject: [PATCH] WeatherInformation: no time for comments --- .../WeatherInformation/MainPage.xaml | 2 +- .../WeatherInformation/MainPage.xaml.cs | 72 +++------------------- .../SampleData/MainViewModelSampleData.xaml | 1 + .../WeatherInformation/ViewModels/MainViewModel.cs | 8 +++ 4 files changed, 19 insertions(+), 64 deletions(-) diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml index e430365..084a4fd 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml @@ -47,7 +47,7 @@ --> - + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml.cs b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml.cs index ad40048..50c1c7a 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml.cs @@ -13,8 +13,6 @@ namespace WeatherInformation { public partial class MainPage : PhoneApplicationPage { - private bool _isNewPageInstance = false; - // Constructor public MainPage() { @@ -24,9 +22,6 @@ namespace WeatherInformation // Establecer el contexto de datos del control ListBox control en los datos de ejemplo DataContext = App.MainViewModel; - - _isNewPageInstance = true; - // Set the event handler for when the application data object changes. // TODO: doing this, when is the GC going to release this object? I do not think it is going to be able... This is weird... // Shouldn't I release this even handler when the MainPage is not used anymore. In my case is not a big problem because @@ -44,64 +39,22 @@ namespace WeatherInformation // Cargar datos para los elementos MainViewModel protected override void OnNavigatedTo(NavigationEventArgs e) { - // If _isNewPageInstance is true, the page constructor has been called, so - // state may need to be restored. - if (_isNewPageInstance) - { - if (!App.MainViewModel.IsThereCurrentLocation()) - { - MessageBox.Show( - AppResources.NoticeThereIsNotCurrentLocation, - AppResources.AskForLocationConsentMessageBoxCaption, - MessageBoxButton.OK); - } - else - { - // If the application member variable is not empty, - // set the page's data object from the application member variable. - // TODO: I am setting and getting ApplicationDataObject from different threads!!!! What if I do not see its last value? Do I need synchronization? :/ - WeatherData weatherData = (Application.Current as WeatherInformation.App).ApplicationDataObject; - if (weatherData != null && !(Application.Current as WeatherInformation.App).IsNewLocation) - { - UpdateApplicationDataUI(); - } - else - { - // Otherwise, call the method that loads data. - (Application.Current as WeatherInformation.App).GetDataAsync(); - } - } - } - else + if (App.MainViewModel.IsThereCurrentLocation()) { - if (!App.MainViewModel.IsThereCurrentLocation()) + // If the application member variable is not empty, + // set the page's data object from the application member variable. + // TODO: I am setting and getting ApplicationDataObject from different threads!!!! What if I do not see its last value? Do I need synchronization? :/ + WeatherData weatherData = (Application.Current as WeatherInformation.App).ApplicationDataObject; + if (weatherData != null && !(Application.Current as WeatherInformation.App).IsNewLocation) { - MessageBox.Show( - AppResources.NoticeThereIsNotCurrentLocation, - AppResources.AskForLocationConsentMessageBoxCaption, - MessageBoxButton.OK); + UpdateApplicationDataUI(); } else { - // If the application member variable is not empty, - // set the page's data object from the application member variable. - // TODO: I am setting and getting ApplicationDataObject from different threads!!!! What if I do not see the its last state? Do I need synchronization? :/ - WeatherData weatherData = (Application.Current as WeatherInformation.App).ApplicationDataObject; - if (weatherData != null && !(Application.Current as WeatherInformation.App).IsNewLocation) - { - UpdateApplicationDataUI(); - } - else - { - // Otherwise, call the method that loads data. - (Application.Current as WeatherInformation.App).GetDataAsync(); - } + // Otherwise, call the method that loads data. + (Application.Current as WeatherInformation.App).GetDataAsync(); } } - - // Set _isNewPageInstance to false. If the user navigates back to this page - // and it has remained in memory, this value will continue to be false. - _isNewPageInstance = false; } // The event handler called when the ApplicationDataObject changes. @@ -128,13 +81,6 @@ namespace WeatherInformation App.MainViewModel.LoadData(weatherData); (Application.Current as WeatherInformation.App).IsNewLocation = false; - - // TODO: Should I try to move this code to MainViewModel. It seems so but how? - // TODO: What if the address is not available? I should show something like "Address not found" by default... - string country = (string)IsolatedStorageSettings.ApplicationSettings["Country"]; - string city = (string)IsolatedStorageSettings.ApplicationSettings["City"]; - string cityCountry = String.Format(CultureInfo.InvariantCulture, "{0}, {1}", city, country); - this.TitleTextCityCountry.Title = cityCountry; } private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e) diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml index c0ff345..c53a2ab 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml @@ -2,6 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="clr-namespace:WeatherInformation.ViewModels" + TitleTextCityCountry="City,country" CurrentMaxTemp="25" CurrentMaxTempUnits="ºC" CurrentMinTemp="15" diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs index 2d125c3..8ca2a49 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs @@ -44,6 +44,7 @@ namespace WeatherInformation.ViewModels /// public ObservableCollection ForecastItems{ get; private set; } public ObservableCollection CurrentItems { get; private set; } + public String TitleTextCityCountry { get; private set; } public String CurrentMaxTemp { get; private set; } public String CurrentMaxTempUnits { get; private set; } public String CurrentMinTemp { get; private set; } @@ -111,6 +112,13 @@ namespace WeatherInformation.ViewModels double tempUnits = isFahrenheit ? 0 : 273.15; string symbol = isFahrenheit ? AppResources.TemperatureUnitsFahrenheitSymbol : AppResources.TemperatureUnitsCentigradeSymbol; + + // TODO: What if address is not available? I should show something like "Address not found" by default... + string country = (string)IsolatedStorageSettings.ApplicationSettings["Country"]; + string city = (string)IsolatedStorageSettings.ApplicationSettings["City"]; + string cityCountry = String.Format(CultureInfo.InvariantCulture, "{0}, {1}", city, country); + this.TitleTextCityCountry = cityCountry; + DateTime unixTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var remoteForecastWeatherData = weatherData.RemoteForecastWeatherData; -- 2.1.4