private void SetPoint(MapPointMessage message)
        {
            ShowHeaderLoader();

            cancellationTokenSource.Cancel();
            cancellationTokenSource = new CancellationTokenSource();

            Point           = message.Point.GeoCoordinate;
            PointVisibility = Visibility.Visible;

            FooterBarVisibility = Visibility.Collapsed;

            Action search = async() =>
            {
                try
                {
                    Address customAddress = await BumbleApiService.ReverseGeoCode(cancellationTokenSource.Token, user, message.Point);

                    SelectedCustomPoint = new Entities.PlaceOfInterest(customAddress.AddressText, null, customAddress.ShortAddressText, message.Point, -1);

                    FooterBarVisibility = Visibility.Visible;
                }
                catch (Exception ex)
                {
                    if (ex.Message != AppResources.ApiErrorTaskCancelled)
                    {
                        base.ShowPopup(CustomPopupMessageType.Error, ex.Message, AppResources.CustomPopupGenericOkMessage, null);
                    }
                }

                HideHeaderLoader();
            };

            DispatcherHelper.CheckBeginInvokeOnUI(search);
        }
예제 #2
0
        private void SelectPointOnMap(PointOnMapMessage action)
        {
            switch (action.Reason)
            {
            case PointOnMapMessageReason.PublicStopPoint:
                SelectedStation = UnitOfWork.PublicStopRepository.FindById(action.PublicStopPoint.PublicStopId);
                break;

            case PointOnMapMessageReason.PlaceOfInterest:
                SelectedSearchResult = action.PlaceOfInterest;
                break;

            case PointOnMapMessageReason.CustomPoint:
                cancellationTokenSource.Cancel();
                cancellationTokenSource = new CancellationTokenSource();

                ShowHeaderLoader();

                Action search = async() =>
                {
                    try
                    {
                        Address customAddress = await BumbleApiService.ReverseGeoCode(cancellationTokenSource.Token, user, action.Coordinate);

                        int distance = 0;

                        if (user.LastKnownGeneralLocation != null)
                        {
                            distance = (int)action.Coordinate.DistanceToCoordinateInMetres(user.LastKnownGeneralLocation);
                        }

                        SelectedCustomPoint = new Entities.PlaceOfInterest(customAddress.AddressText, null, customAddress.AddressText, action.Coordinate, distance);
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message != AppResources.ApiErrorTaskCancelled)
                        {
                            base.ShowPopup(CustomPopupMessageType.Error, ex.Message, AppResources.CustomPopupGenericOkMessage, null);
                        }
                    }

                    HideHeaderLoader();
                };

                DispatcherHelper.CheckBeginInvokeOnUI(search);
                break;
            }
        }
예제 #3
0
        public void UserLocationFound(Coordinate coordinate)
        {
            if (sentCoordinateRequest)
            {
                sentCoordinateRequest = false;

                if (cancellationTokenSource == null || cancellationTokenSource.Token.IsCancellationRequested)
                {
                    ClearButton();
                    return;
                }

                // Change text to finding address.
                switch (this.Type)
                {
                case SearchType.Location:
                    // Check if still finding location (there is a chance that a favourite was loaded in this time).
                    if (TextLocation == AppResources.WhereToFindingLocationTextBoxWaterMark)
                    {
                        TextLocation = AppResources.WhereToFindingAddressWaterMark;
                    }
                    else
                    {
                        return;
                    }
                    break;

                case SearchType.Destination:
                    // Check if still finding location (there is a chance that a favourite was loaded in this time).
                    if (TextDestination == AppResources.WhereToFindingLocationTextBoxWaterMark)
                    {
                        TextDestination = AppResources.WhereToFindingAddressWaterMark;
                    }
                    else
                    {
                        return;
                    }
                    break;
                }

                Action getAddress = async() =>
                {
                    LoadingBarMessage.Send(LoadingBarMessageReason.Show);

                    try
                    {
                        Address userAddress = await BumbleApiService.ReverseGeoCode(cancellationTokenSource.Token, user, coordinate);

                        switch (this.Type)
                        {
                        case SearchType.Location:
                            // Check if still finding location (there is a chance that a favourite was loaded in this time).
                            if (TextLocation == AppResources.WhereToFindingAddressWaterMark)
                            {
                                TextLocation = userAddress.ShortAddressText;
                            }
                            else
                            {
                                LoadingBarMessage.Send(LoadingBarMessageReason.Hide);
                                return;
                            }
                            break;

                        case SearchType.Destination:
                            // Check if still finding location (there is a chance that a favourite was loaded in this time).
                            if (TextDestination == AppResources.WhereToFindingAddressWaterMark)
                            {
                                TextDestination = userAddress.ShortAddressText;
                            }
                            else
                            {
                                LoadingBarMessage.Send(LoadingBarMessageReason.Hide);
                                return;
                            }
                            break;
                        }

                        // Don't lose the user's location, so create a new address object.
                        TripOptions.SetAsAddress(userAddress);

                        OnChanged(EventArgs.Empty);
                    }
                    catch (Exception e)
                    {
                        ClearButton();

                        if (e.Message != "Cancelled")
                        {
                            Messenger.Default.Send <CustomPopupMessage>(new CustomPopupMessage(CustomPopupMessageType.Error, e.Message, AppResources.CustomPopupGenericOkMessage, null));
                        }
                    }

                    LoadingBarMessage.Send(LoadingBarMessageReason.Hide);
                };

                DispatcherHelper.CheckBeginInvokeOnUI(getAddress);
            }
        }