WindowsPhone8 WeahterInformation no time for comments
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Thu, 31 Jul 2014 23:00:14 +0000 (01:00 +0200)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Thu, 31 Jul 2014 23:00:14 +0000 (01:00 +0200)
WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs
WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml.cs
WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs
WindowsPhone/WeatherInformation/WeatherInformation/Model/Services/StoredLocation.cs [new file with mode: 0644]
WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs
WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf
WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf
WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx
WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj

index e51cdb1..62697af 100644 (file)
@@ -65,12 +65,6 @@ namespace WeatherInformation
             }
         }
 
-        public bool IsNewLocation
-        {
-            get;
-            set;
-        }
-
         // Create a method to raise the ApplicationDataObjectChanged event.
         protected void OnApplicationDataObjectChanged(EventArgs e)
         {
@@ -142,7 +136,7 @@ namespace WeatherInformation
                 TimeSinceLastSave = DateTime.Now - dataLastSaveTime;
             }
 
-            if (TimeSinceLastSave.TotalSeconds < 30 && !IsNewLocation)
+            if (TimeSinceLastSave.TotalSeconds < 30 && !StoredLocation.IsNewLocation)
             {
                 GetStoredData();
             }
@@ -213,19 +207,20 @@ namespace WeatherInformation
         /// </summary>
         async public Task LoadDataAsync()
         {
+            double latitude = StoredLocation.CurrentLatitude;
+            double longitude = StoredLocation.CurrentLongitude;
+            int resultsNumber = Convert.ToInt32(AppResources.APIOpenWeatherMapResultsNumber);
+
             CustomHTTPClient httpClient = new CustomHTTPClient();
 
-            int resultsNumber = 14;
             string formattedForecastURL = String.Format(
                 CultureInfo.InvariantCulture, AppResources.URIAPIOpenWeatherMapForecast,
-                AppResources.APIVersionOpenWeatherMap, (double)IsolatedStorageSettings.ApplicationSettings["CurrentLatitude"],
-                (double)IsolatedStorageSettings.ApplicationSettings["CurrentLongitude"], resultsNumber);
+                AppResources.APIVersionOpenWeatherMap, latitude, longitude, resultsNumber);
             string JSONRemoteForecastWeather = await httpClient.GetWeatherDataAsync(formattedForecastURL);
 
             string formattedCurrentURL = String.Format(
                 CultureInfo.InvariantCulture, AppResources.URIAPIOpenWeatherMapCurrent,
-                AppResources.APIVersionOpenWeatherMap, (double)IsolatedStorageSettings.ApplicationSettings["CurrentLatitude"],
-                (double)IsolatedStorageSettings.ApplicationSettings["CurrentLongitude"], resultsNumber);
+                AppResources.APIVersionOpenWeatherMap, latitude, longitude, resultsNumber);
             string JSONRemoteCurrentWeather = await httpClient.GetWeatherDataAsync(formattedCurrentURL);
 
             ApplicationDataObject = WeatherDataParser(JSONRemoteForecastWeather, JSONRemoteCurrentWeather);
@@ -316,11 +311,6 @@ namespace WeatherInformation
             }
 
             ApplicationDataObject = WeatherDataParser(JSONRemoteForecastWeather, JSONRemoteCurrentWeather);
-            
-            if (PhoneApplicationService.Current.State.ContainsKey("IsNewLocation"))
-            {
-                IsNewLocation = (bool)PhoneApplicationService.Current.State["IsNewLocation"];
-            }
         }
 
         // Código para ejecutar cuando la aplicación se desactiva (se envía a segundo plano)
@@ -347,8 +337,6 @@ namespace WeatherInformation
                     // Also store it in isolated storage, in case the application is never reactivated.
                     SaveDataToIsolatedStorage("JSONRemoteCurrentWeatherDataFile.txt", weatherData.JSONRemoteCurrentWeatherData);
                 }
-
-                PhoneApplicationService.Current.State["IsNewLocation"] = IsNewLocation;
             }
         }
 
index 50c1c7a..f61244f 100644 (file)
@@ -6,6 +6,7 @@ using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Navigation;
 using WeatherInformation.Model;
+using WeatherInformation.Model.Services;
 using WeatherInformation.Resources;
 using WeatherInformation.ViewModels;
 
@@ -45,7 +46,7 @@ namespace WeatherInformation
                 // 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)
+                if (weatherData != null && !StoredLocation.IsNewLocation)
                 {
                     UpdateApplicationDataUI();
                 }
@@ -80,7 +81,7 @@ namespace WeatherInformation
     
             App.MainViewModel.LoadData(weatherData);
 
-            (Application.Current as WeatherInformation.App).IsNewLocation = false;
+            StoredLocation.IsNewLocation = false;
         }
 
         private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
index 6e1ae1a..e2b89d3 100644 (file)
@@ -16,6 +16,7 @@ using Microsoft.Phone.Maps.Controls;
 using WeatherInformation.Resources;
 using System.Globalization;
 using Microsoft.Phone.Maps.Services;
