WeatherInformation: SelectedDatePage
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Mon, 28 Jul 2014 00:41:05 +0000 (02:41 +0200)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Mon, 28 Jul 2014 00:41:05 +0000 (02:41 +0200)
14 files changed:
WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs
WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml
WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml.cs
WindowsPhone/WeatherInformation/WeatherInformation/Model/Services/CustomHTTPClient.cs
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/SampleData/SelectedDateViewModelSampleData.xaml [new file with mode: 0644]
WindowsPhone/WeatherInformation/WeatherInformation/SelectedDatePage.xaml [new file with mode: 0644]
WindowsPhone/WeatherInformation/WeatherInformation/SelectedDatePage.xaml.cs [new file with mode: 0644]
WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs
WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs [new file with mode: 0644]
WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj

index a0fe39e..03f213d 100644 (file)
@@ -154,6 +154,7 @@ namespace WeatherInformation
                         using (StreamReader sr = new StreamReader(isoStore.OpenFile("JSONDataFile.txt", FileMode.Open)))
                         {
                             // This method loads the data from isolated storage, if it is available.
+                            // TODO: qué pasa si JSONRemoteForecastWeatherData o JSONRemoteCurrentWeatherData son null?
                             string JSONRemoteForecastWeatherData = sr.ReadLine();
                             string JSONRemoteCurrentWeatherData = sr.ReadLine();
                             var weatherData = WeatherParser(JSONRemoteForecastWeatherData, JSONRemoteCurrentWeatherData);
@@ -244,6 +245,7 @@ namespace WeatherInformation
             using (IsolatedStorageFileStream fileStream = isoStore.OpenFile(isoFileName, FileMode.OpenOrCreate))
             using (StreamWriter sw = new StreamWriter(fileStream))
             {
+                // TODO: qué pasa si JSONRemoteForecastWeatherData o JSONRemoteCurrentWeatherData son null?
                 sw.Write(value.JSONRemoteForecastWeatherData);
                 sw.Write(value.JSONRemoteCurrentWeatherData);
                 fileStream.Flush(true);
@@ -273,20 +275,28 @@ namespace WeatherInformation
 
             // Coming from TOMBSTONED
             // Check to see if the key for the application state data is in the State dictionary.
+            string JSONRemoteForecastWeatherData = null;
             if (PhoneApplicationService.Current.State.ContainsKey("JSONRemoteForecastWeatherData"))
             {
                 // If it exists, assign the data to the application member variable.
-                string JSONRemoteForecastWeatherData = PhoneApplicationService.Current.State["JSONRemoteForecastWeatherData"] as string;
-                // string remoteCurrentWeatherData = sr.ReadLine();
-                var weatherData = WeatherParser(JSONRemoteForecastWeatherData, null);
-                weatherData.JSONRemoteForecastWeatherData = JSONRemoteForecastWeatherData;
-                weatherData.JSONRemoteCurrentWeatherData = null;
-                weatherData.WasThereRemoteError = false;
-                ApplicationDataObject = weatherData;
+                JSONRemoteForecastWeatherData = PhoneApplicationService.Current.State["JSONRemoteForecastWeatherData"] as string;
             }
+            string JSONRemoteCurrentWeatherData = null;
+            if (PhoneApplicationService.Current.State.ContainsKey("JSONRemoteCurrentWeatherData"))
+            {
+                // If it exists, assign the data to the application member variable.
+                JSONRemoteCurrentWeatherData = PhoneApplicationService.Current.State["JSONRemoteCurrentWeatherData"] as string;
+            }
+            // TODO: qué pasa si JSONRemoteForecastWeatherData o JSONRemoteCurrentWeatherData son null?
+            var weatherData = WeatherParser(JSONRemoteForecastWeatherData, JSONRemoteCurrentWeatherData);
+            weatherData.JSONRemoteForecastWeatherData = JSONRemoteForecastWeatherData;
+            weatherData.JSONRemoteCurrentWeatherData = JSONRemoteCurrentWeatherData;
+            weatherData.WasThereRemoteError = false;
+            ApplicationDataObject = weatherData;
+            
             if (PhoneApplicationService.Current.State.ContainsKey("IsNewLocation"))
             {
-                IsNewLocation = (bool)IsolatedStorageSettings.ApplicationSettings["IsNewLocation"];
+                IsNewLocation = (bool)PhoneApplicationService.Current.State["IsNewLocation"];
             }
         }
 
@@ -301,7 +311,12 @@ namespace WeatherInformation
                 if (!string.IsNullOrEmpty(weatherData.JSONRemoteForecastWeatherData))
                 {
                     // Store it in the State dictionary.
-                    PhoneApplicationService.Current.State["JSONRemoteForecastWeatherData"] = weatherData.JSONRemoteForecastWeatherData;
+                    PhoneApplicationService.Current.State["JSONRemoteForecastWeatherData"] = weatherData.JSONRemoteForecastWeatherData; 
+                }
+                if (!string.IsNullOrEmpty(weatherData.JSONRemoteCurrentWeatherData))
+                {
+                    // Store it in the State dictionary.
+                    PhoneApplicationService.Current.State["JSONRemoteCurrentWeatherData"] = weatherData.JSONRemoteCurrentWeatherData;
                 }
                 PhoneApplicationService.Current.State["IsNewLocation"] = IsNewLocation;
 
index f72410f..e430365 100644 (file)
                                 <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
                                     <TextBlock Text="{Binding CurrentCloudsText}" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle3Style}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2,0"/>
                                     <TextBlock Text="{Binding CurrentClouds}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,0,2,0"/>
