WeatherInformation: no time for comments
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Tue, 29 Jul 2014 22:25:24 +0000 (00:25 +0200)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Tue, 29 Jul 2014 22:25:24 +0000 (00:25 +0200)
WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml
WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml.cs
WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml
WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs

index e430365..084a4fd 100644 (file)
@@ -47,7 +47,7 @@
          -->
 
         <!--Control Pivot-->
-        <phone:Pivot x:Name="TitleTextCityCountry" Title="{Binding LocalizedResources.MainPageTitle, Mode=OneWay, Source={StaticResource LocalizedStrings}}">
+        <phone:Pivot x:Name="TitleTextCityCountry" Title="{Binding TitleTextCityCountry}">
             <!--Elemento Pivot uno-->
             <phone:PivotItem Header="{Binding LocalizedResources.MainPageForecastHeader, Mode=OneWay, Source={StaticResource LocalizedStrings}}">
                 <phone:LongListSelector x:Name="ForecastItems" Margin="0,0,-12,0" ItemsSource="{Binding ForecastItems}" SelectionChanged="LongListSelector_SelectionChanged">
index ad40048..50c1c7a 100644 (file)
@@ -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)
index c0ff345..c53a2ab 100644 (file)
@@ -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"
index 2d125c3..8ca2a49 100644 (file)
@@ -44,6 +44,7 @@ namespace WeatherInformation.ViewModels
         /// </summary>
         public ObservableCollection<ItemViewModel> ForecastItems{ get; private set; }
         public ObservableCollection<ItemViewModel> 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;