Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Mejora de rendimiento general.

Añadida barra de progreso y carga localizada de paradas de bus
  • Loading branch information...
commit b3ee62898f59d9a76abb1a096b8c2e7090a4cf65 1 parent 05b9bad
@hbiarge authored
View
42 Arosbi.DnDZgZ.UI/BusesPage.xaml
@@ -1,4 +1,5 @@
-<phone:PhoneApplicationPage
+<phone:PhoneApplicationPage
+ xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
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"
@@ -15,8 +16,7 @@
d:DesignHeight="696"
SupportedOrientations="PortraitOrLandscape"
Orientation="Portrait"
- shell:SystemTray.IsVisible="True"
- >
+ shell:SystemTray.IsVisible="false">
<phone:PhoneApplicationPage.Resources>
<c4f:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</phone:PhoneApplicationPage.Resources>
@@ -50,13 +50,17 @@
</phone:PhoneApplicationPage.ApplicationBar>
<Grid x:Name="LayoutRoot" Background="Black">
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto"/>
+ <RowDefinition/>
+ </Grid.RowDefinitions>
- <Grid x:Name="Popup" Background="#99000000" Canvas.ZIndex="1" Visibility="{Binding ShowBusStopDetail, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}">
- <i:Interaction.Triggers>
- <i:EventTrigger EventName="Tap">
- <mvvm:EventToCommand Command="{Binding ClosePopupCommand, Mode=OneWay}"/>
- </i:EventTrigger>
- </i:Interaction.Triggers>
+ <Grid x:Name="Popup" Background="#99000000" Canvas.ZIndex="1" Visibility="{Binding ShowBusStopDetail, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}" Grid.RowSpan="2">
+ <i:Interaction.Triggers>
+ <i:EventTrigger EventName="Tap">
+ <mvvm:EventToCommand Command="{Binding ClosePopupCommand, Mode=OneWay}"/>
+ </i:EventTrigger>
+ </i:Interaction.Triggers>
<ListBox x:Name="ListaTiempos"
ItemsSource="{Binding CurrentBusStopDetail.Timelines}" Padding="20" d:LayoutOverrides="Width, Height" HorizontalAlignment="Center" Margin="0,50">
<ListBox.ItemTemplate>
@@ -85,13 +89,23 @@
</TextBlock>
</Grid>
+ <Grid x:Name="ProgressBarGrid" Visibility="{Binding IsDoingAsyncWork, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="Auto"/>
+ <ColumnDefinition/>
+ </Grid.ColumnDefinitions>
+ <TextBlock Grid.Column="0" TextWrapping="Wrap" Text="{Binding AsyncMessage, Mode=OneWay}"/>
+ <toolkit:PerformanceProgressBar Grid.Column="1" Margin="20,0,10,0" IsIndeterminate="{Binding IsDoingAsyncWork, Mode=OneWay}" />
+ </Grid>
+
<Border x:Name="MapView"
- BorderBrush="Black">
+ BorderBrush="Black" Grid.Row="1">
<maps:Map x:Name="Map"
- CredentialsProvider="{Binding CredentialsProvider, Mode=OneWay}"
- CopyrightVisibility="Collapsed" LogoVisibility="Collapsed"
- ZoomLevel="{Binding ZoomLevel, Mode=TwoWay}"
- Center="{Binding Center, Mode=TwoWay}" ScaleVisibility="Visible" ZoomBarVisibility="Collapsed">
+ CredentialsProvider="{Binding CredentialsProvider, Mode=OneWay}"
+ CopyrightVisibility="Collapsed" LogoVisibility="Collapsed"
+ ZoomLevel="{Binding ZoomLevel, Mode=TwoWay}"
+ Center="{Binding Center, Mode=TwoWay}" ScaleVisibility="Visible" ZoomBarVisibility="Collapsed"
+ ViewChangeEnd="MapViewChangeEnd">
<maps:Map.Mode>
<maps:RoadMode />
View
15 Arosbi.DnDZgZ.UI/BusesPage.xaml.cs
@@ -3,6 +3,7 @@
using Arosbi.DnDZgZ.UI.ViewModel;
using Microsoft.Phone.Controls;
+ using Microsoft.Phone.Controls.Maps;
/// <summary>
/// Description for BusesPage.
@@ -28,5 +29,19 @@ private void ApplicationBarIconButtonClick(object sender, System.EventArgs e)
vm.CurrentLocationCommand.Execute(null);
}
+
+ private void MapViewChangeEnd(object sender, MapEventArgs e)
+ {
+ var vm = DataContext as BusesViewModel;
+
+ if (vm == null)
+ {
+ return;
+ }
+
+ var targetBoundingRectangle = this.Map.TargetBoundingRectangle;
+
+ vm.LoadBusStopsInExtents(targetBoundingRectangle);
+ }
}
}
View
7 Arosbi.DnDZgZ.UI/Model/PushpinModel.cs
@@ -3,12 +3,17 @@
using System;
using System.Device.Location;
- public class PushpinModel
+ public class PushpinModel : IEquatable<PushpinModel>
{
public GeoCoordinate Location { get; set; }
public Uri Icon { get; set; }
public string Id { get; set; }
+
+ public bool Equals(PushpinModel other)
+ {
+ return this.Id.Equals(other.Id);
+ }
}
}
View
147 Arosbi.DnDZgZ.UI/ViewModel/BusesViewModel.cs
@@ -1,7 +1,7 @@
namespace Arosbi.DnDZgZ.UI.ViewModel
{
using System;
- using System.Collections.ObjectModel;
+ using System.Collections.Generic;
using System.Device.Location;
using System.Linq;
using System.Windows.Input;
@@ -14,6 +14,9 @@
using Microsoft.Phone.Controls.Maps;
+ using WP7Contrib.Collections;
+ using WP7Contrib.Common.Extensions;
+
using ILocationService = WP7Contrib.Services.Location.ILocationService;
public class BusesViewModel : ViewModelBase
@@ -28,9 +31,11 @@ public class BusesViewModel : ViewModelBase
private readonly IRepository repository;
- private readonly ObservableCollection<PushpinModel> busStops = new ObservableCollection<PushpinModel>();
+ private readonly TrickleAllToCollection<PushpinModel> trikler;
+
+ private readonly List<PushpinModel> cachedBusStops = new List<PushpinModel>();
- private IDisposable locationSuscription;
+ private readonly ObservableCollection<PushpinModel> showedBusStops = new ObservableCollection<PushpinModel>();
private RelayCommand zoomInCommand;
@@ -43,7 +48,7 @@ public class BusesViewModel : ViewModelBase
private RelayCommand closePopupCommand;
private RelayCommand loadedCommand;
-
+
private RelayCommand unloadedCommand;
private double zoomLevelLevel;
@@ -56,6 +61,10 @@ public class BusesViewModel : ViewModelBase
private BusStopDetail currentBusStopDetail;
+ private string asyncMessage;
+
+ private bool isDoingAsyncWork;
+
public BusesViewModel(ILocationService locationService, IRepository repository)
{
if (locationService == null)
@@ -87,11 +96,13 @@ public BusesViewModel(ILocationService locationService, IRepository repository)
this.locationService = locationService;
this.repository = repository;
+ this.trikler = new TrickleAllToCollection<PushpinModel>(
+ () => this.ToString(),
+ () => this.ToString());
- this.locationSuscription = locationService.Location()
+ locationService.Location()
.Subscribe(
- location => this.CurrentLocation = this.Center = location,
- () => this.locationSuscription.Dispose());
+ location => this.CurrentLocation = this.Center = location);
this.ZoomLevel = DefaultZoomLevel;
this.Center = this.GetCenter();
@@ -154,11 +165,11 @@ public GeoCoordinate Center
}
}
- public ObservableCollection<PushpinModel> BusStops
+ public System.Collections.ObjectModel.ObservableCollection<PushpinModel> BusStops
{
get
{
- return this.busStops;
+ return this.showedBusStops;
}
}
@@ -232,10 +243,16 @@ public ICommand CurrentLocationCommand
this.currentLocationCommand = new RelayCommand(
() =>
{
- this.locationSuscription = this.locationService.Location()
+ this.AsyncMessage = "Oteniendo posición...";
+ this.IsDoingAsyncWork = true;
+
+ this.locationService.Location()
.Subscribe(
- location => this.CurrentLocation = this.Center = location,
- () => this.locationSuscription.Dispose());
+ location =>
+ {
+ this.IsDoingAsyncWork = false;
+ this.CurrentLocation = this.Center = location;
+ });
});
}
@@ -250,13 +267,21 @@ public ICommand PushpinCommand
if (this.busStopDetailCommand == null)
{
this.busStopDetailCommand = new RelayCommand<string>(
- p => this.repository.GetBusStopDetails(
- p,
- busDetail =>
- {
- this.CurrentBusStopDetail = busDetail;
- this.ShowBusStopDetail = true;
- }));
+ busStopId =>
+ {
+ this.AsyncMessage = string.Format("Cargando poste {0}...", busStopId);
+ this.IsDoingAsyncWork = true;
+
+ this.repository.GetBusStopDetails(
+ busStopId,
+ busDetail =>
+ {
+ this.IsDoingAsyncWork = false;
+
+ this.CurrentBusStopDetail = busDetail;
+ this.ShowBusStopDetail = true;
+ });
+ });
}
return this.busStopDetailCommand;
@@ -269,7 +294,11 @@ public ICommand ClosePopupCommand
{
if (this.closePopupCommand == null)
{
- this.closePopupCommand = new RelayCommand(() => this.ShowBusStopDetail = false);
+ this.closePopupCommand = new RelayCommand(() =>
+ {
+ this.CurrentBusStopDetail = null;
+ this.ShowBusStopDetail = false;
+ });
}
return this.closePopupCommand;
@@ -282,7 +311,7 @@ public ICommand LoadedCommand
{
if (this.loadedCommand == null)
{
- this.loadedCommand = new RelayCommand(this.GetBusStops);
+ this.loadedCommand = new RelayCommand(() => this.ToString());
}
return this.loadedCommand;
@@ -302,24 +331,86 @@ public ICommand UnloadedCommand
}
}
- private void GetBusStops()
+ public string AsyncMessage
+ {
+ get
+ {
+ return this.asyncMessage;
+ }
+ internal set
+ {
+ this.asyncMessage = value;
+ RaisePropertyChanged("AsyncMessage");
+ }
+ }
+
+ public bool IsDoingAsyncWork
+ {
+ get
+ {
+ return this.isDoingAsyncWork;
+ }
+ internal set
+ {
+ this.isDoingAsyncWork = value;
+ RaisePropertyChanged("IsDoingAsyncWork");
+ }
+ }
+
+ public void LoadBusStopsInExtents(LocationRect extents)
+ {
+ if (this.cachedBusStops.Count == 0)
+ {
+ this.GetBusStops(extents, this.LoadBusStopsInExtentsImpl);
+ }
+ else
+ {
+ this.LoadBusStopsInExtentsImpl(extents);
+ }
+ }
+
+ private void GetBusStops(LocationRect extents, Action<LocationRect> callback)
{
this.repository.GetBusStops(buses =>
{
- var pushpins = buses
+ var busStops = buses
.Select(b => new PushpinModel
{
Location = new GeoCoordinate(b.Lat, b.Lon),
Id = b.Id
- });
+ });
- foreach (var pushpin in pushpins)
- {
- this.busStops.Add(pushpin);
- }
+ this.cachedBusStops.AddRange(busStops);
+ callback(extents);
});
}
+ private void LoadBusStopsInExtentsImpl(LocationRect extents)
+ {
+ this.trikler.Stop();
+
+ // All the pins to add to the map control...
+ var allPinsToAdd = this.cachedBusStops
+ .Where(bs => (bs.Location.Latitude <= extents.North) &&
+ (bs.Location.Latitude >= extents.South) &&
+ (bs.Location.Longitude >= extents.West) &&
+ (bs.Location.Longitude <= extents.East)).ToArray();
+
+ // All the pins already added to the map control we want to keep...
+ var alreadyAdded = allPinsToAdd.Intersect(this.showedBusStops).ToArray();
+
+ // The new pins to be added to the mapp control...
+ var pinsToAdd = allPinsToAdd.Except(alreadyAdded).ToArray();
+
+ // The existing pins to be removed which aren't visible...
+ var pinsToRemove = this.showedBusStops.Except(alreadyAdded).ToArray();
+
+ // Remove the pins...
+ pinsToRemove.ForEach(p => this.showedBusStops.Remove(p));
+
+ this.trikler.Start(10, pinsToAdd, this.showedBusStops);
+ }
+
private GeoCoordinate GetCenter()
{
if (this.currentLocation != null)
View
8 Arosbi.DnDZgZ.UI/ViewModel/ViewModelLocator.cs
@@ -20,6 +20,9 @@
public class ViewModelLocator
{
+ //private const string MapId = "";
+ private const string MapId = "replace-with-your-private-key";
+
internal static readonly CredentialsProvider CredentialsProvider = new ApplicationIdCredentialsProvider(MapId);
internal static readonly GeoCoordinate DefaultLocation = new GeoCoordinate(41.6521, -0.8809);
@@ -29,9 +32,7 @@ public class ViewModelLocator
internal static readonly Uri WifiPage = new Uri("/WifisPage.xaml", UriKind.Relative);
private static Funq.Container container;
-
- private const string MapId = "replace-with-your-private-key";
-
+
private static MainViewModel main;
private static BusesViewModel buses;
@@ -164,7 +165,6 @@ private static void InitializeContainer()
new ApplicationFrameNavigationService(((App)Application.Current).RootFrame))
.ReusedWithin(ReuseScope.Container);
-
container.Register<ILocationService>(c => new LocationService(
GeoPositionAccuracy.Default,
container.Resolve<ILog>()));
Please sign in to comment.
Something went wrong with that request. Please try again.