async void RecordButton_TouchUpInside(object sender, EventArgs e) { if (!CurrentTripViewModel.Geolocator.IsGeolocationEnabled) { Acr.UserDialogs.UserDialogs.Instance.Alert( "Please ensure that geolocation is enabled and permissions are allowed for MyDriving to start a recording.", "Geolocation Disabled", "OK"); return; } if (!CurrentTripViewModel.IsRecording) { if (!await CurrentTripViewModel.StartRecordingTrip()) { return; } UpdateRecordButton(true); ResetTripInfoView(); AnimateTripInfoView(); if (CurrentTripViewModel.CurrentTrip.HasSimulatedOBDData) { NavigationItem.Title = "Current Trip (Sim OBD)"; } var endpoint = "A"; var annotation = new WaypointAnnotation(CurrentTripViewModel.CurrentPosition.ToCoordinate(), endpoint); tripMapView.AddAnnotation(annotation); } else { if (await CurrentTripViewModel.StopRecordingTrip()) { ResetMapViewState(); InvokeOnMainThread(delegate { mapDelegate = new TripMapViewDelegate(true); tripMapView.Delegate = mapDelegate; }); UpdateRecordButton(false); tripInfoView.Alpha = 0; NavigationItem.Title = "Current Trip"; await CurrentTripViewModel.SaveRecordingTripAsync(); var vc = Storyboard.InstantiateViewController("tripSummaryViewController") as TripSummaryViewController; vc.ViewModel = CurrentTripViewModel; PresentModalViewController(vc, true); } } }
async Task ConfigurePastTripUserInterface() { NavigationItem.Title = PastTripsDetailViewModel.Title; sliderView.Hidden = false; tripSlider.Hidden = false; wayPointA.Layer.CornerRadius = wayPointA.Frame.Width / 2; wayPointA.Layer.BorderWidth = 2; wayPointA.Layer.BorderColor = UIColor.White.CGColor; wayPointB.Layer.CornerRadius = wayPointB.Frame.Width / 2; wayPointB.Layer.BorderWidth = 2; wayPointB.Layer.BorderColor = UIColor.White.CGColor; var success = await PastTripsDetailViewModel.ExecuteLoadTripCommandAsync(PastTripsDetailViewModel.Trip.Id); if(!success) { NavigationController.PopViewController(true); return; } // Setup map mapDelegate = new TripMapViewDelegate(false); tripMapView.Delegate = mapDelegate; tripMapView.ShowsUserLocation = false; if (PastTripsDetailViewModel.Trip == null || PastTripsDetailViewModel.Trip.Points == null || PastTripsDetailViewModel.Trip.Points.Count == 0) return; var coordinateCount = PastTripsDetailViewModel.Trip.Points.Count; // Draw endpoints var startEndpoint = new WaypointAnnotation(PastTripsDetailViewModel.Trip.Points[0].ToCoordinate(), "A"); tripMapView.AddAnnotation(startEndpoint); var endEndpoint = new WaypointAnnotation(PastTripsDetailViewModel.Trip.Points[coordinateCount - 1].ToCoordinate(), "B"); tripMapView.AddAnnotation(endEndpoint); // Draw route tripMapView.DrawRoute(PastTripsDetailViewModel.Trip.Points.ToCoordinateArray()); // Draw car var carCoordinate = PastTripsDetailViewModel.Trip.Points[0]; currentLocationAnnotation = new CarAnnotation(carCoordinate.ToCoordinate(), UIColor.Blue); tripMapView.AddAnnotation(currentLocationAnnotation); // Configure slider area ConfigureSlider(); ConfigureWayPointButtons(); ConfigurePoiAnnotations(); recordButton.Hidden = true; tripMapView.SetVisibleMapRect( MKPolyline.FromCoordinates(PastTripsDetailViewModel.Trip.Points.ToCoordinateArray()).BoundingMapRect, new UIEdgeInsets(25, 25, 25, 25), false); tripMapView.CenterCoordinate = carCoordinate.ToCoordinate(); UpdateTripStatistics(carCoordinate); NSNotificationCenter.DefaultCenter.AddObserver(new NSString("RefreshTripUnits"), HandleTripUnitsChanged); }
async void RecordButton_TouchUpInside(object sender, EventArgs e) { if (!CurrentTripViewModel.Geolocator.IsGeolocationEnabled) { Acr.UserDialogs.UserDialogs.Instance.Alert( "Please ensure that geolocation is enabled and permissions are allowed for MyDriving to start a recording.", "Geolocation Disabled", "OK"); return; } if (!CurrentTripViewModel.IsRecording) { if (!await CurrentTripViewModel.StartRecordingTrip()) return; UpdateRecordButton(true); ResetTripInfoView(); AnimateTripInfoView(); if (CurrentTripViewModel.CurrentTrip.HasSimulatedOBDData) NavigationItem.Title = "Current Trip (Sim OBD)"; var endpoint = "A"; var annotation = new WaypointAnnotation(CurrentTripViewModel.CurrentPosition.ToCoordinate(), endpoint); tripMapView.AddAnnotation(annotation); } else { if (await CurrentTripViewModel.StopRecordingTrip()) { ResetMapViewState(); InvokeOnMainThread(delegate { mapDelegate = new TripMapViewDelegate(true); tripMapView.Delegate = mapDelegate; }); UpdateRecordButton(false); tripInfoView.Alpha = 0; NavigationItem.Title = "Current Trip"; await CurrentTripViewModel.SaveRecordingTripAsync(); var vc = Storyboard.InstantiateViewController("tripSummaryViewController") as TripSummaryViewController; vc.ViewModel = CurrentTripViewModel; PresentModalViewController(vc, true); } } }
async Task ConfigurePastTripUserInterface() { NavigationItem.Title = PastTripsDetailViewModel.Title; sliderView.Hidden = false; tripSlider.Hidden = false; wayPointA.Layer.CornerRadius = wayPointA.Frame.Width / 2; wayPointA.Layer.BorderWidth = 2; wayPointA.Layer.BorderColor = UIColor.White.CGColor; wayPointB.Layer.CornerRadius = wayPointB.Frame.Width / 2; wayPointB.Layer.BorderWidth = 2; wayPointB.Layer.BorderColor = UIColor.White.CGColor; var success = await PastTripsDetailViewModel.ExecuteLoadTripCommandAsync(PastTripsDetailViewModel.Trip.Id); if (!success) { NavigationController.PopViewController(true); return; } // Setup map mapDelegate = new TripMapViewDelegate(false); tripMapView.Delegate = mapDelegate; tripMapView.ShowsUserLocation = false; if (PastTripsDetailViewModel.Trip == null || PastTripsDetailViewModel.Trip.Points == null || PastTripsDetailViewModel.Trip.Points.Count == 0) { return; } var coordinateCount = PastTripsDetailViewModel.Trip.Points.Count; // Draw endpoints var startEndpoint = new WaypointAnnotation(PastTripsDetailViewModel.Trip.Points[0].ToCoordinate(), "A"); tripMapView.AddAnnotation(startEndpoint); var endEndpoint = new WaypointAnnotation(PastTripsDetailViewModel.Trip.Points[coordinateCount - 1].ToCoordinate(), "B"); tripMapView.AddAnnotation(endEndpoint); // Draw route tripMapView.DrawRoute(PastTripsDetailViewModel.Trip.Points.ToCoordinateArray()); // Draw car var carCoordinate = PastTripsDetailViewModel.Trip.Points[0]; currentLocationAnnotation = new CarAnnotation(carCoordinate.ToCoordinate(), UIColor.Blue); tripMapView.AddAnnotation(currentLocationAnnotation); // Configure slider area ConfigureSlider(); ConfigureWayPointButtons(); ConfigurePoiAnnotations(); recordButton.Hidden = true; tripMapView.SetVisibleMapRect( MKPolyline.FromCoordinates(PastTripsDetailViewModel.Trip.Points.ToCoordinateArray()).BoundingMapRect, new UIEdgeInsets(25, 25, 25, 25), false); tripMapView.CenterCoordinate = carCoordinate.ToCoordinate(); UpdateTripStatistics(carCoordinate); NSNotificationCenter.DefaultCenter.AddObserver(new NSString("RefreshTripUnits"), HandleTripUnitsChanged); }