From d4963c15ef90cd29bcdce531fd703593a89b31b9 Mon Sep 17 00:00:00 2001 From: "gu.martinm@gmail.com" Date: Sat, 16 Aug 2014 23:32:51 +0200 Subject: [PATCH] WeatherInformation WP8: city and country by default. Default values: City not found/Country not found --- .../WeatherInformation/WeatherInformation/App.xaml.cs | 8 ++++---- .../WeatherInformation/MapPage.xaml.cs | 13 +++++++++---- .../Resources/AppResources.Designer.cs | 18 ++++++++++++++++++ .../WeatherInformation/Resources/AppResources.es.resx | 8 ++++++++ .../WeatherInformation/Resources/AppResources.es.xlf | 10 ++++++++++ .../Resources/AppResources.qps-ploc.xlf | 10 ++++++++++ .../WeatherInformation/Resources/AppResources.resx | 8 ++++++++ .../WeatherInformation/ViewModels/MainViewModel.cs | 1 - .../ViewModels/SelectedDateViewModel.cs | 1 - 9 files changed, 67 insertions(+), 10 deletions(-) diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs index 8a009ce..005e5e4 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs @@ -151,13 +151,13 @@ namespace WeatherInformation country = PhoneApplicationService.Current.State["Country"] as string; } - if (!string.IsNullOrEmpty(JSONRemoteCurrentWeather) && !string.IsNullOrEmpty(JSONRemoteForecastWeather)) + if (!string.IsNullOrEmpty(JSONRemoteCurrentWeather) && !string.IsNullOrEmpty(JSONRemoteForecastWeather) && + !string.IsNullOrEmpty(city) && !string.IsNullOrEmpty(country)) { - // TODO: I am repeating this code 2 times. What could I do to improve it? var parser = new ServiceParser(new JsonParser()); weatherData = parser.WeatherDataParser(JSONRemoteForecastWeather, JSONRemoteCurrentWeather); - weatherData.City = city ?? ""; - weatherData.Country = country ?? ""; + weatherData.City = city; + weatherData.Country = country; } ApplicationDataObject = weatherData; diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs b/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs index 822847c..e2d936d 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs @@ -99,7 +99,6 @@ namespace WeatherInformation { if (eventData.Result.Count > 0) { - // TODO: What if there is no city or country. Is there null value or empty string? MapAddress address = eventData.Result[0].Information.Address; GeoCoordinate currentGeoCoordinate = eventData.Result[0].GeoCoordinate; @@ -132,9 +131,15 @@ namespace WeatherInformation this.mapWeatherInformation.Center = geoCoordinate; this.mapWeatherInformation.ZoomLevel = 13; - // TODO: What if there is no city or country. Is there null value or empty string? - string cityCountry = String.Format(CultureInfo.InvariantCulture, "{0}, {1}", city, country); - this.LocationTextCityCountry.Text = cityCountry; + if (string.IsNullOrEmpty(city)) + { + city = AppResources.DefaultCity; + } + if (string.IsNullOrEmpty(country)) + { + country = AppResources.DefaultCountry; + } + this.LocationTextCityCountry.Text = String.Format(CultureInfo.InvariantCulture, "{0}, {1}", city, country); _city = city; _country = country; // Add the MapLayer to the Map. diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs index d05d572..35806cd 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs @@ -106,6 +106,24 @@ namespace WeatherInformation.Resources { } /// + /// Busca una cadena traducida similar a City not found. + /// + public static string DefaultCity { + get { + return ResourceManager.GetString("DefaultCity", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a Country not found. + /// + public static string DefaultCountry { + get { + return ResourceManager.GetString("DefaultCountry", resourceCulture); + } + } + + /// /// Busca una cadena traducida similar a City, country. /// public static string LocationPageSubTitle { diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx index 4841556..64e05c9 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx @@ -257,4 +257,12 @@ Detección automática de la ubicación parece estar desactivada en el teléfono o el servicio no está disponible. Message box error: while trying to get automatic current location + + País no encontrado + Country, default value. + + + Ciudad no encontrada + City, default value. + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf index 5325aac..5ca1bae 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf @@ -154,6 +154,16 @@ Posición actual Map page, button get the user's current location + + Country not found + País no encontrado + Country, default value. + + + City not found + Ciudad no encontrada + City, default value. + MORNING MAÑANA diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf index 6106e3e..d40fbf3 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf @@ -139,6 +139,16 @@ Current Location Map page, button get the user's current location + + Country not found + Country not found + Country, default value. + + + City not found + City not found + City, default value. + MORNING MORNING diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx index 65e2de4..232519c 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx @@ -300,4 +300,12 @@ Current Location Map page, button get the user's current location + + City not found + City, default value. + + + Country not found + Country, default value. + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs index f6bf463..8cb7891 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs @@ -308,7 +308,6 @@ namespace WeatherInformation.ViewModels NotifyPropertyChanged("CurrentSunSet"); NotifyPropertyChanged("CurrentSunSetText"); - // TODO: What if address is not available? I should show something like "Address not found" by default... string country = weatherData.Country; string city = weatherData.City; string cityCountry = String.Format(CultureInfo.InvariantCulture, "{0}, {1}", city, country); diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs index cb2e009..1e27dee 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs @@ -222,7 +222,6 @@ namespace WeatherInformation.ViewModels this.SelectedDateNightTempUnits = selectedDateTempUnits; NotifyPropertyChanged("SelectedDateNightTempUnits"); - // TODO: What if address is not available? I should show something like "Address not found" by default... string country = weatherData.Country; string city = weatherData.City; string cityCountry = String.Format(CultureInfo.InvariantCulture, "{0}, {1}", city, country); -- 2.1.4