From: gu.martinm@gmail.com Date: Sat, 16 Aug 2014 20:19:42 +0000 (+0200) Subject: WeatherInformation WP8: X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=29f777467393e926f08ab571eb278a03bd43e345;p=CSharpForFun%2F.git WeatherInformation WP8: Weather pictures plus UTC time instead of local time. --- diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_clear.png b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_clear.png new file mode 100644 index 0000000..73a5bbd Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_clear.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_clear_night.png b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_clear_night.png new file mode 100644 index 0000000..2c60054 Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_clear_night.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_few_clouds.png b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_few_clouds.png new file mode 100644 index 0000000..2d38702 Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_few_clouds.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_few_clouds_night.png b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_few_clouds_night.png new file mode 100644 index 0000000..333afa7 Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_few_clouds_night.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_fog.png b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_fog.png new file mode 100644 index 0000000..1bebc54 Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_fog.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_overcast.png b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_overcast.png new file mode 100644 index 0000000..e3101eb Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_overcast.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_severe_alert.png b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_severe_alert.png new file mode 100644 index 0000000..b0ac4b7 Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_severe_alert.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_showers.png b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_showers.png new file mode 100644 index 0000000..6a1860c Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_showers.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_showers_scattered.png b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_showers_scattered.png new file mode 100644 index 0000000..97d0f77 Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_showers_scattered.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_snow.png b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_snow.png new file mode 100644 index 0000000..ac714cc Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_snow.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_storm.png b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_storm.png new file mode 100644 index 0000000..c339221 Binary files /dev/null and b/WindowsPhone/WeatherInformation/WeatherInformation/Images/weather_storm.png differ diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml index a0d3cff..5d73b4e 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml @@ -96,7 +96,7 @@ - + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Model/Images/RemoteImagesTranslation.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Model/Images/RemoteImagesTranslation.cs new file mode 100644 index 0000000..b62df75 --- /dev/null +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Model/Images/RemoteImagesTranslation.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WeatherInformation.Model.Images +{ + class RemoteImagesTranslation + { + // C# Language Specification§10.11 + // If a class contains any static fields with initializers, those initializers are executed + // in textual order immediately prior to executing the static constructor. + private readonly static Dictionary images = new Dictionary(); + + static RemoteImagesTranslation() + { + images.Add("01d", "weather_clear"); + images.Add("01n", "weather_clear_night"); + images.Add("02d", "weather_few_clouds"); + images.Add("02n", "weather_few_clouds_night"); + images.Add("03d", "weather_few_clouds"); + images.Add("03n", "weather_few_clouds"); + images.Add("04d", "weather_overcast"); + images.Add("04n", "weather_overcast"); + images.Add("09d", "weather_showers"); + images.Add("09n", "weather_showers"); + images.Add("10d", "weather_showers_scattered"); + images.Add("10n", "weather_showers_scattered"); + images.Add("11d", "weather_storm"); + images.Add("11n", "weather_storm"); + images.Add("13d", "weather_snow"); + images.Add("13n", "weather_snow"); + images.Add("50d", "weather_fog"); + images.Add("50n", "weather_fog"); + } + + public static string GetTransaltedImage(string id) + { + string value; + images.TryGetValue(id, out value); + + return value; + } + } +} diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs index 94aff21..d05d572 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs @@ -232,7 +232,7 @@ namespace WeatherInformation.Resources { } /// - /// Busca una cadena traducida similar a SUN RISE. + /// Busca una cadena traducida similar a SUN RISE (UTC). /// public static string MainPageCurrentSunRise { get { @@ -241,7 +241,7 @@ namespace WeatherInformation.Resources { } /// - /// Busca una cadena traducida similar a SUN SET. + /// Busca una cadena traducida similar a SUN SET (UTC). /// public static string MainPageCurrentSunSet { get { diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx index fdb107b..4841556 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.resx @@ -210,10 +210,10 @@ VIENTO - SOL SE PONE + SOL SE PONE (UTC) - SOL SALE + SOL SALE (UTC) NIEVE diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf index d281cf9..5325aac 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf @@ -185,13 +185,11 @@ Not to be translated. - SUN SET - SOL SE PONE - + SUN SET (UTC) + SOL SE PONE (UTC) - SUN RISE - SOL SALE - + SUN RISE (UTC) + SOL SALE (UTC) SNOW NIEVE diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf index d601dde..6106e3e 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf @@ -170,12 +170,12 @@ Not to be translated. - SUN SET - SUN SET + SUN SET (UTC) + SUN SET (UTC) - SUN RISE - SUN RISE + SUN RISE (UTC) + SUN RISE (UTC) SNOW diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx index fb63164..65e2de4 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx @@ -243,10 +243,10 @@ SNOW - SUN RISE + SUN RISE (UTC) - SUN SET + SUN SET (UTC) WIND diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml index c53a2ab..6bdfb9e 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/MainViewModelSampleData.xaml @@ -3,6 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="clr-namespace:WeatherInformation.ViewModels" TitleTextCityCountry="City,country" + CurrentWeatherImagePath="/Images/weather_clear.png" CurrentMaxTemp="25" CurrentMaxTempUnits="ºC" CurrentMinTemp="15" @@ -14,9 +15,9 @@ CurrentRainText="RAIN" CurrentSnow="10" CurrentSnowText="SNOW" - CurrentSunRiseText="SUN RISE" + CurrentSunRiseText="SUN RISE (UTC)" CurrentSunRise="2014.07.19 07:01:54" - CurrentSunSetText="SUN SET" + CurrentSunSetText="SUN SET (UTC)" CurrentSunSet="2014.07.19 21:41:40" CurrentWind="1.03" CurrentWindText="WIND" @@ -35,22 +36,13 @@ CurrentCloudsUnits="%"> - - - - - - + + + + + + - - - - - - - - - \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/SelectedDateViewModelSampleData.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/SelectedDateViewModelSampleData.xaml index bbc7f3e..bc26817 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/SelectedDateViewModelSampleData.xaml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/SelectedDateViewModelSampleData.xaml @@ -2,6 +2,7 @@ xmlns:ViewModels="clr-namespace:WeatherInformation.ViewModels" TitleTextCityCountry="City,country" SelectedDate="July 27" + SelectedDateWeatherImagePath="/Images/weather_clear.png" SelectedDateRainText="RAIN" SelectedDateMaxTempUnits="ºC" SelectedDateCloudsText="CLOUDS" diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SelectedDatePage.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/SelectedDatePage.xaml index c0e6f04..37764ae 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/SelectedDatePage.xaml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/SelectedDatePage.xaml @@ -44,7 +44,7 @@ - + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs index 1248ddf..f6bf463 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Globalization; using System.IO.IsolatedStorage; using WeatherInformation.Model; +using WeatherInformation.Model.Images; using WeatherInformation.Resources; namespace WeatherInformation.ViewModels @@ -38,6 +39,7 @@ namespace WeatherInformation.ViewModels public ObservableCollection ForecastItems{ get; private set; } public ObservableCollection CurrentItems { get; private set; } public String TitleTextCityCountry { get; private set; } + public String CurrentWeatherImagePath { get; private set; } public String CurrentMaxTemp { get; private set; } public String CurrentMaxTempUnits { get; private set; } public String CurrentMinTemp { get; private set; } @@ -113,7 +115,7 @@ namespace WeatherInformation.ViewModels foreach (WeatherInformation.Model.ForecastWeatherParser.List item in remoteForecastWeatherData.list) { - DateTime date = unixTime.AddSeconds(item.dt).ToLocalTime(); + DateTime date = unixTime.AddSeconds(item.dt); // TODO: if I do not receive max temp or min temp... Am I going to receive item.temp.max=0 or item.temp.min=0 (I guess because // double has no null value) @@ -125,13 +127,26 @@ namespace WeatherInformation.ViewModels double minTemp = item.temp.min; minTemp = minTemp - tempUnits; + string weatherImage; + if (item.weather.Count > 0 && + item.weather[0].icon != null && + RemoteImagesTranslation.GetTransaltedImage(item.weather[0].icon) != null) + { + weatherImage = RemoteImagesTranslation.GetTransaltedImage(item.weather[0].icon); + } + else + { + weatherImage = "weather_severe_alert"; + } + string weatherImagePath = String.Format(CultureInfo.InvariantCulture, "/Images/{0}.png", weatherImage); + this.ForecastItems.Add(new ItemViewModel() { LineOne = date.ToString("ddd", CultureInfo.InvariantCulture), LineTwo = date.ToString("dd", CultureInfo.InvariantCulture), LineThree = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", maxTemp) + symbol, LineFour = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", minTemp) + symbol, - LineFive = "/Assets/Tiles/IconicTileMediumLarge.png" + LineFive = weatherImagePath }); count--; @@ -148,6 +163,20 @@ namespace WeatherInformation.ViewModels var remoteCurrentWeatherData = weatherData.RemoteCurrent; if (remoteCurrentWeatherData != null) { + string weatherImage; + if (remoteCurrentWeatherData.weather.Count > 0 && + remoteCurrentWeatherData.weather[0].icon != null && + RemoteImagesTranslation.GetTransaltedImage(remoteCurrentWeatherData.weather[0].icon) != null) + { + weatherImage = RemoteImagesTranslation.GetTransaltedImage(remoteCurrentWeatherData.weather[0].icon); + } + else + { + weatherImage = "weather_severe_alert"; + } + this.CurrentWeatherImagePath = String.Format(CultureInfo.InvariantCulture, "/Images/{0}.png", weatherImage); + NotifyPropertyChanged("CurrentWeatherImagePath"); + var currentMaxTemp = ""; if (remoteCurrentWeatherData.main != null) { @@ -268,13 +297,13 @@ namespace WeatherInformation.ViewModels NotifyPropertyChanged("CurrentPressureText"); this.CurrentSunRiseText = AppResources.MainPageCurrentSunRise; - var sunRiseTime = unixTime.AddSeconds(remoteCurrentWeatherData.sys.sunrise).ToLocalTime(); + var sunRiseTime = unixTime.AddSeconds(remoteCurrentWeatherData.sys.sunrise); this.CurrentSunRise = sunRiseTime.ToString("MM/dd/yy H:mm:ss", CultureInfo.InvariantCulture); NotifyPropertyChanged("CurrentSunRise"); NotifyPropertyChanged("CurrentSunRiseText"); this.CurrentSunSetText = AppResources.MainPageCurrentSunSet; - var sunSetTime = unixTime.AddSeconds(remoteCurrentWeatherData.sys.sunset).ToLocalTime(); + var sunSetTime = unixTime.AddSeconds(remoteCurrentWeatherData.sys.sunset); this.CurrentSunSet = sunSetTime.ToString("MM/dd/yy H:mm:ss", CultureInfo.InvariantCulture); NotifyPropertyChanged("CurrentSunSet"); NotifyPropertyChanged("CurrentSunSetText"); diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs index 2cddabb..cb2e009 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs @@ -7,6 +7,7 @@ using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using WeatherInformation.Model; +using WeatherInformation.Model.Images; using WeatherInformation.Model.Services; using WeatherInformation.Resources; @@ -21,6 +22,7 @@ namespace WeatherInformation.ViewModels public String TitleTextCityCountry { get; private set; } public String SelectedDate { get; private set; } + public String SelectedDateWeatherImagePath { get; private set; } public String SelectedDateMaxTemp { get; private set; } public String SelectedDateMaxTempUnits { get; private set; } public String SelectedDateMinTemp { get; private set; } @@ -69,6 +71,20 @@ namespace WeatherInformation.ViewModels double tempUnits = isFahrenheit ? 0 : 273.15; string symbol = isFahrenheit ? AppResources.TemperatureUnitsFahrenheitSymbol : AppResources.TemperatureUnitsCentigradeSymbol; + string weatherImage; + if (forecast.weather.Count > 0 && + forecast.weather[0].icon != null && + RemoteImagesTranslation.GetTransaltedImage(forecast.weather[0].icon) != null) + { + weatherImage = RemoteImagesTranslation.GetTransaltedImage(forecast.weather[0].icon); + } + else + { + weatherImage = "weather_severe_alert"; + } + this.SelectedDateWeatherImagePath = String.Format(CultureInfo.InvariantCulture, "/Images/{0}.png", weatherImage); + NotifyPropertyChanged("SelectedDateWeatherImagePath"); + var selectedDateMaxTemp = ""; var selectedDateTempUnits = ""; if (forecast.temp != null) diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj b/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj index 529e604..820d1fe 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj +++ b/WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj @@ -118,6 +118,7 @@ + @@ -199,6 +200,17 @@ + + + + + + + + + + +