}
}
- public bool IsNewLocation
- {
- get;
- set;
- }
-
// Create a method to raise the ApplicationDataObjectChanged event.
protected void OnApplicationDataObjectChanged(EventArgs e)
{
TimeSinceLastSave = DateTime.Now - dataLastSaveTime;
}
- if (TimeSinceLastSave.TotalSeconds < 30 && !IsNewLocation)
+ if (TimeSinceLastSave.TotalSeconds < 30 && !StoredLocation.IsNewLocation)
{
GetStoredData();
}
/// </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);
}
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)
// Also store it in isolated storage, in case the application is never reactivated.
SaveDataToIsolatedStorage("JSONRemoteCurrentWeatherDataFile.txt", weatherData.JSONRemoteCurrentWeatherData);
}
-
- PhoneApplicationService.Current.State["IsNewLocation"] = IsNewLocation;
}
}
using System.Windows.Controls;
using System.Windows.Navigation;
using WeatherInformation.Model;
+using WeatherInformation.Model.Services;
using WeatherInformation.Resources;
using WeatherInformation.ViewModels;
// 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();
}
App.MainViewModel.LoadData(weatherData);
- (Application.Current as WeatherInformation.App).IsNewLocation = false;
+ StoredLocation.IsNewLocation = false;
}
private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
using WeatherInformation.Resources;
using System.Globalization;
using Microsoft.Phone.Maps.Services;
+using WeatherInformation.Model.Services;
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();
--- /dev/null
+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;
+ }
+ }
+ }
+}
}
/// <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 {
<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>
<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>
<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
<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" />