示例#1
0
        public void Accept()
        {
            var locationCordinate = new NSDictionary
                                    (
                "latitude", currentLocation.Latitude.ToString(),
                "longitude", currentLocation.Longitude.ToString()
                                    );

            tripRef.GetChild("driver_location").SetValue <NSDictionary>(locationCordinate);
            tripRef.GetChild("driver_name").SetValue((NSString)AppDataHelper.GetFullName());
            tripRef.GetChild("driver_id").SetValue((NSString)AppDataHelper.GetDriverID());
            tripRef.GetChild("driver_phone").SetValue((NSString)AppDataHelper.GetPhone());
            tripRef.GetChild("status").SetValue((NSString)"accepted");
        }
示例#2
0
        async void TripReady()
        {
            ShowProgressBar("Finding direction ....");
            mapHelper = new MapFunctionHelper("AIzaSyAZQBaY-ugQuwCWr4NkD-bybK7urElvNyY", googleMap);

            var    pickupLatLng  = new CLLocationCoordinate2D(newRideDetails.PickupLat, newRideDetails.PickLng);
            string directionJson = await mapHelper.GetDirectionJsonAsync(currentLocation, pickupLatLng);

            if (!string.IsNullOrEmpty(directionJson))
            {
                mapHelper.DrawTripOnMap(directionJson);

                status = "ACCEPTED";

                HideProgressBar();
                centerMarker.Hidden            = true;
                goOnlineButton.BackgroundColor = UIColor.FromRGB(227, 16, 48);
                goOnlineButton.SetTitle("ON TRIP", UIControlState.Normal);
                goOnlineButton.Enabled = false;

                riderNameText.Text     = newRideDetails.RiderName;
                rideDetailsView.Hidden = false;

                DatabaseReference historyRef = Database.DefaultInstance.GetRootReference().GetChild("drivers/" + AppDataHelper.GetDriverID() + "/trips/" + newRideDetails.RideId);
                historyRef.SetValue((NSNumber)true);
            }
        }
示例#3
0
        void TopUpEarning(double fares)
        {
            DatabaseReference earningRef = Database.DefaultInstance.GetRootReference().GetChild("drivers/" + AppDataHelper.GetDriverID() + "/earnings");

            earningRef.ObserveSingleEvent(DataEventType.Value, (DataSnapshot snapshot) =>
            {
                if (snapshot.GetValue <NSObject>() != NSNull.Null)
                {
                    string value = snapshot.GetValue <NSObject>().ToString();
                    double totalEarningsBefore = double.Parse(value);
                    double totalEarningsAfter  = totalEarningsBefore + fares;
                    earningRef.SetValue((NSString)totalEarningsAfter.ToString());
                }
                else
                {
                    earningRef.SetValue((NSString)fares.ToString());
                }
            });
        }
        public void Create(CLLocationCoordinate2D location)
        {
            var locationCordinate = new NSDictionary
                                    (
                "latitude", location.Latitude.ToString(),
                "longitude", location.Longitude.ToString()
                                    );

            var driverInfo = new NSDictionary
                             (
                "location", locationCordinate,
                "ride_id", "waiting"
                             );

            driverAvailableRef = Database.DefaultInstance.GetRootReference().GetChild("driversAvailable/" + AppDataHelper.GetDriverID());
            driverAvailableRef.SetValue <NSDictionary>(driverInfo);

            driverAvailableRef.ObserveEvent(DataEventType.Value, (DataSnapshot snapshot) =>
            {
                if (snapshot.GetValue <NSObject>() != NSNull.Null)
                {
                    if (snapshot.GetChildSnapshot("ride_id").GetValue <NSObject>() != NSNull.Null)
                    {
                        string ride_id = snapshot.GetChildSnapshot("ride_id").GetValue <NSObject>().ToString();

                        if (ride_id != "waiting" && ride_id != "timeout" && ride_id != "cancelled")
                        {
                            // Ride has been assigned to us
                            if (!rideAssigned)
                            {
                                GetRideDetails(ride_id);
                                rideAssigned = true;
                            }
                        }
                        else if (ride_id == "timeout")
                        {
                            // timeout
                            RideTimedOut?.Invoke(this, new EventArgs());
                            rideAssigned = false;
                            ReActivate();
                        }
                        else if (ride_id == "cancelled")
                        {
                            // cancelled;
                            RideCancelled?.Invoke(this, new EventArgs());
                            rideAssigned = false;
                            ReActivate();
                        }
                    }
                }
            });
        }
        void GetTripCount()
        {
            DatabaseReference tripsRef = Database.DefaultInstance.GetRootReference().GetChild("drivers/" + AppDataHelper.GetDriverID() + "/trips");

            tripsRef.ObserveEvent(DataEventType.Value, (DataSnapshot snapshot) =>
            {
                if (snapshot.GetValue <NSObject>() != NSNull.Null)
                {
                    var snapShotData   = snapshot.GetValue <NSDictionary>();
                    string keycount    = snapshot.ChildrenCount.ToString();
                    tripCountText.Text = keycount;

                    KeyList = new List <string>();
                    foreach (NSString key in snapShotData.Keys)
                    {
                        KeyList.Add(key);
                    }
                }
            });
        }
        void GetEarnings()
        {
            DatabaseReference earningsRef = Database.DefaultInstance.GetRootReference().GetChild("drivers/" + AppDataHelper.GetDriverID() + "/earnings");

            earningsRef.ObserveEvent(DataEventType.Value, (DataSnapshot snapshot) =>
            {
                if (snapshot.GetValue <NSObject>() != NSNull.Null)
                {
                    string value           = snapshot.GetValue <NSObject>().ToString();
                    tripsEarningsText.Text = "$" + value;
                }
            });
        }