+using WeatherInformation.Model.Services;
 
 namespace WeatherInformation
 {
@@ -128,13 +129,12 @@ namespace WeatherInformation
                     this.LocationTextCityCountry.Text = cityCountry;
 
                     // TODO: If I want to store more than one place I should use a database :(
-                    _settings["CurrentLatitude"] = currentGeoCoordinate.Latitude;
-                    _settings["CurrentLongitude"] = currentGeoCoordinate.Longitude;
+                    StoredLocation.CurrentLatitude = currentGeoCoordinate.Latitude;
+                    StoredLocation.CurrentLongitude = currentGeoCoordinate.Longitude;
                     // TODO: If I want to store more thant one place I should use a database :(
-                    _settings["City"] = address.City;
-                    _settings["Country"] = address.Country;
-
-                    (Application.Current as WeatherInformation.App).IsNewLocation = true;
+                    StoredLocation.City = address.City;
+                    StoredLocation.Country = address.Country;
+                    StoredLocation.IsNewLocation = true;
 
                     // Create a small circle to mark the current location.
                     Ellipse myCircle = new Ellipse();
diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/Services/StoredLocation.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/Services/StoredLocation.cs
new file mode 100644 (file)
index 0000000..bec91c0
--- /dev/null
@@ -0,0 +1,95 @@
+using System;
+using System.Collections.Generic;
+using System.IO.IsolatedStorage;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WeatherInformation.Model.Services
+{
+    // TODO: If I want to store more than one place I should use a database :(
+    class StoredLocation
+    {
+        public static double CurrentLatitude
+        {
+            get
+            {
+                if (IsolatedStorageSettings.ApplicationSettings.Contains("CurrentLatitude"))
+                {
+                    return (double)IsolatedStorageSettings.ApplicationSettings["CurrentLatitude"];
+                }
+                // TODO: what if settings does not contain this value? :/
+                return 0;
+            }
+            set
+            {
+                IsolatedStorageSettings.ApplicationSettings["CurrentLatitude"] = value;
+            }
+        }
+
+        public static double CurrentLongitude
+        {
+            get
+            {
+                if (IsolatedStorageSettings.ApplicationSettings.Contains("CurrentLongitude"))
+                {
+                    return (double)IsolatedStorageSettings.ApplicationSettings["CurrentLongitude"];
+                }
+                // TODO: what if settings does not contain this value? :/
+                return 0;
+            }
+            set
+            {
+                IsolatedStorageSettings.ApplicationSettings["CurrentLongitude"] = value;
+            }
+        }
+
+        public static string City
+        {
+            get
+            {
+                if (IsolatedStorageSettings.ApplicationSettings.Contains("City"))
+                {
+                    return (string)IsolatedStorageSettings.ApplicationSettings["City"];
+                }
+                return null;
+            }
+            set
+            {
+                IsolatedStorageSettings.ApplicationSettings["City"] = value;
+            }
+        }
+
+        public static string Country
+        {
+            get
+            {
+                if (IsolatedStorageSettings.ApplicationSettings.Contains("Country"))
+                {
+                    return (string)IsolatedStorageSettings.ApplicationSettings["Country"];
+                }
+                return null;
+            }
+            set
+            {
+                IsolatedStorageSettings.ApplicationSettings["Country"] = value;
+            }
+        }
+
+        public static bool IsNewLocation
+        {
+            get
+            {
+                if (IsolatedStorageSettings.ApplicationSettings.Contains("IsNewLocation"))
+                {
+                    return (bool)IsolatedStorageSettings.ApplicationSettings["IsNewLocation"];
+                }
+                return false;
+            }
+            set
+            {
+                IsolatedStorageSettings.ApplicationSettings["IsNewLocation"] = value;
+            }
+        }
+    }
+}
index 9598fb4..8ce8080 100644 (file)
@@ -61,6 +61,15 @@ namespace WeatherInformation.Resources {
         }
         
         /// <summary>
+        ///   Busca una cadena traducida similar a 14.
+        /// </summary>
+        public static string APIOpenWeatherMapResultsNumber {
+            get {
+                return ResourceManager.GetString("APIOpenWeatherMapResultsNumber", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Busca una cadena traducida similar a 2.5.
         /// </summary>
         public static string APIVersionOpenWeatherMap {
index 314a1a1..a60ca8f 100644 (file)
           <source>NIGHT</source>
           <target state="translated">NOCHE</target>
         </trans-unit>
+        <trans-unit id="Resx/APIOpenWeatherMapResultsNumber" translate="yes" xml:space="preserve">
+          <source>14</source>
+          <target state="new">14</target>
+          <note from="MultilingualBuild" annotates="source" priority="2">Not to be translated.</note>
+        </trans-unit>
         <trans-unit id="Resx/SelectedDatePageMorning" translate="yes" xml:space="preserve">
           <source>MORNING</source>
           <target state="translated">MAÑANA</target>
index 6b8c906..106efef 100644 (file)
           <source>NIGHT</source>
           <target state="new">NIGHT</target>
         </trans-unit>
+        <trans-unit id="Resx/APIOpenWeatherMapResultsNumber" translate="yes" xml:space="preserve">
+          <source>14</source>
+          <target state="new">14</target>
+          <note from="MultilingualBuild" annotates="source" priority="2">Not to be translated.</note>
+        </trans-unit>
         <trans-unit id="Resx/SelectedDatePageMorning" translate="yes" xml:space="preserve">
           <source>MORNING</source>
           <target state="new">MORNING</target>
index ce474c5..596a211 100644 (file)
   <data name="SelectedDatePageNight" xml:space="preserve">
     <value>NIGHT</value>
   </data>
+  <data name="APIOpenWeatherMapResultsNumber" xml:space="preserve">
+    <value>14</value>
+    <comment>Not to be translated.</comment>
+  </data>
 </root>
\ No newline at end of file
index cb96eff..c5993ed 100644 (file)
     <Compile Include="Model\ForecastWeatherParser\Temp.cs" />
     <Compile Include="Model\ForecastWeatherParser\Weather.cs" />
     <Compile Include="Model\JsonDataParser\JsonParser.cs" />
+    <Compile Include="Model\Services\StoredLocation.cs" />
     <Compile Include="Model\WeatherData.cs" />
     <Compile Include="Model\Services\CustomHTTPClient.cs" />
     <Compile Include="Model\Services\ServiceParser.cs" />