-                                    <TextBlock Text="{Binding CurrentSnowUnits}" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle3Style}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Margin="2,0"/>
+                                    <TextBlock Text="{Binding CurrentCloudsUnits}" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle3Style}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Margin="2,0"/>
                                 </StackPanel>
                             </StackPanel>
                         </Grid>
index d98b2b9..ad40048 100644 (file)
@@ -7,6 +7,7 @@ using System.Windows.Controls;
 using System.Windows.Navigation;
 using WeatherInformation.Model;
 using WeatherInformation.Resources;
+using WeatherInformation.ViewModels;
 
 namespace WeatherInformation
 {
@@ -138,7 +139,13 @@ namespace WeatherInformation
 
         private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
+            LongListSelector longListSelector = sender as LongListSelector;
 
+            // TODO: with LINQ :(
+            ItemViewModel element = longListSelector.SelectedItem as ItemViewModel;
+            int index = longListSelector.ItemsSource.IndexOf(element);
+            String uri = string.Format(CultureInfo.InvariantCulture, "/SelectedDatePage.xaml?parameter={0}", index);
+            NavigationService.Navigate(new Uri(uri, UriKind.Relative));
         }
 
         private void Location_Click(object sender, EventArgs e)
index 42ba9a3..c9c2bef 100644 (file)
@@ -22,6 +22,7 @@ namespace WeatherInformation.Model.Services
                 HttpRequestHeaders headers = client.DefaultRequestHeaders;
                 headers.IfModifiedSince = DateTime.UtcNow;
 
+                // TODO: THIS IS FUCKED UP. IT IS WORKING RANDOMLY... THE MOST OF THE TIMES IT STOPS HERE FOREVER...
                 string jsonData = await client.GetStringAsync(url);
 
                 return jsonData;
index 9118bb7..9598fb4 100644 (file)
@@ -331,6 +331,42 @@ namespace WeatherInformation.Resources {
         }
         
         /// <summary>
