CurrentUICulture de la aplicación en tiempo de ejecución.
-->
+ <TextBlock x:Name="NoDataAvailable" Text="{Binding LocalizedResources.MainPageRemoteDataError, Mode=OneWay, Source={StaticResource LocalizedStrings}}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle2Style}" FontSize="24" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.ColumnSpan="3" Visibility="Collapsed"/>
+ <ProgressBar x:Name="ProgressBarRemoteData" IsIndeterminate="True" LargeChange="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Height="80" FontSize="20" FlowDirection="LeftToRight" UseLayoutRounding="True" IsEnabled="False" />
+
<!--Control Pivot-->
<phone:Pivot x:Name="TitleTextCityCountry" Title="{Binding TitleTextCityCountry}">
<!--Elemento Pivot uno-->
- <phone:PivotItem Header="{Binding LocalizedResources.MainPageForecastHeader, Mode=OneWay, Source={StaticResource LocalizedStrings}}">
+ <phone:PivotItem x:Name="ForecastData" Header="{Binding LocalizedResources.MainPageForecastHeader, Mode=OneWay, Source={StaticResource LocalizedStrings}}">
<phone:LongListSelector x:Name="ForecastItems" Margin="0,0,-12,0" ItemsSource="{Binding ForecastItems}" SelectionChanged="LongListSelector_SelectionChanged">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
</phone:PivotItem>
<!--Elemento Pivot dos-->
- <phone:PivotItem Header="{Binding LocalizedResources.MainPageCurrentHeader, Mode=OneWay, Source={StaticResource LocalizedStrings}}">
+ <phone:PivotItem x:Name="CurrentData" Header="{Binding LocalizedResources.MainPageCurrentHeader, Mode=OneWay, Source={StaticResource LocalizedStrings}}">
<ScrollViewer HorizontalScrollBarVisibility="Auto">
<Grid>
<Grid.RowDefinitions>
using WeatherInformation.ViewModels;
using System.Threading.Tasks;
using WeatherInformation.Model.JsonDataParser;
-using Microsoft.Phone.Shell;
namespace WeatherInformation
{
{
base.OnNavigatedTo(e);
- CreateFlipTile();
-
// If _isNewPageInstance is true, the page constuctor has been called, so
// state may need to be restored.
if (_isNewPageInstance)
locationItem = db.Locations.Where(location => location.IsSelected).FirstOrDefault();
}
+ // Empty UI
+ this.CurrentData.Visibility = Visibility.Collapsed;
+ this.ForecastData.Visibility = Visibility.Collapsed;
+ this.ProgressBarRemoteData.Visibility = Visibility.Collapsed;
+ this.NoDataAvailable.Visibility = Visibility.Collapsed;
+
if (locationItem == null)
{
// Nothing to do.
+ // Show error message.
+ this.CurrentData.Visibility = Visibility.Collapsed;
+ this.ForecastData.Visibility = Visibility.Collapsed;
+ this.ProgressBarRemoteData.Visibility = Visibility.Collapsed;
+ this.NoDataAvailable.Visibility = Visibility.Visible;
return;
}
WeatherData weatherData = (Application.Current as WeatherInformation.App).ApplicationDataObject;
if (!IsDataFresh(locationItem.LastRemoteDataUpdate) || weatherData == null)
{
- // Load remote data (aynchronous way by means of async/await)
-
// Gets the data from the web.
- (Application.Current as WeatherInformation.App).ApplicationDataObject =
- await GetRemoteDataAsync(locationItem);
+ this.CurrentData.Visibility = Visibility.Collapsed;
+ this.ForecastData.Visibility = Visibility.Collapsed;
+ this.ProgressBarRemoteData.Visibility = Visibility.Visible;
+ this.NoDataAvailable.Visibility = Visibility.Collapsed;
- using (var db = new LocationDataContext(LocationDataContext.DBConnectionString))
- {
- locationItem = db.Locations.Where(location => location.IsSelected).FirstOrDefault();
- locationItem.LastRemoteDataUpdate = DateTime.UtcNow;
- db.SubmitChanges();
- }
+ await GetRemoteDataAndUpdateUI(locationItem);
}
+ else
+ {
+ this.CurrentData.Visibility = Visibility.Visible;
+ this.ForecastData.Visibility = Visibility.Visible;
+ this.ProgressBarRemoteData.Visibility = Visibility.Collapsed;
+ this.NoDataAvailable.Visibility = Visibility.Collapsed;
- // Call UpdateUI on the UI thread.
- // Without ConfigureAwait(false) await returns data on the calling thread. In this case the calling one
- // is the UI thread. So, I can save the call to Dispatcher.BeginInvoke.
- //Dispatcher.BeginInvoke(() => UpdateUI());
- UpdateUI();
+ UpdateUI(weatherData);
+ }
}
- void UpdateUI()
+ private void UpdateUI(WeatherData weatherData)
{
- // Set the ApplicationData and ApplicationDataStatus members of the ViewModel
- WeatherData weatherData = (Application.Current as WeatherInformation.App).ApplicationDataObject;
-
if (weatherData != null)
{
_mainViewModel.LoadData(weatherData);
}
}
+ async private Task GetRemoteDataAndUpdateUI(Location locationItem)
+ {
+ // Load remote data (aynchronous way by means of async/await)
+ try
+ {
+ // Without ConfigureAwait(false) await returns data on the calling thread.
+ WeatherData weatherData = await GetRemoteDataAsync(locationItem);
+
+ this.CurrentData.Visibility = Visibility.Visible;
+ this.ForecastData.Visibility = Visibility.Visible;
+ this.ProgressBarRemoteData.Visibility = Visibility.Collapsed;
+ this.NoDataAvailable.Visibility = Visibility.Collapsed;
+
+ UpdateUI(weatherData);
+
+ (Application.Current as WeatherInformation.App).ApplicationDataObject = weatherData;
+
+ using (var db = new LocationDataContext(LocationDataContext.DBConnectionString))
+ {
+ locationItem = db.Locations.Where(location => location.IsSelected).FirstOrDefault();
+ locationItem.LastRemoteDataUpdate = DateTime.UtcNow;
+ db.SubmitChanges();
+ }
+ }
+ catch(Exception e)
+ {
+ // Empty UI and show error message
+ this.CurrentData.Visibility = Visibility.Collapsed;
+ this.ForecastData.Visibility = Visibility.Collapsed;
+ this.ProgressBarRemoteData.Visibility = Visibility.Collapsed;
+ this.NoDataAvailable.Visibility = Visibility.Visible;
+ }
+
+ }
+
private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
LongListSelector longListSelector = sender as LongListSelector;
NavigationService.Navigate(new Uri("/SettingsPage.xaml", UriKind.Relative));
}
- private void CreateFlipTile()
- {
- ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault(
- x => x.NavigationUri.ToString().Contains("flip"));
- tile = ShellTile.ActiveTiles.First();
- var activeTiles = ShellTile.ActiveTiles;
-
- var tileData = new FlipTileData();
- tileData.Title = "GUSTAVO RULES";
- tileData.BackTitle = "Gustavo Rules Back";
- tileData.BackContent = "Gustavo Back Content";
- tileData.WideBackContent = "Gustavo Wid Back Content";
- tile.Update(tileData);
-
- }
-
// Código de ejemplo para compilar una ApplicationBar traducida
//private void BuildLocalizedApplicationBar()
//{