Exemplo n.º 1
0
 private bool CanPlanTripExecute()
 {
     return(((bool)IsFerryChecked || (bool)IsBusChecked || (bool)IsTramChecked ||
             (bool)IsTrainChecked || (bool)IsMetroChecked || (bool)IsBikeChecked
             ) &&
            FromPlace != null &&
            (IntermediatePlaces.Count == 0 || IntermediatePlaces.All(x => x.IntermediatePlace != null)) &&
            ToPlace != null &&
            !_isBusy);
 }
Exemplo n.º 2
0
        private void SwapIntermediateLocation(IntermediateSearchViewModel obj)
        {
            int    intermediateIndex = IntermediatePlaces.IndexOf(obj);
            IPlace nextPlace;

            //If we're at the end of the list, then we need to swap with the To box
            if (intermediateIndex + 1 < IntermediatePlaces.Count)
            {
                nextPlace = IntermediatePlaces[intermediateIndex + 1].IntermediatePlace;
                IntermediatePlaces[intermediateIndex + 1].IntermediatePlace = obj.IntermediatePlace;
                obj.IntermediatePlace = nextPlace;
            }
            else
            {
                nextPlace             = ToPlace;
                ToPlace               = obj.IntermediatePlace;
                obj.IntermediatePlace = nextPlace;
            }
        }
Exemplo n.º 3
0
        private void SwapFirstLocation()
        {
            IPlace first = FromPlace;
            IPlace nextPlace;

            if (IntermediatePlaces.Count > 0)
            {
                nextPlace = IntermediatePlaces.First().IntermediatePlace;
                FromPlace = nextPlace;
                IntermediatePlaces.First().IntermediatePlace = first;
            }
            //If the list doesn't have any intermediates, then we need to swap with the To box
            else
            {
                nextPlace = ToPlace;
                FromPlace = nextPlace;
                ToPlace   = first;
            }
        }
Exemplo n.º 4
0
        //todo: refactor the favorite/secondary tile stuff to use the same type if possible
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            _favoritesService.FavoritesChanged += FavoritesChanged;

            Views.Busy.BusyCancelled += Busy_BusyCancelled;

            if (mode != NavigationMode.Back)
            {
                //---Plan trip from favorites
                var placeArgs = parameter as NavigateWithFavoritePlaceArgs;
                if (placeArgs != null)
                {
                    if (placeArgs.PlaceNavigationType == NavigationType.AsDestination)
                    {
                        ToPlace = placeArgs.Place;
                    }
                    else if (placeArgs.PlaceNavigationType == NavigationType.AsOrigin)

                    {
                        FromPlace = placeArgs.Place;
                    }
                    else if (placeArgs.PlaceNavigationType == NavigationType.AsIntermediate)
                    {
                        if (placeArgs.IntermediateIndex != null)
                        {
                            IntermediatePlaces.Insert(placeArgs.IntermediateIndex.Value, new IntermediateSearchViewModel(this, placeArgs.Place));
                        }
                    }
                    if (PlanTripCommand.CanExecute(null))
                    {
                        PlanTripCommand.Execute(null);
                    }
                }

                var routeArgs = parameter as FavoriteRoute;
                if (routeArgs != null)
                {
                    var firstPlace = routeArgs.RoutePlaces.First();
                    FromPlace = new Place {
                        Type = PlaceType.Address, Lat = (float)firstPlace.Lat, Lon = (float)firstPlace.Lon, Name = firstPlace.Name
                    };
                    var lastPlace = routeArgs.RoutePlaces.Last();
                    ToPlace = new Place {
                        Type = PlaceType.Address, Lat = (float)lastPlace.Lat, Lon = (float)lastPlace.Lon, Name = lastPlace.Name
                    };
                    if (PlanTripCommand.CanExecute(null))
                    {
                        PlanTripCommand.Execute(null);
                    }
                }

                //---Plan trip from tile
                if (SessionState.ContainsKey(NavParamKeys.SecondaryTilePayload))
                {
                    var secondaryTileArgs = (SecondaryTilePayload)SessionState[NavParamKeys.SecondaryTilePayload];
                    SecondaryTileInvoked(secondaryTileArgs);
                    SessionState.Remove(NavParamKeys.SecondaryTilePayload);
                }
            }

            await FillPinnedFavorites();

            await Task.CompletedTask;
        }
