Bugfixes and start to route navigation

This commit is contained in:
2015-12-18 13:08:33 +01:00
parent 8692073e73
commit e81007e9ec
10 changed files with 148 additions and 26 deletions
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
namespace NavCityBreda.Helpers
{
class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if ((bool)value)
return Visibility.Visible;
else
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
if (((Visibility)value) == Visibility.Visible)
return true;
else
return false;
}
}
}
+2 -2
View File
@@ -88,7 +88,7 @@ namespace NavCityBreda
{ {
while (App.RouteManager.LoadingElement != "Done") while (App.RouteManager.LoadingElement != "Done")
{ {
await Task.Delay(TimeSpan.FromMilliseconds(500)); await Task.Delay(TimeSpan.FromMilliseconds(150));
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{ {
splashProgressText.Text = App.RouteManager.LoadingElement; splashProgressText.Text = App.RouteManager.LoadingElement;
@@ -97,7 +97,7 @@ namespace NavCityBreda
while (App.Geo.Connected == null) while (App.Geo.Connected == null)
{ {
await Task.Delay(TimeSpan.FromMilliseconds(250)); await Task.Delay(TimeSpan.FromMilliseconds(150));
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{ {
splashProgressText.Text = "Waiting on GPS..."; splashProgressText.Text = "Waiting on GPS...";
+34 -7
View File
@@ -5,6 +5,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Windows.Devices.Geolocation;
namespace NavCityBreda.Model namespace NavCityBreda.Model
{ {
@@ -18,11 +19,31 @@ namespace NavCityBreda.Model
public string LoadingElement; public string LoadingElement;
public enum State { STOPPED, STARTED }
public State RouteState;
private List<Geoposition> _history;
public List<Geoposition> History
{
get
{
return _history;
}
}
public RouteManager() public RouteManager()
{ {
_routes = new List<Route>(); _routes = new List<Route>();
LoadingElement = "Initializing..."; LoadingElement = "Initializing...";
RouteState = State.STOPPED;
LoadRoutes(); LoadRoutes();
App.Geo.PositionChanged += Geo_PositionChanged;
}
private void Geo_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
if (RouteState == State.STARTED)
_history.Add(args.Position);
} }
private async void LoadRoutes() private async void LoadRoutes()
@@ -37,20 +58,26 @@ namespace NavCityBreda.Model
LoadingElement = "Loading " + r.Name + "..."; LoadingElement = "Loading " + r.Name + "...";
await r.CalculateRoute(); await r.CalculateRoute();
_routes.Add(r); _routes.Add(r);
await Task.Delay(TimeSpan.FromMilliseconds(250));
} }
LoadingElement = "Done"; LoadingElement = "Done";
} }
public void SetCurrentRoute(int index) public void StartRoute(Route r)
{
_currentroute = _routes.ElementAt(index);
}
public void SetCurrentRoute(Route r)
{ {
_currentroute = r; _currentroute = r;
RouteState = State.STARTED;
}
public void StopRoute()
{
if (RouteState == State.STARTED)
{
_currentroute = null;
RouteState = State.STOPPED;
}
_history.Clear();
} }
} }
} }
+1
View File
@@ -121,6 +121,7 @@
<Compile Include="Helpers\Extensions.cs" /> <Compile Include="Helpers\Extensions.cs" />
<Compile Include="Helpers\JSONParser.cs" /> <Compile Include="Helpers\JSONParser.cs" />
<Compile Include="Helpers\Settings.cs" /> <Compile Include="Helpers\Settings.cs" />
<Compile Include="Helpers\BoolToVisibilityConverter.cs" />
<Compile Include="Helpers\Util.cs" /> <Compile Include="Helpers\Util.cs" />
<Compile Include="InitPage.xaml.cs"> <Compile Include="InitPage.xaml.cs">
<DependentUpon>InitPage.xaml</DependentUpon> <DependentUpon>InitPage.xaml</DependentUpon>
+5 -2
View File
@@ -4,7 +4,7 @@
<mp:PhoneIdentity PhoneProductId="4786ea01-1db5-4c7a-a158-af0ee49306fa" PhonePublisherId="00000000-0000-0000-0000-000000000000" /> <mp:PhoneIdentity PhoneProductId="4786ea01-1db5-4c7a-a158-af0ee49306fa" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties> <Properties>
<DisplayName>NavCityBreda</DisplayName> <DisplayName>NavCityBreda</DisplayName>
<PublisherDisplayName>kenny</PublisherDisplayName> <PublisherDisplayName>Nav City Breda A4</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo> <Logo>Assets\StoreLogo.png</Logo>
</Properties> </Properties>
<Dependencies> <Dependencies>
@@ -15,10 +15,13 @@
</Resources> </Resources>
<Applications> <Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="NavCityBreda.App"> <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="NavCityBreda.App">
<uap:VisualElements DisplayName="NavCityBreda" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="NavCityBreda" BackgroundColor="transparent"> <uap:VisualElements DisplayName="Nav City Breda" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="Tourist navigation app for the cirty Breda." BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" ShortName="ags_logo"> <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" ShortName="ags_logo">
</uap:DefaultTile> </uap:DefaultTile>
<uap:SplashScreen Image="Assets\SplashScreen.png" BackgroundColor="white" /> <uap:SplashScreen Image="Assets\SplashScreen.png" BackgroundColor="white" />
<uap:InitialRotationPreference>
<uap:Rotation Preference="portrait" />
</uap:InitialRotationPreference>
</uap:VisualElements> </uap:VisualElements>
</Application> </Application>
</Applications> </Applications>
+38 -4
View File
@@ -2,6 +2,7 @@
using NavCityBreda.Model; using NavCityBreda.Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -10,7 +11,7 @@ using Windows.UI.Xaml;
namespace NavCityBreda.ViewModel namespace NavCityBreda.ViewModel
{ {
public class RouteDetailVM public class RouteDetailVM : INotifyPropertyChanged
{ {
Route route; Route route;
@@ -31,10 +32,13 @@ namespace NavCityBreda.ViewModel
{ {
get get
{ {
int hours = route.Minutes / 60; TimeSpan length = route.RouteObject.EstimatedDuration;
int minutes = route.Minutes % 60; return length.Hours + "h " + length.Minutes + "m";
return hours + "h " + minutes + "m"; //int hours = route.Minutes / 60;
//int minutes = route.Minutes % 60;
//return hours + "h " + minutes + "m";
} }
} }
@@ -64,5 +68,35 @@ namespace NavCityBreda.ViewModel
return route.Waypoints.Where(p => p is Landmark).Cast<Landmark>().ToList(); return route.Waypoints.Where(p => p is Landmark).Cast<Landmark>().ToList();
} }
} }
public bool StartEnabled
{
get
{
return App.RouteManager.CurrentRoute != route;
}
}
public bool StopEnabled
{
get
{
return !StartEnabled;
}
}
public void UpdateRoute()
{
NotifyPropertyChanged(nameof(StartEnabled));
NotifyPropertyChanged(nameof(StopEnabled));
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void NotifyPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
} }
} }
+11 -1
View File
@@ -13,6 +13,16 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<map:MapControl Grid.Row="0" Name="Map" MapElementClick="Map_MapElementClick" ZoomInteractionMode="GestureAndControl" PedestrianFeaturesVisible="True" PanInteractionMode="Auto" TiltInteractionMode="ControlOnly" RotateInteractionMode="GestureAndControl" MapServiceToken="74Y70e71HVjjN7lnx4Eh~3wugTlBDe2DbPGuR_AM2aA~AjMbg-pU2qn4gYf97oH0GZI1oY9Jc4vH-4WyIRyoYQM0Q71CnfbWalEN37bdSgms" /> <map:MapControl Grid.Row="0" Name="Map" MapElementClick="Map_MapElementClick" ZoomInteractionMode="GestureAndControl" PedestrianFeaturesVisible="True" PanInteractionMode="Auto" TiltInteractionMode="ControlOnly" RotateInteractionMode="GestureAndControl" MapServiceToken="74Y70e71HVjjN7lnx4Eh~3wugTlBDe2DbPGuR_AM2aA~AjMbg-pU2qn4gYf97oH0GZI1oY9Jc4vH-4WyIRyoYQM0Q71CnfbWalEN37bdSgms">
<!-- <map:MapItemsControl x:Name="MapItems">
<Button x:Name="MapItemButton" Background="Transparent">
<StackPanel>
<Border Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" />
<Ellipse Margin="4" Width="40" Height="20" Fill="{ThemeResource ApplicationPageBackgroundThemeBrush}">
</Ellipse>
</StackPanel>
</Button>
</map:MapItemsControl> -->
</map:MapControl>
</Grid> </Grid>
</Page> </Page>
+8 -4
View File
@@ -53,6 +53,11 @@ namespace NavCityBreda.Views
{ {
if (App.RouteManager.CurrentRoute != null) if (App.RouteManager.CurrentRoute != null)
DrawRoute(); DrawRoute();
else
{
Map.MapElements.Clear();
Map.MapElements.Add(CurrentPosition);
}
} }
private void DrawRoute() private void DrawRoute()
@@ -91,15 +96,14 @@ namespace NavCityBreda.Views
Map.MapElements.Add(CurrentPosition); Map.MapElements.Add(CurrentPosition);
CurrentPosition.Location = p; CurrentPosition.Location = p;
if ((bool)Settings.LOCAL_SETTINGS.Values["track"]) ; if ((bool)Settings.LOCAL_SETTINGS.Values["track"])
Zoom(); Zoom();
} }
private async void Zoom() private async void Zoom()
{ {
await Task.Delay(TimeSpan.FromSeconds(1)); await Task.Delay(TimeSpan.FromSeconds(1));
await Map.TrySetViewAsync(CurrentPosition.Location); await Map.TrySetViewAsync(CurrentPosition.Location, 15, 0, 0, MapAnimationKind.Linear);
Map.ZoomLevel = 14;
} }
private async void ZoomRoute() private async void ZoomRoute()
@@ -113,7 +117,7 @@ namespace NavCityBreda.Views
MapIcon i = args.MapElements.Where(p => p is MapIcon).Cast<MapIcon>().First(); MapIcon i = args.MapElements.Where(p => p is MapIcon).Cast<MapIcon>().First();
Waypoint w = App.RouteManager.CurrentRoute.Get(i); Waypoint w = App.RouteManager.CurrentRoute.Get(i);
if (!(w is Landmark)) if (w == null || !(w is Landmark))
return; return;
Landmark l = w as Landmark; Landmark l = w as Landmark;
+8 -3
View File
@@ -12,6 +12,7 @@
<Page.Resources> <Page.Resources>
<convert:BoolToCheckmarkConverter x:Key="BoolConverter"/> <convert:BoolToCheckmarkConverter x:Key="BoolConverter"/>
<convert:BoolToVisibilityConverter x:Key="VisConverter"/>
</Page.Resources> </Page.Resources>
<ScrollViewer> <ScrollViewer>
@@ -25,6 +26,9 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<map:MapControl Grid.Row="0" Name="Map" ZoomInteractionMode="Disabled" RotateInteractionMode="Disabled" TiltInteractionMode="Disabled" PanInteractionMode="Disabled" MapServiceToken="74Y70e71HVjjN7lnx4Eh~3wugTlBDe2DbPGuR_AM2aA~AjMbg-pU2qn4gYf97oH0GZI1oY9Jc4vH-4WyIRyoYQM0Q71CnfbWalEN37bdSgms"/> <map:MapControl Grid.Row="0" Name="Map" ZoomInteractionMode="Disabled" RotateInteractionMode="Disabled" TiltInteractionMode="Disabled" PanInteractionMode="Disabled" MapServiceToken="74Y70e71HVjjN7lnx4Eh~3wugTlBDe2DbPGuR_AM2aA~AjMbg-pU2qn4gYf97oH0GZI1oY9Jc4vH-4WyIRyoYQM0Q71CnfbWalEN37bdSgms"/>
<StackPanel Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Transparent">
<!-- Nothing here -->
</StackPanel>
<Grid Grid.Row="1" Margin="10"> <Grid Grid.Row="1" Margin="10">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
@@ -42,9 +46,10 @@
</StackPanel> </StackPanel>
</Grid> </Grid>
<StackPanel Grid.Row="2" Margin="10"> <StackPanel Grid.Row="2" Margin="10" Visibility="Visible">
<Button Name="StartRouteButton" Click="StartRouteButton_Click" Content="Start Route" Background="DarkGreen" Foreground="White" HorizontalAlignment="Stretch" /> <Button Name="StartRouteButton" Click="StartRouteButton_Click" Content="Start Route" Background="DarkGreen" Foreground="White" HorizontalAlignment="Stretch" Visibility="{Binding StartEnabled, Converter={StaticResource VisConverter}}"/>
</StackPanel> <Button Name="StopRouteButton" Click="StopRouteButton_Click" Content="Stop Route" Background="DarkRed" Foreground="White" HorizontalAlignment="Stretch" Visibility="{Binding StopEnabled, Converter={StaticResource VisConverter}}"/>
</StackPanel>
<StackPanel Grid.Row="3" Margin="10"> <StackPanel Grid.Row="3" Margin="10">
<TextBlock Text="[WaypointDescription]" x:Uid="WaypointDescription" Style="{StaticResource Header}"/> <TextBlock Text="[WaypointDescription]" x:Uid="WaypointDescription" Style="{StaticResource Header}"/>
+12 -3
View File
@@ -31,6 +31,7 @@ namespace NavCityBreda.Views
public sealed partial class RouteDetailView : Page public sealed partial class RouteDetailView : Page
{ {
private Route route; private Route route;
private RouteDetailVM vm;
public RouteDetailView() public RouteDetailView()
{ {
@@ -41,15 +42,17 @@ namespace NavCityBreda.Views
protected override void OnNavigatedTo(NavigationEventArgs e) protected override void OnNavigatedTo(NavigationEventArgs e)
{ {
Route r = e.Parameter as Route; Route r = e.Parameter as Route;
if (r == route) if (r == route)
{ {
vm.UpdateRoute();
LandmarkList.SelectedIndex = -1; LandmarkList.SelectedIndex = -1;
return; return;
} }
route = r; route = r;
vm = new RouteDetailVM(route);
this.DataContext = new RouteDetailVM(route); this.DataContext = vm;
Util.MainPage.Title = route.Name; Util.MainPage.Title = route.Name;
Zoom(); Zoom();
@@ -82,7 +85,13 @@ namespace NavCityBreda.Views
private void StartRouteButton_Click(object sender, RoutedEventArgs e) private void StartRouteButton_Click(object sender, RoutedEventArgs e)
{ {
App.RouteManager.SetCurrentRoute(route); App.RouteManager.StartRoute(route);
Util.MainPage.Navigate(typeof(MapView));
}
private void StopRouteButton_Click(object sender, RoutedEventArgs e)
{
App.RouteManager.StartRoute(null);
Util.MainPage.Navigate(typeof(MapView)); Util.MainPage.Navigate(typeof(MapView));
} }
} }