Exemplo n.º 1
0
        public void CreateRequest()
        {
            newTripRef = database.GetReference("RiderRequest").Push();

            HashMap location = new HashMap();

            location.Put("latitude", newTrip.PickupLat);
            location.Put("longitude", newTrip.PickupLng);

            HashMap destination = new HashMap();

            destination.Put("latitude", newTrip.DestinationLat);
            destination.Put("longitude", newTrip.DestinationLng);

            HashMap myTrip = new HashMap();

            newTrip.RideID = newTripRef.Key;

            myTrip.Put("rider_id", AppDataHelper.GetCurrentUser().Uid);
            myTrip.Put("location", location);
            myTrip.Put("destination", destination);
            myTrip.Put("destination_address", newTrip.DestinationAddress);
            myTrip.Put("pickup_address", newTrip.PickupAddress);
            myTrip.Put("payment_method", newTrip.Paymentmethod);
            myTrip.Put("created_at", newTrip.Timestamp.ToString());
            myTrip.Put("driver_id", "waiting");
            myTrip.Put("rider_name", AppDataHelper.GetFullName());
            myTrip.Put("rider_phone", AppDataHelper.GetPhone());
            //myTrip.Put("Imgurl",)

            newTripRef.AddValueEventListener(this);
            newTripRef.SetValue(myTrip);
        }
Exemplo n.º 2
0
 void Accept()
 {
     tripRef.Child("status").SetValue("accepted");
     tripRef.Child("driver_name").SetValue(AppDataHelper.GetFullName());
     tripRef.Child("driver_phone").SetValue(AppDataHelper.GetPhone());
     tripRef.Child("driver_location").Child("latitude").SetValue(mLastlocation.Latitude);
     tripRef.Child("driver_location").Child("longitude").SetValue(mLastlocation.Longitude);
     tripRef.Child("driver_id").SetValue(AppDataHelper.GetCurrentUser().Uid);
 }
Exemplo n.º 3
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");
        }
        public void CreateRequest()
        {
            requestReference      = Database.DefaultInstance.GetRootReference().GetChild("rideRequest").GetChildByAutoId();
            newTripDetails.RideID = requestReference.Key;

            var locationNode = new NSDictionary
                               (
                "latitude", newTripDetails.PickupLat.ToString(),
                "longitude", newTripDetails.PickupLng.ToString()
                               );

            var destinationNode = new NSDictionary
                                  (
                "latitude", newTripDetails.DestinationLat.ToString(),
                "longitude", newTripDetails.DestinationLng.ToString()
                                  );

            var tripDetailsNode = new NSDictionary
                                  (
                "location", locationNode,
                "destination", destinationNode,
                "destination_address", newTripDetails.DestinationAddress,
                "pickup_address", newTripDetails.PickupAddress,
                "rider_id", AppDataHelper.GetUserID(),
                "rider_name", AppDataHelper.GetFullName(),
                "rider_phone", AppDataHelper.GetPhone(),
                "created_at", newTripDetails.TimeStamp.ToString()
                                  );

            requestReference.SetValue <NSDictionary>(tripDetailsNode);
            requestReference.ObserveEvent(DataEventType.Value, (DataSnapshot snapshot) =>
            {
                //Driver has been assigned
                if (snapshot.GetChildSnapshot("driver_id").GetValue <NSObject>() != NSNull.Null)
                {
                    if (snapshot.GetChildSnapshot("driver_id").GetValue <NSObject>().ToString() != "waiting")
                    {
                        if (!isDriverAccepted)
                        {
                            // Fetch Driver Details from the snapshot
                            AcceptedDriver acceptedDriver = new AcceptedDriver();
                            acceptedDriver.ID             = snapshot.GetChildSnapshot("driver_id").GetValue <NSObject>().ToString();
                            acceptedDriver.Fullname       = snapshot.GetChildSnapshot("driver_name").GetValue <NSObject>().ToString();
                            acceptedDriver.phone          = snapshot.GetChildSnapshot("driver_phone").GetValue <NSObject>().ToString();

                            isDriverAccepted = true;
                            DriverAccepted?.Invoke(this, new DriverAcceptedEventArgs {
                                acceptedDriver = acceptedDriver
                            });
                        }


                        // Gets Trip Status

                        if (snapshot.GetChildSnapshot("status").GetValue <NSObject>() != NSNull.Null)
                        {
                            status = snapshot.GetChildSnapshot("status").GetValue <NSObject>().ToString();
                        }

                        // Get fares
                        if (snapshot.GetChildSnapshot("fares").GetValue <NSObject>() != NSNull.Null)
                        {
                            fares = double.Parse(snapshot.GetChildSnapshot("fares").GetValue <NSObject>().ToString());
                        }


                        if (isDriverAccepted)
                        {
                            // Get driver location upadtes

                            double driverLatitude  = 0;
                            double driverLongitude = 0;

                            driverLatitude  = double.Parse(snapshot.GetChildSnapshot("driver_location").GetChildSnapshot("latitude").GetValue <NSObject>().ToString());
                            driverLongitude = double.Parse(snapshot.GetChildSnapshot("driver_location").GetChildSnapshot("longitude").GetValue <NSObject>().ToString());

                            CLLocationCoordinate2D driverLocationLatLng = new CLLocationCoordinate2D(driverLatitude, driverLongitude);
                            TripUpdates?.Invoke(this, new TripUpdatesEventArgs {
                                DriverLocation = driverLocationLatLng, Status = status, Fares = fares
                            });
                        }
                    }
                }
            });
        }