private void RequestListener_DriverAccepted(object sender, CreateRequestEventListener.DriverAcceptedEventArgs e) { acceptedDriver = e.acceptedDriver; if (!requestCabView.Hidden) { overlay.Hidden = true; requestCabView.Hidden = true; } driverNameText.Text = acceptedDriver.Fullname; tripStatusText.Text = "Coming"; UIView.Animate(0.2, HideTripDetailsView); UIView.Animate(0.2, ShowTripControlPanel); }
public void OnDataChange(DataSnapshot snapshot) { if (snapshot.Value != null) { if (snapshot.Child("driver_id").Value.ToString() != "waiting") { string status = ""; double fares = 0; if (!isDriverAccepted) { AcceptedDriver acceptedDriver = new AcceptedDriver(); acceptedDriver.ID = snapshot.Child("driver_id").Value.ToString(); acceptedDriver.fullname = snapshot.Child("driver_name").Value.ToString(); acceptedDriver.phone = snapshot.Child("driver_phone").Value.ToString(); isDriverAccepted = true; DriverAccepted.Invoke(this, new DriverAcceptedEventArgs { acceptedDriver = acceptedDriver }); } //Gets Status if (snapshot.Child("status").Value != null) { status = snapshot.Child("status").Value.ToString(); } //Get Fares if (snapshot.Child("fares").Value != null) { fares = double.Parse(snapshot.Child("fares").Value.ToString()); } if (isDriverAccepted) { //Get Driver Location Updates double driverLatitude = double.Parse(snapshot.Child("driver_location").Child("latitude").Value.ToString()); double driverLongitude = double.Parse(snapshot.Child("driver_location").Child("longitude").Value.ToString()); LatLng driverLocationLatLng = new LatLng(driverLatitude, driverLongitude); TripUpdates.Invoke(this, new TripUpdatesEventArgs { DriverLocation = driverLocationLatLng, Status = status, Fares = fares }); } } } }
async void InitializeConnection() { try { hubConnection = new HubConnectionBuilder().WithUrl(LetsRideCredentials.HubUrl , options => options.AccessTokenProvider = () => Task.FromResult(new AppData().GetToken) ).WithAutomaticReconnect().Build(); await ConnectAsync(); hubConnection.Closed += HubConnection_Closed; hubConnection.On <bool, string>("OnConnected", (status, message) => { //CloseProgressDialogue(); if (status) { //goOnlineButton.Enabled = true; //availablityStatus = true; //goOnlineButton.Text = "Go offline"; //goOnlineButton.Background = ContextCompat.GetDrawable(this, Resource.Drawable.uberroundbutton_green); } else { //availablityStatus = false; //goOnlineButton.Enabled = true; //goOnlineButton.Text = "Go Online"; ////isConnectionSuccessful = false; //Android.Support.V7.App.AlertDialog.Builder alert1 = new Android.Support.V7.App.AlertDialog.Builder(this); //alert1.SetTitle("GO ONLINE"); //alert1.SetMessage("Request Failed, " + message + ". Try Again"); //alert1.SetPositiveButton("Continue", (senderAlert, args) => //{ // alert1.Dispose(); //}); //alert1.Show(); } }); hubConnection.On <string, string, Nullable <double>, Nullable <double> >("ReceiveResponse", (driverName, driverPhone, latitude, longitude) => { if (string.IsNullOrEmpty(driverName)) { requestListener.OnDriverResponse(new AcceptedDriver()); } else { this.driverPhone = driverPhone; requestListener.OnDriverResponse(new AcceptedDriver() { fullname = driverName, phone = driverPhone, Latitude = Convert.ToDouble(latitude), Longitude = Convert.ToDouble(longitude) }); } }); hubConnection.On <string>("ErrorInformation", (message) => { if (message == "notonline") { requestListener.OnDriverResponse(null); } else { Android.Support.V7.App.AlertDialog.Builder alert1 = new Android.Support.V7.App.AlertDialog.Builder(this); alert1.SetTitle("Request Failed"); alert1.SetMessage(message); alert1.SetPositiveButton("Continue", (senderAlert, args) => { alert1.Dispose(); }); alert1.Show(); } }); hubConnection.On <string>("TripInformation", (info) => { if (!string.IsNullOrEmpty(info)) { AcceptedDriver driverInfo = JsonConvert.DeserializeObject <AcceptedDriver>(info); requestListener.OnDriverResponse(driverInfo); } }); } catch (Exception ex) { // CloseProgressDialogue(); Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this); alert.SetTitle("Error in connection"); alert.SetMessage("Request Failed, " + ex.Message + ". Try Again"); alert.SetPositiveButton("Continue", (senderAlert, args) => { alert.Dispose(); }); alert.Show(); } }
public void OnDriverResponse(AcceptedDriver driverInfor) { if (!string.IsNullOrEmpty(driverInfor.fullname) && !isDriverAccepted) { isDriverAccepted = true; DriverAccepted.Invoke(this, new DriverAcceptedEventArgs { acceptedDriver = driverInfor }); LatLng driverLocationLatLng = new LatLng(driverInfor.Latitude, driverInfor.Longitude); TripUpdates.Invoke(this, new TripUpdatesEventArgs { DriverLocation = driverLocationLatLng, Status = "accepted", Fares = Convert.ToDouble(rides.RidesInfo.TotalCost) }); } else if (!string.IsNullOrEmpty(driverInfor.Status) && isDriverAccepted) { LatLng driverLocationLatLng = new LatLng(driverInfor.Latitude, driverInfor.Longitude); TripUpdates.Invoke(this, new TripUpdatesEventArgs { DriverLocation = driverLocationLatLng, Status = driverInfor.Status, Fares = Convert.ToDouble(rides.RidesInfo.TotalCost) }); } else { isDriverRejected = true; } //if(snapshot.Value != null) //{ // if(snapshot.Child("driver_id").Value.ToString() != "waiting") // { // string status = ""; // double fares = 0; // if (!isDriverAccepted) // { // AcceptedDriver acceptedDriver = new AcceptedDriver(); // acceptedDriver.ID = snapshot.Child("driver_id").Value.ToString(); // acceptedDriver.fullname = snapshot.Child("driver_name").Value.ToString(); // acceptedDriver.phone = snapshot.Child("driver_phone").Value.ToString(); // isDriverAccepted = true; // DriverAccepted.Invoke(this, new DriverAcceptedEventArgs { acceptedDriver = acceptedDriver }); // } // //Gets Status // if(snapshot.Child("status").Value != null) // { // status = snapshot.Child("status").Value.ToString(); // } // //Get Fares // if(snapshot.Child("fares").Value != null) // { // fares = double.Parse(snapshot.Child("fares").Value.ToString()); // } // if (isDriverAccepted) // { // //Get Driver Location Updates // double driverLatitude = double.Parse(snapshot.Child("driver_location").Child("latitude").Value.ToString()); // double driverLongitude = double.Parse(snapshot.Child("driver_location").Child("longitude").Value.ToString()); // LatLng driverLocationLatLng = new LatLng(driverLatitude, driverLongitude); // TripUpdates.Invoke(this, new TripUpdatesEventArgs { DriverLocation = driverLocationLatLng , Status = status, Fares = fares}); // } // } //} }
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 }); } } } }); }