Esempio n. 1
0
        public async Task PostPendingRideStatus(PendingRideStatus status)
        {
            if (DataStore == null)
            {
                return;
            }

            string data = JsonConvert.SerializeObject(status);

            await DataStore.PostStringResource(PendingRideStatusName(status.Id), data);
        }
Esempio n. 2
0
        async Task <Ridesharing.StateBase> TryComputeRideOfferState(string userId, RideRelatedRequestStatus offerStatus)
        {
            string requestId = offerStatus.Id;
            string rideId    = offerStatus.PendingRideId;

            if (string.IsNullOrEmpty(rideId))
            {
                var requestNotifications = new PendingRideRelatedRequest(userId, requestId);

                // FIXME Retrieve old RideOffer corresponding to requestId
                return(new OfferPendingState(this, requestNotifications, null));
            }

            PendingRideStatus status = await App.Current.DataStore.GetPendingRideStatus(rideId);

            if (status != null)
            {
                switch (status.State)
                {
                case PendingRideStatus.PendingRideState.Confirmed:
                    if (status.ActiveRideId == null)
                    {
                        break;
                    }

                    ActiveRideStatus activeRide = await App.Current.DataStore.GetActiveRideStatus(status.ActiveRideId);

                    if (activeRide == null)
                    {
                        break;
                    }

                    if (activeRide.RideState == ActiveRideStatus.State.InProgress)
                    {
                        return(new RideInProgressState(this, activeRide));
                    }

                    break;

                case PendingRideStatus.PendingRideState.WaitingOnDriver:
                    return(new OfferMatchedState(this, new MatchedRideRelatedRequest(userId, requestId, rideId)));

                case PendingRideStatus.PendingRideState.WaitingOnRiders:
                    return(new WaitingForConfirmedState(this, new MatchedRideRelatedRequest(userId, requestId, rideId)));

                case PendingRideStatus.PendingRideState.Canceled:
                    break;
                }
            }

            return(null);
        }
Esempio n. 3
0
        void HandleRidesStateChanged(Ridesharing.StateBase newState)
        {
            bool isMatched = false;
            PendingRideStatus   pendingRideStatus = null;
            Func <Task <bool> > confirm           = null;
            Func <Task <bool> > decline           = null;

            //TODO ick...
            HomeView hPage = ((homePage as NavigationPage).RootPage as ContentPage).Content as HomeView;

            switch (newState)
            {
            case AbstractMatchedState matchedState:
                isMatched = true;
                confirm   = matchedState.Confirm;
                decline   = matchedState.Decline;

                pendingRideStatus = matchedState.MostRecentStatus;
                break;

            case RideInProgressState rideInProgressState:
                // TODO: Compute route to display.
                break;
            }

            if (isMatched)
            {
                async Task ShowConfirmView()
                {
                    ShowHomePage();
                    await(homePage as NavigationPage).PopToRootAsync();

                    hPage.ShowConfirmView(confirm, decline, pendingRideStatus);
                }

                Device.BeginInvokeOnMainThread(() => ShowConfirmView().FireAndForgetAsync(App.Current.ErrorHandler));
            }
        }
Esempio n. 4
0
        public void ShowConfirmView(Func <Task <bool> > confirm, Func <Task <bool> > decline, PendingRideStatus pendingRideStatus)
        {
            tagRideMap.RideInfoView(pendingRideStatus.RideInfo);

            View slideView = new RideConfirmationView(
                new RideConfirmationViewModel(
                    async() =>
            {
                bool success = await confirm();

                ClearSlideInView();
                tagRideMap.HomeView(OnSearchBarLocation, OnMapLongPress);

                if (!success)
                {
                    await this.GetPageParent()?.DisplayAlert("Failed", "Failed to confirm.", "Wait why?");
                }
            },
                    async() =>
            {
                bool success = await decline();

                ClearSlideInView();
                tagRideMap.HomeView(OnSearchBarLocation, OnMapLongPress);

                if (!success)
                {
                    await this.GetPageParent()?.DisplayAlert("Failed", "Failed to decline.", "Wait why?");
                }
            },
                    async() =>
            {
                await decline();

                ClearSlideInView();
                tagRideMap.HomeView(OnSearchBarLocation, OnMapLongPress);

                await this.GetPageParent()?.DisplayAlert("Ride Expired", "Ride has expired, try again to get matched", "Ok");
            },

                    pendingRideStatus.PostTime,
                    pendingRideStatus.TimeTillExpire,
                    pendingRideStatus.RideInfo));

            // TODO: Avoid hardcoded split. The following View properties do not help:
            // Height, HeightRequest, MinimumHeightRequest
            // They are all -1. There should be some way of determining a view's
            // preferred height.
            SlideInView(slideView, "Confirmation Page", 0.6);
        }