Esempio n. 1
0
        /// <summary>
        /// Executes everytime the page appears.
        /// Changes the app state and starts the update timer.
        /// </summary>
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            if (KCApi.Properties.State != KCProperties.AppState.Accept)
            {
                KCApi.Properties.State = KCProperties.AppState.Accept;

                Timer(null, null);

                if (KCApi.Properties.NetState == KCProperties.NetworkState.Disconnected)
                {
                    lock (KCApi.Properties.StateLock)
                        KCApi.Properties.State = KCProperties.AppState.Transitioning;

                    await Navigation.PopAsync();

                    return;
                }

                KCApi.Properties.CurrentPosition = await KCApi.GetCurrentPosition();

                // Location is not set
                if (KCApi.Properties.CurrentPosition.Latitude == 0 && KCApi.Properties.CurrentPosition.Longitude == 0)
                {
                    var text = "GPS signal lost. Please reenable or reenter service.";
                    Toast.MakeText(CrossCurrentActivity.Current.Activity, text, ToastLength.Short).Show();
                }
                // Driver is no longer authenticated. Send back to sign in
                else if (!Driver_Id.authenticated)
                {
                    var text = "Authentication Failure";
                    Toast.MakeText(CrossCurrentActivity.Current.Activity, text, ToastLength.Short).Show();

                    lock (KCApi.Properties.StateLock)
                        KCApi.Properties.State = KCProperties.AppState.Transitioning;

                    await Navigation.PopAsync();
                }
                // Driver has entered the Accept screen for the first time since logging in as CurrentRide is null
                else if (KCApi.Properties.RideStatus != KCProperties.RideStatuses.Active && KCApi.Properties.CurrentRide == null)
                {
                    Ride ride = new Ride();

                    if (KCApi.RecoveryCheck(ride) && KCApi.SetRideLocation(ride))
                    {
                        ride.SetDisplayAddress(KCApi.GetAddressFromPosition(new Position(ride.ClientLat, ride.ClientLong)));
                        KCApi.Start(ride);

                        lock (KCApi.Properties.StateLock)
                            KCApi.Properties.State = KCProperties.AppState.Transitioning;

                        await Navigation.PushAsync(new MapPage());
                    }
                }

                updater.Start();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Timer function which updates the driver if there are any rides in the queue.
        /// </summary>
        private void Timer(Object source, ElapsedEventArgs e)
        {
            if (KCApi.Properties.State == KCProperties.AppState.Accept)
            {
                string status = Task.Run(() => KCApi.CheckQueue()).Result;

                if (KCApi.RecoveryCheck(new Ride()))
                {
                    status = "Active ride ongoing";
                }

                if (KCApi.Properties.NetState == KCProperties.NetworkState.Disconnected)
                {
                    var text = "Internet connection lost.";

                    lock (KCApi.Properties.StateLock)
                    {
                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            Toast.MakeText(CrossCurrentActivity.Current.Activity, text, ToastLength.Short).Show();

                            KCApi.Properties.State = KCProperties.AppState.Transitioning;

                            await Navigation.PopAsync();
                        });
                        return;
                    }
                }

                Device.BeginInvokeOnMainThread(() =>
                {
                    Status.Text = status;

                    if (status.Equals("Rides are available"))
                    {
                        StatusColor.BackgroundColor = Color.Green;
                    }
                    else
                    {
                        StatusColor.BackgroundColor = Color.Gray;
                    }
                });

                updater.Interval = 500; // Can optimize to reduce interval depending on time taken
            }
        }