From: gu.martinm@gmail.com Date: Thu, 31 Jul 2014 23:00:14 +0000 (+0200) Subject: WindowsPhone8 WeahterInformation no time for comments X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=884bc819b8b1d4c101e443c648857918c54fab5b;p=CSharpForFun%2F.git WindowsPhone8 WeahterInformation no time for comments --- diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs index e51cdb1..62697af 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs @@ -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 /// 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; } } diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml.cs b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml.cs index 50c1c7a..f61244f 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml.cs @@ -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) diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs b/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs index 6e1ae1a..e2b89d3 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs @@ -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 index 0000000..bec91c0 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/Services/StoredLocation.cs @@ -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; + } + } + } +} diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs index 9598fb4..8ce8080 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs @@ -61,6 +61,15 @@ namespace WeatherInformation.Resources { } /// + /// Busca una cadena traducida similar a 14. + /// + public static string APIOpenWeatherMapResultsNumber { + get { + return ResourceManager.GetString("APIOpenWeatherMapResultsNumber", resourceCulture); + } + } + + /// /// Busca una cadena traducida similar a 2.5. /// public static string APIVersionOpenWeatherMap { diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf index 314a1a1..a60ca8f 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf @@ -144,6 +144,11 @@ NIGHT NOCHE + + 14 + 14 + Not to be translated. + MORNING MAÑANA diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf index 6b8c906..106efef 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf @@ -129,6 +129,11 @@ NIGHT NIGHT + + 14 + 14 + Not to be translated. + MORNING MORNING diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx index ce474c5..596a211 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx @@ -292,4 +292,8 @@ NIGHT + + 14 + Not to be translated. + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj b/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj index cb96eff..c5993ed 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj +++ b/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj @@ -119,6 +119,7 @@ +