Added skipping of landmarks. Better navigation through waypoints.

This commit is contained in:
2015-12-26 13:03:41 +01:00
parent dc0c162f70
commit 24e3a5240d
19 changed files with 197 additions and 63 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

@@ -7,14 +7,18 @@ namespace NavCityBreda.Helpers.Comparer
{ {
public int Compare(Landmark x, Landmark y) public int Compare(Landmark x, Landmark y)
{ {
if (x.Visited == y.Visited) if (x.Status == y.Status)
{
return x.Name.CompareTo(y.Name); return x.Name.CompareTo(y.Name);
} else if (x.Status == Landmark.LandmarkStatus.VISITED)
else if (x.Visited)
return 1; return 1;
else else if (y.Status == Landmark.LandmarkStatus.VISITED)
return -1; return -1;
else if (x.Status == Landmark.LandmarkStatus.SKIPPED)
return 1;
else if (y.Status == Landmark.LandmarkStatus.SKIPPED)
return -1;
else
return 1;
} }
} }
} }
@@ -7,14 +7,18 @@ namespace NavCityBreda.Helpers.Comparer
{ {
public int Compare(Landmark x, Landmark y) public int Compare(Landmark x, Landmark y)
{ {
if (x.Visited == y.Visited) if (x.Status == y.Status)
{
return x.Name.CompareTo(y.Name); return x.Name.CompareTo(y.Name);
} else if (x.Status == Landmark.LandmarkStatus.VISITED)
else if (x.Visited)
return -1; return -1;
else else if (y.Status == Landmark.LandmarkStatus.VISITED)
return 1; return 1;
else if (x.Status == Landmark.LandmarkStatus.SKIPPED)
return -1;
else if (y.Status == Landmark.LandmarkStatus.SKIPPED)
return 1;
else
return -1;
} }
} }
} }
@@ -1,23 +0,0 @@
using System;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
namespace NavCityBreda.Helpers.Converter
{
class BoolToIconConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if ((bool)value)
return Symbol.Like;
else
return Symbol.Cancel;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
//Not implemented
return null;
}
}
}
@@ -0,0 +1,31 @@
using System;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
namespace NavCityBreda.Helpers.Converter
{
class StatusToIconConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
Model.Landmark.LandmarkStatus st = (Model.Landmark.LandmarkStatus)value;
switch(st)
{
default:
case Model.Landmark.LandmarkStatus.NOTVISITED:
return Symbol.Cancel;
case Model.Landmark.LandmarkStatus.VISITED:
return Symbol.Accept;
case Model.Landmark.LandmarkStatus.SKIPPED:
return Symbol.Forward;
}
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
//Not implemented
return null;
}
}
}
+6
View File
@@ -306,4 +306,10 @@
<data name="SortOrder" xml:space="preserve"> <data name="SortOrder" xml:space="preserve">
<value>Sort Order</value> <value>Sort Order</value>
</data> </data>
<data name="SkipLandmark" xml:space="preserve">
<value>Skip landmark</value>
</data>
<data name="Skipped" xml:space="preserve">
<value>Skipped</value>
</data>
</root> </root>
+6
View File
@@ -306,4 +306,10 @@
<data name="SortOrder" xml:space="preserve"> <data name="SortOrder" xml:space="preserve">
<value>Sorteer volgorde</value> <value>Sorteer volgorde</value>
</data> </data>
<data name="SkipLandmark" xml:space="preserve">
<value>Bezienswaardigheid overslaan</value>
</data>
<data name="Skipped" xml:space="preserve">
<value>Overgeslagen</value>
</data>
</root> </root>
+20 -9
View File
@@ -15,13 +15,15 @@ namespace NavCityBreda.Model
public List<Image> Images { get; private set; } public List<Image> Images { get; private set; }
private bool _visited; public enum LandmarkStatus { NOTVISITED, VISITED, SKIPPED }
public bool Visited
private LandmarkStatus _status;
public LandmarkStatus Status
{ {
get { return _visited; } get { return _status; }
set set
{ {
_visited = value; _status = value;
UpdateIcon(); UpdateIcon();
} }
} }
@@ -42,7 +44,7 @@ namespace NavCityBreda.Model
private void Create(string name, string desc, int num, List<Image> images) private void Create(string name, string desc, int num, List<Image> images)
{ {
_visited = false; _status = LandmarkStatus.NOTVISITED;
_desckey = desc; _desckey = desc;
Images = images; Images = images;
@@ -60,10 +62,19 @@ namespace NavCityBreda.Model
{ {
Icon.Title = Name; Icon.Title = Name;
if(_visited) switch(_status)
Icon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/LandmarkVisited.png")); {
else default:
Icon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/LandmarkNotVisited.png")); case LandmarkStatus.NOTVISITED:
Icon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/LandmarkNotVisited.png"));
break;
case LandmarkStatus.VISITED:
Icon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/LandmarkVisited.png"));
break;
case LandmarkStatus.SKIPPED:
Icon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/LandmarkSkipped.png"));
break;
}
} }
} }
} }
+1 -1
View File
@@ -82,7 +82,7 @@ namespace NavCityBreda.Model
{ {
foreach(Landmark l in Landmarks) foreach(Landmark l in Landmarks)
{ {
l.Visited = false; l.Status = Landmark.LandmarkStatus.NOTVISITED;
await Task.Delay(TimeSpan.FromMilliseconds(2)); await Task.Delay(TimeSpan.FromMilliseconds(2));
} }
return "success"; return "success";
+44 -3
View File
@@ -1,9 +1,11 @@
using NavCityBreda.Helpers; using NavCityBreda.Helpers;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Windows.Devices.Geolocation;
using Windows.Devices.Geolocation.Geofencing; using Windows.Devices.Geolocation.Geofencing;
using Windows.Services.Maps; using Windows.Services.Maps;
using Windows.UI.Core; using Windows.UI.Core;
@@ -138,7 +140,7 @@ namespace NavCityBreda.Model
{ {
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{ {
i.Visited = true; i.Status = Landmark.LandmarkStatus.VISITED;
}); });
_currentlandmark = i; _currentlandmark = i;
LandmarkVisited(i, LandmarkVisitedEventArgs.VisitedStatus.ENTERED); LandmarkVisited(i, LandmarkVisitedEventArgs.VisitedStatus.ENTERED);
@@ -177,21 +179,60 @@ namespace NavCityBreda.Model
public async Task<String> UpdateRoute() public async Task<String> UpdateRoute()
{ {
//Can't navigate without current position
if (App.Geo.Position == null) return "error"; if (App.Geo.Position == null) return "error";
_currentlandmark = _currentroute.Landmarks.FirstOrDefault(p => !p.Visited); //Stop route if end is reached
_routetolandmark = await Util.FindWalkingRoute(App.Geo.Position.Coordinate.Point, _currentlandmark.Position); _currentlandmark = _currentroute.Landmarks.FirstOrDefault(p => p.Status == Landmark.LandmarkStatus.NOTVISITED);
if (_currentlandmark == null)
{
StopRoute();
return "stopped";
}
//Create route from last landmark trough all the waypoints
List<Geopoint> _waypoints = new List<Geopoint>();
_waypoints.Add(App.Geo.Position.Coordinate.Point);
Landmark lastlandmark = _currentroute.Landmarks.ElementAtOrDefault(_currentroute.Landmarks.IndexOf(_currentlandmark) - 1);
if (lastlandmark != null)
{
int start = _currentroute.Waypoints.IndexOf(lastlandmark) + 1;
int offset = _currentroute.Waypoints.IndexOf(_currentlandmark) - start;
List<Geopoint> temp = _currentroute.Waypoints.GetRange(start, offset).Select(e => e.Position).ToList();
_waypoints.AddRange(temp);
}
_waypoints.Add(_currentlandmark.Position);
//Update all other vars to match
//_routetolandmark = await Util.FindWalkingRoute(App.Geo.Position.Coordinate.Point, _currentlandmark.Position);
_routetolandmark = await Util.FindWalkingRoute(_waypoints);
_currentroutelegs = _routetolandmark.Legs.ToList() as List<MapRouteLeg>; _currentroutelegs = _routetolandmark.Legs.ToList() as List<MapRouteLeg>;
_currentroutelegcount = 0; _currentroutelegcount = 0;
_currentmaneuvercount = 0; _currentmaneuvercount = 0;
_currentmaneuver = _currentmaneuvers[_currentmaneuvercount]; _currentmaneuver = _currentmaneuvers[_currentmaneuvercount];
//Send out events
UpdateRoute(_routetolandmark, _currentlandmark); UpdateRoute(_routetolandmark, _currentlandmark);
UpdateManeuver(_currentmaneuver); UpdateManeuver(_currentmaneuver);
return "success"; return "success";
} }
public async Task<String> SkipLandmark()
{
if (Status != RouteStatus.STARTED) return "error";
await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
_currentlandmark.Status = Landmark.LandmarkStatus.SKIPPED;
});
string s = await UpdateRoute();
return s;
}
public async void StartRoute(Route r) public async void StartRoute(Route r)
{ {
App.Geo.ClearHistory(); App.Geo.ClearHistory();
+2 -1
View File
@@ -101,6 +101,7 @@
<Content Include="Assets\LandmarkNotVisited.png"> <Content Include="Assets\LandmarkNotVisited.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Assets\LandmarkSkipped.png" />
<Content Include="Assets\LandmarkVisited.png"> <Content Include="Assets\LandmarkVisited.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
@@ -153,7 +154,7 @@
<Compile Include="Helpers\Comparer\LandmarkAlphaReversedComparer.cs" /> <Compile Include="Helpers\Comparer\LandmarkAlphaReversedComparer.cs" />
<Compile Include="Helpers\Comparer\LandmarkNotVisitedComparer.cs" /> <Compile Include="Helpers\Comparer\LandmarkNotVisitedComparer.cs" />
<Compile Include="Helpers\Comparer\LandmarkVisitedComparer.cs" /> <Compile Include="Helpers\Comparer\LandmarkVisitedComparer.cs" />
<Compile Include="Helpers\Converter\BoolToIconConverter.cs" /> <Compile Include="Helpers\Converter\StatusToIconConverter.cs" />
<Compile Include="Helpers\Extensions.cs" /> <Compile Include="Helpers\Extensions.cs" />
<Compile Include="Helpers\RouteParser.cs" /> <Compile Include="Helpers\RouteParser.cs" />
<Compile Include="Helpers\Settings.cs" /> <Compile Include="Helpers\Settings.cs" />
+35 -6
View File
@@ -25,6 +25,29 @@ namespace NavCityBreda.ViewModels
NotifyPropertyChanged(nameof(Description)); NotifyPropertyChanged(nameof(Description));
} }
public void Skip()
{
NotifyPropertyChanged(nameof(CurrentLandmark));
NotifyPropertyChanged(nameof(IsVisited));
NotifyPropertyChanged(nameof(Visited));
}
public bool CurrentLandmark
{
get
{
return landmark == App.RouteManager.CurrentLandmark;
}
}
public string SkipLandmarkText
{
get
{
return Util.Loader.GetString("SkipLandmark");
}
}
public string Address public string Address
{ {
get get
@@ -41,11 +64,11 @@ namespace NavCityBreda.ViewModels
} }
} }
public bool IsVisited public Landmark.LandmarkStatus IsVisited
{ {
get get
{ {
return landmark.Visited; return landmark.Status;
} }
} }
@@ -53,10 +76,16 @@ namespace NavCityBreda.ViewModels
{ {
get get
{ {
if (landmark.Visited) switch(landmark.Status)
return Util.Loader.GetString("Visited"); {
else default:
return Util.Loader.GetString("NotVisited"); case Landmark.LandmarkStatus.NOTVISITED:
return Util.Loader.GetString("NotVisited");
case Landmark.LandmarkStatus.VISITED:
return Util.Loader.GetString("Visited");
case Landmark.LandmarkStatus.SKIPPED:
return Util.Loader.GetString("Skipped");
}
} }
} }
+1
View File
@@ -1,6 +1,7 @@
using NavCityBreda.Helpers; using NavCityBreda.Helpers;
using NavCityBreda.Helpers.Comparer; using NavCityBreda.Helpers.Comparer;
using NavCityBreda.Model; using NavCityBreda.Model;
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace NavCityBreda.ViewModels namespace NavCityBreda.ViewModels
+7 -1
View File
@@ -89,6 +89,9 @@ namespace NavCityBreda.ViewModels
{ {
get get
{ {
if (route.Landmarks.TrueForAll(lm => lm.Status != Landmark.LandmarkStatus.NOTVISITED))
return false;
return App.RouteManager.CurrentRoute != route; return App.RouteManager.CurrentRoute != route;
} }
} }
@@ -105,7 +108,10 @@ namespace NavCityBreda.ViewModels
{ {
get get
{ {
return !StartEnabled; if (route.Landmarks.TrueForAll(lm => lm.Status != Landmark.LandmarkStatus.NOTVISITED))
return false;
return App.RouteManager.CurrentRoute == route;
} }
} }
+9 -3
View File
@@ -9,12 +9,14 @@
mc:Ignorable="d"> mc:Ignorable="d">
<Page.Resources> <Page.Resources>
<convert:BoolToIconConverter x:Key="BoolConverter"/> <convert:StatusToIconConverter x:Key="IconConverter"/>
<convert:BoolToVisibilityConverter x:Key="VisConverter" />
</Page.Resources> </Page.Resources>
<ScrollViewer> <ScrollViewer>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
@@ -56,14 +58,18 @@
</Viewbox> </Viewbox>
</StackPanel> </StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal"> <StackPanel Grid.Column="1" Orientation="Horizontal">
<SymbolIcon Symbol="{Binding IsVisited, Converter={StaticResource BoolConverter}}" Style="{StaticResource InfoIcon}"/> <SymbolIcon Symbol="{Binding IsVisited, Converter={StaticResource IconConverter}}" Style="{StaticResource InfoIcon}"/>
<Viewbox StretchDirection="DownOnly" Stretch="UniformToFill"> <Viewbox StretchDirection="DownOnly" Stretch="UniformToFill">
<TextBlock Text="{Binding Visited}" Style="{StaticResource InfoText}"/> <TextBlock Text="{Binding Visited}" Style="{StaticResource InfoText}"/>
</Viewbox> </Viewbox>
</StackPanel> </StackPanel>
</Grid> </Grid>
<StackPanel Grid.Row="2" Margin="10"> <StackPanel Grid.Row="2" Margin="10">
<Button Name="Button" Click="Button_Click" Content="{Binding SkipLandmarkText}" Background="DarkRed" Foreground="White" HorizontalAlignment="Stretch" Visibility="{Binding CurrentLandmark, Converter={StaticResource VisConverter}}"/>
</StackPanel>
<StackPanel Grid.Row="3" Margin="10">
<TextBlock Text="{Binding DescriptionTitle}" Style="{StaticResource Header}"/> <TextBlock Text="{Binding DescriptionTitle}" Style="{StaticResource Header}"/>
<TextBlock TextWrapping="WrapWholeWords" Text="{Binding Description}"/> <TextBlock TextWrapping="WrapWholeWords" Text="{Binding Description}"/>
</StackPanel> </StackPanel>
@@ -25,5 +25,16 @@ namespace NavCityBreda.Views
landmarkvm = new LandmarkDetailVM(landmark); landmarkvm = new LandmarkDetailVM(landmark);
this.DataContext = landmarkvm; this.DataContext = landmarkvm;
} }
private void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
Skip();
}
private async void Skip()
{
await App.RouteManager.SkipLandmark();
landmarkvm.Skip();
}
} }
} }
+2 -2
View File
@@ -9,7 +9,7 @@
mc:Ignorable="d"> mc:Ignorable="d">
<Page.Resources> <Page.Resources>
<convert:BoolToIconConverter x:Key="BoolConverter" /> <convert:StatusToIconConverter x:Key="IconConverter" />
</Page.Resources> </Page.Resources>
<ScrollViewer> <ScrollViewer>
@@ -49,7 +49,7 @@
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate x:Name="ListViewDataTemplate"> <DataTemplate x:Name="ListViewDataTemplate">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<SymbolIcon Symbol="{Binding Visited, Converter={StaticResource BoolConverter}}" Margin="0,0,10,0"/> <SymbolIcon Symbol="{Binding Status, Converter={StaticResource IconConverter}}" Margin="0,0,10,0"/>
<TextBlock Text="{Binding Name}" FontSize="18"/> <TextBlock Text="{Binding Name}" FontSize="18"/>
</StackPanel> </StackPanel>
</DataTemplate> </DataTemplate>
+1 -1
View File
@@ -151,7 +151,7 @@ namespace NavCityBreda.Views
foreach (Landmark l in r.Landmarks) foreach (Landmark l in r.Landmarks)
{ {
if (!l.Visited) if (l.Status == Landmark.LandmarkStatus.NOTVISITED)
GeofenceMonitor.Current.Geofences.Add(new Geofence(l.Id, new Geocircle(l.Position.Position, 35), MonitoredGeofenceStates.Entered, true)); GeofenceMonitor.Current.Geofences.Add(new Geofence(l.Id, new Geocircle(l.Position.Position, 35), MonitoredGeofenceStates.Entered, true));
l.UpdateIcon(); l.UpdateIcon();
await Task.Delay(TimeSpan.FromMilliseconds(3)); await Task.Delay(TimeSpan.FromMilliseconds(3));
+3 -3
View File
@@ -11,7 +11,7 @@
mc:Ignorable="d"> mc:Ignorable="d">
<Page.Resources> <Page.Resources>
<convert:BoolToIconConverter x:Key="BoolConverter"/> <convert:StatusToIconConverter x:Key="IconConverter"/>
<convert:BoolToVisibilityConverter x:Key="VisConverter"/> <convert:BoolToVisibilityConverter x:Key="VisConverter"/>
</Page.Resources> </Page.Resources>
@@ -46,7 +46,7 @@
</StackPanel> </StackPanel>
</Grid> </Grid>
<StackPanel Grid.Row="2" Margin="10" Visibility="Visible"> <StackPanel Grid.Row="2" Margin="10">
<Button Click="StartRouteButton_Click" Content="{Binding StartRouteText}" Background="DarkGreen" Foreground="White" HorizontalAlignment="Stretch" Visibility="{Binding StartEnabled, Converter={StaticResource VisConverter}}"/> <Button Click="StartRouteButton_Click" Content="{Binding StartRouteText}" Background="DarkGreen" Foreground="White" HorizontalAlignment="Stretch" Visibility="{Binding StartEnabled, Converter={StaticResource VisConverter}}"/>
<Button Click="StopRouteButton_Click" Content="{Binding StopRouteText}" Background="DarkRed" Foreground="White" HorizontalAlignment="Stretch" Visibility="{Binding StopEnabled, Converter={StaticResource VisConverter}}"/> <Button Click="StopRouteButton_Click" Content="{Binding StopRouteText}" Background="DarkRed" Foreground="White" HorizontalAlignment="Stretch" Visibility="{Binding StopEnabled, Converter={StaticResource VisConverter}}"/>
</StackPanel> </StackPanel>
@@ -64,7 +64,7 @@
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate x:Name="ListViewDataTemplate"> <DataTemplate x:Name="ListViewDataTemplate">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<SymbolIcon Symbol="{Binding Visited, Converter={StaticResource BoolConverter}}" Margin="0,0,10,0"/> <SymbolIcon Symbol="{Binding Status, Converter={StaticResource IconConverter}}" Margin="0,0,10,0"/>
<TextBlock Text="{Binding Name}" FontSize="18"/> <TextBlock Text="{Binding Name}" FontSize="18"/>
</StackPanel> </StackPanel>
</DataTemplate> </DataTemplate>