+        ///   Busca una cadena traducida similar a DAY.
+        /// </summary>
+        public static string SelectedDatePageDay {
+            get {
+                return ResourceManager.GetString("SelectedDatePageDay", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Busca una cadena traducida similar a EVENING.
+        /// </summary>
+        public static string SelectedDatePageEvening {
+            get {
+                return ResourceManager.GetString("SelectedDatePageEvening", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Busca una cadena traducida similar a MORNING.
+        /// </summary>
+        public static string SelectedDatePageMorning {
+            get {
+                return ResourceManager.GetString("SelectedDatePageMorning", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Busca una cadena traducida similar a NIGHT.
+        /// </summary>
+        public static string SelectedDatePageNight {
+            get {
+                return ResourceManager.GetString("SelectedDatePageNight", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Busca una cadena traducida similar a Forecast day numbers.
         /// </summary>
         public static string SettingsForecastDayNumbersHeader {
index 8ac4022..314a1a1 100644 (file)
           <source>hpa</source>
           <target state="new">hpa</target>
           <note from="MultilingualBuild" annotates="source" priority="2">Not to be translated.</note>
+          </trans-unit>
+        <trans-unit id="Resx/SelectedDatePageNight" translate="yes" xml:space="preserve">
+          <source>NIGHT</source>
+          <target state="translated">NOCHE</target>
+        </trans-unit>
+        <trans-unit id="Resx/SelectedDatePageMorning" translate="yes" xml:space="preserve">
+          <source>MORNING</source>
+          <target state="translated">MAÑANA</target>
+        </trans-unit>
+        <trans-unit id="Resx/SelectedDatePageEvening" translate="yes" xml:space="preserve">
+          <source>EVENING</source>
+          <target state="translated">TARDE</target>
+        </trans-unit>
+        <trans-unit id="Resx/SelectedDatePageDay" translate="yes" xml:space="preserve">
+          <source>DAY</source>
+          <target state="translated">DÍA</target>
         </trans-unit>
         <trans-unit id="Resx/MainPageCurrentSnowUnits" translate="yes" xml:space="preserve">
           <source>mm 3h</source>
           <source>%</source>
           <target state="new">%</target>
           <note from="MultilingualBuild" annotates="source" priority="2">Not to be translated.</note>
-        </trans-unit>
+          </trans-unit>
         <trans-unit id="Resx/MainPageCurrentCloudsUnits" translate="yes" xml:space="preserve">
           <source>%</source>
           <target state="new">%</target>
           <note from="MultilingualBuild" annotates="source" priority="2">Not to be translated.</note>
-        </trans-unit>
+          </trans-unit>
         <trans-unit id="Resx/MainPageCurrentSunSet" translate="yes" xml:space="preserve">
           <source>SUN SET</source>
           <target state="translated">SOL SE PONE</target>
index 1aa0c42..6b8c906 100644 (file)
           <target state="new">hpa</target>
           <note from="MultilingualBuild" annotates="source" priority="2">Not to be translated.</note>
         </trans-unit>
+        <trans-unit id="Resx/SelectedDatePageNight" translate="yes" xml:space="preserve">
+          <source>NIGHT</source>
+          <target state="new">NIGHT</target>
+        </trans-unit>
+        <trans-unit id="Resx/SelectedDatePageMorning" translate="yes" xml:space="preserve">
+          <source>MORNING</source>
+          <target state="new">MORNING</target>
+        </trans-unit>
+        <trans-unit id="Resx/SelectedDatePageEvening" translate="yes" xml:space="preserve">
+          <source>EVENING</source>
+          <target state="new">EVENING</target>
+        </trans-unit>
+        <trans-unit id="Resx/SelectedDatePageDay" translate="yes" xml:space="preserve">
+          <source>DAY</source>
+          <target state="new">DAY</target>
+        </trans-unit>
         <trans-unit id="Resx/MainPageCurrentSnowUnits" translate="yes" xml:space="preserve">
           <source>mm 3h</source>
           <target state="new">mm 3h</target>
index 62525d9..ce474c5 100644 (file)
     <value>hpa</value>
     <comment>Not to be translated.</comment>
   </data>
+  <data name="SelectedDatePageDay" xml:space="preserve">
+    <value>DAY</value>
+  </data>
+  <data name="SelectedDatePageEvening" xml:space="preserve">
+    <value>EVENING</value>
+  </data>
+  <data name="SelectedDatePageMorning" xml:space="preserve">
+    <value>MORNING</value>
+  </data>
+  <data name="SelectedDatePageNight" xml:space="preserve">
+    <value>NIGHT</value>
+  </data>
 </root>
\ No newline at end of file
diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/SelectedDateViewModelSampleData.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/SelectedDateViewModelSampleData.xaml
new file mode 100644 (file)
index 0000000..30098de
--- /dev/null
@@ -0,0 +1,35 @@
+<ViewModels:SelectedDateViewModel
+    xmlns:ViewModels="clr-namespace:WeatherInformation.ViewModels"
+    SelectedDate="July 27"
+    SelectedDateRainText="RAIN"
+    SelectedDateMaxTempUnits="ºC"
+    SelectedDateCloudsText="CLOUDS"
+    SelectedDatePressureText="PRESSURE"
+    SelectedDatePressure="1015"
+    SelectedDateWindText="WIND"
+    SelectedDateConditions="Sky is Clear"
+    SelectedDateWind="1.03"
+    SelectedDateWindUnits="m/s"
+    SelectedDateMinTempUnits="ºC"
+    SelectedDateHumidityUnits="%"
+    SelectedDateRain="10"
+    SelectedDateHumidity="50"
+    SelectedDateMaxTemp="25"
+    SelectedDateMorningTempText="MORNING"
+    SelectedDateMorningTemp="25"
+    SelectedDateMorningTempUnits="ºC"
+    SelectedDateDayTempText="DAY"
+    SelectedDateDayTemp="25"
+    SelectedDateDayTempUnits="ºC"
+    SelectedDateEveningTempText="EVENING"
+    SelectedDateEveningTemp="25"
+    SelectedDateEveningTempUnits="ºC"
+    SelectedDateNightTempText="NIGHT"
+    SelectedDateNightTemp="25"
+    SelectedDateNightTempUnits="ºC"
+    SelectedDatePressureUnits="hpa"
+    SelectedDateClouds="10"
+    SelectedDateRainUnits="mm 3h"
+    SelectedDateMinTemp="15"
+    SelectedDateHumidityText="HUMIDITY"
+    SelectedDateCloudsUnits="%"/>
diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SelectedDatePage.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/SelectedDatePage.xaml
new file mode 100644 (file)
index 0000000..124fbfb
--- /dev/null
@@ -0,0 +1,138 @@
+<phone:PhoneApplicationPage
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
+    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    xmlns:ViewModels="clr-namespace:WeatherInformation.ViewModels"
+    x:Class="WeatherInformation.SelectedDate"
+    mc:Ignorable="d"
+    SupportedOrientations="PortraitOrLandscape"  Orientation="Portrait"
+    shell:SystemTray.IsVisible="True"
+    d:DataContext="{d:DesignData /SampleData/SelectedDateViewModelSampleData.xaml}">
+
+       <phone:PhoneApplicationPage.Resources>
+               <ViewModels:SelectedDateViewModel x:Key="SelectedDateViewModelDataSource" d:IsDataSource="True"/>
+       </phone:PhoneApplicationPage.Resources>
+       <phone:PhoneApplicationPage.FontFamily>
+               <StaticResource ResourceKey="PhoneFontFamilyNormal"/>
+       </phone:PhoneApplicationPage.FontFamily>
+       <phone:PhoneApplicationPage.FontSize>
+               <StaticResource ResourceKey="PhoneFontSizeNormal"/>
+       </phone:PhoneApplicationPage.FontSize>
+       <phone:PhoneApplicationPage.Foreground>
+               <StaticResource ResourceKey="PhoneForegroundBrush"/>
+       </phone:PhoneApplicationPage.Foreground>
+<!--LayoutRoot es la cuadrícula raíz donde se coloca todo el contenido de la página-->
+       <Grid x:Name="LayoutRoot" Background="Transparent">
+        <!--Control Pivot-->
+               <phone:Pivot x:Name="TitleTextCityCountry" Title="{Binding LocalizedResources.MainPageTitle, Mode=OneWay, Source={StaticResource LocalizedStrings}}">
+                       <!--Elemento Pivot uno-->
+                       <phone:PivotItem Header="{Binding SelectedDate}">
+                <ScrollViewer HorizontalScrollBarVisibility="Auto">
+                    <Grid>
+                        <Grid.RowDefinitions>
+                            <RowDefinition Height="*" />
+                            <RowDefinition Height="*" />
+                            <RowDefinition Height="*" />
+                            <RowDefinition Height="*" />
+                        </Grid.RowDefinitions>
+                        <Grid.ColumnDefinitions>
+                            <ColumnDefinition Width="*" />
+                        </Grid.ColumnDefinitions>
+                        <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
+                            <Image Source="/Assets/Tiles/IconicTileMediumLarge.png" Width="100" Height="100" Margin="12,-6,12,0" />
+                            <StackPanel  Orientation="Vertical" VerticalAlignment="Center">
+                                <StackPanel  Orientation="Horizontal" VerticalAlignment="Center">
+                                    <TextBlock Text="{Binding SelectedDateMaxTemp}" TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Margin="2,0"/>
+                                    <TextBlock Text="{Binding SelectedDateMaxTempUnits}" TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Margin="2,0"/>
+                                </StackPanel>
+                                <StackPanel  Orientation="Horizontal" VerticalAlignment="Center">
+                                    <TextBlock Text="{Binding SelectedDateMinTemp}" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle3Style}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Margin="2,0"/>
+                                    <TextBlock Text="{Binding SelectedDateMinTempUnits}" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle3Style}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Margin="2,0"/>
+                                </StackPanel>
+                            </StackPanel>
+                        </StackPanel>
+                        <StackPanel Grid.Column="0" Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
+                            <TextBlock Text="{Binding SelectedDateConditions}" TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Margin="2,0"/>
+                        </StackPanel>
+                        <Grid Grid.Column="0" Grid.Row="2" HorizontalAlignment="Center">
+                            <Grid.ColumnDefinitions>
+                                <ColumnDefinition Width="Auto" />
+                                <ColumnDefinition Width="Auto" />
+                            </Grid.ColumnDefinitions>
+                            <Grid.RowDefinitions>
+                                <RowDefinition Height="*" />
+                                <RowDefinition Height="*" />
+                            </Grid.RowDefinitions>
+                            <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Center">
+                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
+                                    <TextBlock Text="{Binding SelectedDateHumidityText}" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle3Style}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2,0"/>
+                                    <TextBlock Text="{Binding SelectedDateHumidity}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,0,2,0"/>
+                                    <TextBlock Text="{Binding SelectedDateHumidityUnits}" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle3Style}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Margin="2,0"/>
+                                </StackPanel>
+                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
+                                    <TextBlock Text="{Binding SelectedDateRainText}" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle3Style}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2,0"/>
+                                    <TextBlock Text="{Binding SelectedDateRain}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,0,2,0"/>
+                                    <TextBlock Text="{Binding SelectedDateRainUnits}" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle3Style}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Margin="2,0"/>
+                                </StackPanel>
+                            </StackPanel>
+                            <StackPanel Grid.Column="1" Grid.Row="0" Orientation="Vertical" HorizontalAlignment="Right" VerticalAlignment="Center">
+                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
+                                    <TextBlock Text="{Binding SelectedDateWindText}" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle3Style}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2,0"/>
+                                    <TextBlock Text="{Binding SelectedDateWind}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,0,2,0"/>
+                                    <TextBlock Text="{Binding SelectedDateWindUnits}" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle3Style}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Margin="2,0"/>
+                                </StackPanel>
+                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
+                                    <TextBlock Text="{Binding SelectedDateCloudsText}" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle3Style}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2,0"/>
+                                    <TextBlock Text="{Binding SelectedDateClouds}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,0,2,0"/>
+                                    <TextBlock Text="{Binding SelectedDateCloudsUnits}" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle3Style}" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Margin="2,0"/>
+                                </StackPanel>
+                            </StackPanel>
+                            <StackPanel Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center">
+                                <TextBlock Text="{Binding SelectedDatePressureText}" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle3Style}" Margin="2,0"/>
+                                <TextBlock Text="{Binding SelectedDatePressure}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}" Margin="10,0,2,0"/>
+                                <TextBlock Text="{Binding SelectedDatePressureUnits}" TextWrapping="Wrap" Style="{StaticResource PhoneTextTitle3Style}" FontWeight="Bold" Margin="2,0"/>
+                            </StackPanel>
+                        </Grid>
+                        <ScrollViewer Grid.Column="0" Grid.Row="3" HorizontalScrollBarVisibility="Auto">
+                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
+                                <StackPanel Orientation="Vertical" Margin="0,0,20,0">
+                                    <TextBlock Text="{Binding SelectedDateMorningTempText}" Margin="2,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
+                                        <TextBlock Text="{Binding SelectedDateMorningTemp}" Margin="10,0,2,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                                        <TextBlock Text="{Binding SelectedDateMorningTempUnits}" Margin="2,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                                    </StackPanel>
+                                </StackPanel>
+                                <StackPanel Orientation="Vertical" Margin="0,0,20,0">
+                                    <TextBlock Text="{Binding SelectedDateDayTempText}" Margin="2,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
+                                        <TextBlock Text="{Binding SelectedDateDayTemp}" Margin="10,0,2,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                                        <TextBlock Text="{Binding SelectedDateDayTempUnits}" Margin="2,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                                    </StackPanel>
+                                </StackPanel>
+                                <StackPanel Orientation="Vertical" Margin="0,0,20,0">
+                                    <TextBlock Text="{Binding SelectedDateEveningTempText}" Margin="2,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
+                                        <TextBlock Text="{Binding SelectedDateEveningTemp}" Margin="10,0,2,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                                        <TextBlock Text="{Binding SelectedDateEveningTempUnits}" Margin="2,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                                    </StackPanel>
+                                </StackPanel>
+                                <StackPanel Orientation="Vertical" Margin="0,0,20,0">
+                                    <TextBlock Text="{Binding SelectedDateNightTempText}" Margin="2,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
+                                        <TextBlock Text="{Binding SelectedDateNightTemp}" Margin="10,0,2,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                                        <TextBlock Text="{Binding SelectedDateNightTempUnits}" Margin="2,0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+                                    </StackPanel>
+                                </StackPanel>
+                            </StackPanel>
+                        </ScrollViewer>
+                    </Grid>
+                </ScrollViewer>
+            </phone:PivotItem>
+            
+               </phone:Pivot>
+       </Grid>
+    
+</phone:PhoneApplicationPage>
\ No newline at end of file
diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SelectedDatePage.xaml.cs b/WindowsPhone/WeatherInformation/WeatherInformation/SelectedDatePage.xaml.cs
new file mode 100644 (file)
index 0000000..132581a
--- /dev/null
@@ -0,0 +1,72 @@
+using Microsoft.Phone.Controls;
+using System;
+using System.Globalization;
+using System.IO.IsolatedStorage;
+using System.Windows;
+using WeatherInformation.Model;
+using WeatherInformation.Resources;
+using WeatherInformation.ViewModels;
+
+namespace WeatherInformation
+{
+    public partial class SelectedDate : PhoneApplicationPage
+    {
+        SelectedDateViewModel _selectedDateViewModel;
+        bool _isNewPageInstance = false;
+
+        public SelectedDate()
+        {
+            InitializeComponent();
+
+            _isNewPageInstance = true;
+        }
+
+        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
+        {
+            base.OnNavigatedTo(e);
+
+            // If _isNewPageInstance is true, the page constuctor has been called, so
+            // state may need to be restored.
+            if (_isNewPageInstance)
+            {
+                if (_selectedDateViewModel == null)
+                {
+                    _selectedDateViewModel = new SelectedDateViewModel();
+                    // I always receive my parameter even if page was tombstoned. :)
+                    string stringIndex = NavigationContext.QueryString["parameter"];
+                    _selectedDateViewModel.SelectedDateIndex = Convert.ToInt32(stringIndex, CultureInfo.InvariantCulture);    
+                }
+
+                DataContext = _selectedDateViewModel;
+            }
+            // Set _isNewPageInstance to false. If the user navigates back to this page
+            // and it has remained in memory, this value will continue to be false.
+            _isNewPageInstance = false;
+
+            UpdateApplicationDataUI();
+        }
+
+        void UpdateApplicationDataUI()
+        {
+            WeatherData weatherData = (Application.Current as WeatherInformation.App).ApplicationDataObject;
+
+            if (weatherData.WasThereRemoteError)
+            {
+                MessageBox.Show(
+                     AppResources.NoticeThereIsNotCurrentLocation,
+                     AppResources.AskForLocationConsentMessageBoxCaption,
+                     MessageBoxButton.OK);
+                return;
+            }
+
+            _selectedDateViewModel.LoadData(weatherData);
+
+            // TODO: Should I try to move this code to MainViewModel. It seems so but how?
+            // TODO: What if the address is not available? I should show something like "Address not found" by default...
+            string country = (string)IsolatedStorageSettings.ApplicationSettings["Country"];
+            string city = (string)IsolatedStorageSettings.ApplicationSettings["City"];
+            string cityCountry = String.Format(CultureInfo.InvariantCulture, "{0}, {1}", city, country);
+            this.TitleTextCityCountry.Title = cityCountry;
+        }
+    }
+}
\ No newline at end of file
index 4cb995a..59cdbf0 100644 (file)
@@ -145,6 +145,7 @@ namespace WeatherInformation.ViewModels
             }
 
             // TODO: nullables?
+            // TODO: nullables para distinguir cuando hay datos o no. Ahora me llega 0 si no datos (supongo) cuando double/integer
 
             var remoteCurrentWeatherData = weatherData.RemoteCurrentWeatherData;
 
@@ -172,6 +173,7 @@ namespace WeatherInformation.ViewModels
             NotifyPropertyChanged("CurrentMinTemp");
             NotifyPropertyChanged("CurrentMinTempUnits");
 
+            // TODO: static resource :(
             var currentConditions = "no description available";
             if (remoteCurrentWeatherData.weather.Count > 0)
             {
diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SelectedDateViewModel.cs
new file mode 100644 (file)
index 0000000..9cb6625
--- /dev/null
@@ -0,0 +1,217 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Globalization;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+using WeatherInformation.Model;
+using WeatherInformation.Resources;
+
+namespace WeatherInformation.ViewModels
+{
+    public class SelectedDateViewModel : INotifyPropertyChanged
+    {
+
+        [DataMember]
+        public Int32 SelectedDateIndex { get; set; }
+
+        public String SelectedDate { get; private set; }
+        public String SelectedDateMaxTemp { get; private set; }
+        public String SelectedDateMaxTempUnits { get; private set; }
+        public String SelectedDateMinTemp { get; private set; }
+        public String SelectedDateMinTempUnits { get; private set; }
+        public String SelectedDateMorningTempText { get; private set; }
+        public String SelectedDateMorningTemp { get; private set; }
+        public String SelectedDateMorningTempUnits { get; private set; }
+        public String SelectedDateDayTempText { get; private set; }
+        public String SelectedDateDayTemp { get; private set; }
+        public String SelectedDateDayTempUnits { get; private set; }
+        public String SelectedDateEveningTempText { get; private set; }
+        public String SelectedDateEveningTemp { get; private set; }
+        public String SelectedDateEveningTempUnits { get; private set; }
+        public String SelectedDateNightTempText { get; private set; }
+        public String SelectedDateNightTemp { get; private set; }
+        public String SelectedDateNightTempUnits { get; private set; }
+        public String SelectedDateConditions { get; private set; }
+        public String SelectedDateHumidityText { get; private set; }
+        public String SelectedDateHumidity { get; private set; }
+        public String SelectedDateHumidityUnits { get; private set; }
+        public String SelectedDateRainText { get; private set; }
+        public String SelectedDateRain { get; private set; }
+        public String SelectedDateRainUnits { get; private set; }
+        public String SelectedDateWindText { get; private set; }
+        public String SelectedDateWind { get; private set; }
+        public String SelectedDateWindUnits { get; private set; }
+        public String SelectedDateCloudsText { get; private set; }
+        public String SelectedDateClouds { get; private set; }
+        public String SelectedDateCloudsUnits { get; private set; }
+        public String SelectedDatePressureText { get; private set; }
+        public String SelectedDatePressure { get; private set; }
+        public String SelectedDatePressureUnits { get; private set; }
+
+        public void LoadData(WeatherData weatherData)
+        {
+            var remoteForecastWeatherData = weatherData.RemoteForecastWeatherData;
+
+            WeatherInformation.Model.ForecastWeatherParser.List forecast = remoteForecastWeatherData.list[this.SelectedDateIndex];
+            DateTime unixTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+            DateTime date = unixTime.AddSeconds(forecast.dt).ToLocalTime();
+            this.SelectedDate = date.ToString("m", CultureInfo.InvariantCulture);
+            NotifyPropertyChanged("SelectedDate");
+
+            // TODO: units :(
+            bool isFahrenheit = false;
+            double tempUnits = isFahrenheit ? 0 : 273.15;
+            string symbol = isFahrenheit ? AppResources.TemperatureUnitsFahrenheitSymbol : AppResources.TemperatureUnitsCentigradeSymbol;
+
+            var selectedDateMaxTemp = "";
+            var selectedDateTempUnits = "";
+            if (forecast.temp != null)
+            {
+                var conversion = forecast.temp.max;
+                conversion -= tempUnits;
+                selectedDateMaxTemp = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", conversion);
+                selectedDateTempUnits = symbol;
+            }
+            this.SelectedDateMaxTemp = selectedDateMaxTemp;
+            NotifyPropertyChanged("SelectedDateMaxTemp");
+            this.SelectedDateMaxTempUnits = selectedDateTempUnits;
+            NotifyPropertyChanged("SelectedDateMaxTempUnits");
+
+            var selectedDateMinTemp = "";
+            selectedDateTempUnits = "";
+            if (forecast.temp != null)
+            {
+                var conversion = forecast.temp.min;
+                conversion -= tempUnits;
+                selectedDateMinTemp = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", conversion);
+                selectedDateTempUnits = symbol;
+            }
+            this.SelectedDateMinTemp = selectedDateMinTemp;
+            NotifyPropertyChanged("SelectedDateMinTemp");
+            this.SelectedDateMaxTempUnits = selectedDateTempUnits;
+            NotifyPropertyChanged("SelectedDateMinTempUnits");
+
+            // TODO: static resource :(
+            var selectedDateConditions = "no description available";
+            if (forecast.weather.Count > 0)
+            {
+                selectedDateConditions = forecast.weather[0].description;
+            }
+            this.SelectedDateConditions = selectedDateConditions;
+            NotifyPropertyChanged("SelectedDateConditions");
+
+            // TODO: nullables para distinguir cuando hay datos o no. Ahora me llega 0 si no datos (supongo) cuando double/integer
+            this.SelectedDateHumidityText = AppResources.MainPageCurrentHumidity;
+            this.SelectedDateHumidity = forecast.humidity.ToString(CultureInfo.InvariantCulture);
+            this.SelectedDateHumidityUnits = AppResources.MainPageCurrentHumidityUnits;
+            NotifyPropertyChanged("SelectedDateHumidity");
+            NotifyPropertyChanged("SelectedDateHumidityUnits");
+            NotifyPropertyChanged("SelectedDateHumidityText");
+
+            this.SelectedDateRainText = AppResources.MainPageCurrentRain;
+            this.SelectedDateRain = forecast.rain.ToString(CultureInfo.InvariantCulture);
+            this.SelectedDateRainUnits = AppResources.MainPageCurrentRainUnits;
+            NotifyPropertyChanged("SelectedDateRain");
+            NotifyPropertyChanged("SelectedDateRainUnits");
+            NotifyPropertyChanged("SelectedDateRainText");
+
+            this.SelectedDateWindText = AppResources.MainPageCurrentWind;
+            this.SelectedDateWind = forecast.speed.ToString(CultureInfo.InvariantCulture);
+            this.SelectedDateWindUnits = AppResources.MainPageCurrentWindUnits;
+            NotifyPropertyChanged("SelectedDateWind");
+            NotifyPropertyChanged("SelectedDateWindUnits");
+            NotifyPropertyChanged("SelectedDateWindText");
+
+            this.SelectedDateCloudsText = AppResources.MainPageCurrentClouds;
+            this.SelectedDateClouds = forecast.clouds.ToString(CultureInfo.InvariantCulture);
+            this.SelectedDateCloudsUnits = AppResources.MainPageCurrentCloudsUnits;
+            NotifyPropertyChanged("SelectedDateClouds");
+            NotifyPropertyChanged("SelectedDateCloudsUnits");
+            NotifyPropertyChanged("SelectedDateCloudsText");
+
+            this.SelectedDatePressureText = AppResources.MainPageCurrentPressure;
+            this.SelectedDatePressure = forecast.pressure.ToString(CultureInfo.InvariantCulture);
+            this.SelectedDatePressureUnits = AppResources.MainPageCurrentPressureUnits;
+            NotifyPropertyChanged("SelectedDatePressure");
+            NotifyPropertyChanged("SelectedDatePressureUnits");
+            NotifyPropertyChanged("SelectedDatePressureText");
+
+            var selectedDateMorningTemp = "";
+            selectedDateTempUnits = "";
+            if (forecast.temp != null)
+            {
+                var conversion = forecast.temp.morn;
+                conversion -= tempUnits;
+                selectedDateMorningTemp = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", conversion);
+                selectedDateTempUnits = symbol;
+            }
+            this.SelectedDateMorningTempText = AppResources.SelectedDatePageMorning;
+            NotifyPropertyChanged("SelectedDateMorningTempText");
+            this.SelectedDateMorningTemp = selectedDateMorningTemp;
+            NotifyPropertyChanged("SelectedDateMorningTemp");
+            this.SelectedDateMorningTempUnits = selectedDateTempUnits;
+            NotifyPropertyChanged("SelectedDateMorningTempUnits");
+
+            var selectedDateDayTemp = "";
+            selectedDateTempUnits = "";
+            if (forecast.temp != null)
+            {
+                var conversion = forecast.temp.day;
+                conversion -= tempUnits;
+                selectedDateDayTemp = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", conversion);
+                selectedDateTempUnits = symbol;
+            }
+            this.SelectedDateDayTempText = AppResources.SelectedDatePageDay;
+            NotifyPropertyChanged("SelectedDateDayTempText");
+            this.SelectedDateDayTemp = selectedDateDayTemp;
+            NotifyPropertyChanged("SelectedDateDayTemp");
+            this.SelectedDateDayTempUnits = selectedDateTempUnits;
+            NotifyPropertyChanged("SelectedDateDayTempUnits");
+
+            var selectedDateEveningTemp = "";
+            selectedDateTempUnits = "";
+            if (forecast.temp != null)
+            {
+                var conversion = forecast.temp.eve;
+                conversion -= tempUnits;
+                selectedDateEveningTemp = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", conversion);
+                selectedDateTempUnits = symbol;
+            }
+            this.SelectedDateEveningTempText = AppResources.SelectedDatePageEvening;
+            NotifyPropertyChanged("SelectedDateEveningTempText");
+            this.SelectedDateEveningTemp = selectedDateEveningTemp;
+            NotifyPropertyChanged("SelectedDateEveningTemp");
+            this.SelectedDateEveningTempUnits = selectedDateTempUnits;
+            NotifyPropertyChanged("SelectedDateEveningTempUnits");
+
+            var selectedDateNightTemp = "";
+            selectedDateTempUnits = "";
+            if (forecast.temp != null)
+            {
+                var conversion = forecast.temp.night;
+                conversion -= tempUnits;
+                selectedDateNightTemp = String.Format(CultureInfo.InvariantCulture, "{0:0.##}", conversion);
+                selectedDateTempUnits = symbol;
+            }
+            this.SelectedDateNightTempText = AppResources.SelectedDatePageNight;
+            NotifyPropertyChanged("SelectedDateNightTempText");
+            this.SelectedDateNightTemp = selectedDateNightTemp;
+            NotifyPropertyChanged("SelectedDateNightTemp");
+            this.SelectedDateNightTempUnits = selectedDateTempUnits;
+            NotifyPropertyChanged("SelectedDateNightTempUnits");
+        }
+
+        public event PropertyChangedEventHandler PropertyChanged;
+        private void NotifyPropertyChanged(String propertyName)
+        {
+            PropertyChangedEventHandler handler = PropertyChanged;
+            if (null != handler)
+            {
+                handler(this, new PropertyChangedEventArgs(propertyName));
+            }
+        }
+    }
+}
index 53220e0..cb96eff 100644 (file)
@@ -24,7 +24,7 @@
     <ValidateXaml>true</ValidateXaml>
     <MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
     <ThrowErrorsInValidation>true</ThrowErrorsInValidation>
-    <ExpressionBlendVersion>12.0.41212.0</ExpressionBlendVersion>
+    <ExpressionBlendVersion>12.0.50429.0</ExpressionBlendVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
       <DesignTime>True</DesignTime>
       <DependentUpon>AppResources.resx</DependentUpon>
     </Compile>
+    <Compile Include="SelectedDatePage.xaml.cs">
+      <DependentUpon>SelectedDatePage.xaml</DependentUpon>
+    </Compile>
     <Compile Include="SettingsPage.xaml.cs">
       <DependentUpon>SettingsPage.xaml</DependentUpon>
     </Compile>
     <Compile Include="ViewModels\ItemViewModel.cs" />
     <Compile Include="ViewModels\MainViewModel.cs" />
+    <Compile Include="ViewModels\SelectedDateViewModel.cs" />
     <Compile Include="ViewModels\SettingsViewModel.cs" />
   </ItemGroup>
   <ItemGroup>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </ApplicationDefinition>
+    <DesignData Include="SampleData\SelectedDateViewModelSampleData.xaml">
+      <Generator>MSBuild:MarkupCompilePass1</Generator>
+    </DesignData>
     <Page Include="MainPage.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="SelectedDatePage.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="SettingsPage.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>