Exemplo n.º 5
0
 private void RemoveIntermediate(IntermediateSearchViewModel obj)
 {
     IntermediatePlaces.Remove(obj);
     PlanTripCommand.RaiseCanExecuteChanged();
 }
Exemplo n.º 6
0
 private void AddIntermediatePlace()
 {
     IntermediatePlaces.Add(new IntermediateSearchViewModel(this));
     PlanTripCommand.RaiseCanExecuteChanged();
 }
Exemplo n.º 7
0
        private async void PlanTrip()
        {
            if (_cts != null && !_cts.IsCancellationRequested)
            {
                _cts.Cancel();
            }
            _cts = new CancellationTokenSource();
            _cts.Token.ThrowIfCancellationRequested();

            try
            {
                SetBusy(true, AppResources.TripFrom_GettingsAddresses);

                List <IPlace> searchPlaces = new List <IPlace> {
                    FromPlace
                };
                if (IntermediatePlaces.Count > 0)
                {
                    searchPlaces.AddRange(IntermediatePlaces.Select(x => x.IntermediatePlace));
                }
                searchPlaces.Add(ToPlace);
                IEnumerable <PlaceResolutionResult> placeResolutionResults = await ResolvePlaces(searchPlaces, _cts.Token);

                if (placeResolutionResults.Any(x => x.IsFailure))
                {
                    await HandlePlaceResolutionFailure(placeResolutionResults.Where(x => x.IsFailure));

                    SetBusy(false);
                    return;
                }
                IEnumerable <IPlace> places = placeResolutionResults.Select(x => x.AttemptedResolvedPlace);

                FromPlace = places.First();
                if (IntermediatePlaces.Any())
                {
                    int intermediateIndex = 0;
                    foreach (IPlace intermediate in places.Skip(1))
                    {
                        if (intermediate == places.Last())
                        {
                            continue;
                        }
                        IntermediatePlaces[intermediateIndex].IntermediatePlace = intermediate;
                    }
                }
                ToPlace = places.Last();

                ApiCoordinates fromCoords = new ApiCoordinates {
                    Lat = (float)FromPlace.Lat, Lon = (float)FromPlace.Lon
                };
                List <ApiCoordinates> intermediateCoords = IntermediatePlaces
                                                           .Select(x => new ApiCoordinates {
                    Lat = (float)x.IntermediatePlace.Lat, Lon = (float)x.IntermediatePlace.Lon
                })
                                                           .ToList();
                ApiCoordinates toCoords = new ApiCoordinates {
                    Lat = (float)ToPlace.Lat, Lon = (float)ToPlace.Lon
                };
                TripQueryDetails details = new TripQueryDetails(
                    fromCoords,
                    FromPlace.Name,
                    intermediateCoords,
                    toCoords,
                    ToPlace.Name,
                    IsUsingCurrentTime ? DateTime.Now.TimeOfDay : SelectedTime,
                    IsUsingCurrentDate ? DateTime.Today : SelectedDate.DateTime,
                    IsArrivalChecked == true,
                    ConstructTransitModes((bool)IsBusChecked, (bool)IsTramChecked, (bool)IsTrainChecked,
                                          (bool)IsMetroChecked, (bool)IsFerryChecked, (bool)IsBikeChecked),
                    SelectedWalkingAmount,
                    SelectedWalkingSpeed
                    );

                Views.Busy.SetBusyText(AppResources.TripForm_PlanningTrip);

                var result = await _networkService.PlanTripAsync(details, _cts.Token);

                if (result.IsFailure)
                {
                    await HandleTripPlanningFailure(result);

                    SetBusy(false);
                    return;
                }

                if (!BootStrapper.Current.SessionState.ContainsKey(NavParamKeys.PlanResults))
                {
                    BootStrapper.Current.SessionState.Add(NavParamKeys.PlanResults, result.Result);
                }
                else
                {
                    BootStrapper.Current.SessionState.Remove(NavParamKeys.PlanResults);
                    BootStrapper.Current.SessionState.Add(NavParamKeys.PlanResults, result.Result);
                }

                _messengerService.Send(new MessageTypes.PlanFoundMessage(CurrentVisualState));
            }
            catch (OperationCanceledException ex)
            {
                //Log and swallow. Cancellation should only happen on user request here.
                System.Diagnostics.Debug.WriteLine("User cancelled place lookup.");
            }
            finally
            {
                SetBusy(false);
            }
        }