private void TrackingStopped(DateTime stopTime) { if (distance > 0) { var trackEntity = new TrackEntity { StartDate = startTime, EndDate = stopTime, // TODO: utc? Distance = distance }; _trackService.Add(trackEntity); var json = JsonConvert.SerializeObject(trackEntity); var intent = new Intent("TrackingStopped"); intent.PutExtra("TrackEntity", json); LocalBroadcastManager.SendBroadcast(intent); } isStarted = false; startTime = default(DateTime); distance = 0; currentModel = null; textViewTrackingCoordinates.Text = string.Empty; textViewTrackingDuration.Text = string.Empty; textViewTrackingStarted.Text = string.Empty; textViewTrackingDistance.Text = string.Empty; }
private void TrackingStarted() { isStarted = false; startTime = default(DateTime); distance = 0; currentModel = null; textViewTrackingCoordinates.Text = string.Empty; textViewTrackingDuration.Text = string.Empty; textViewTrackingStarted.Text = string.Empty; textViewTrackingDistance.Text = string.Empty; }
public void OnLocationChanged(Location location) { var intent = new Intent("testAction"); intent.PutExtra("x", $"{DateTime.Now.ToString("HH:mm:ss")} - location set"); //_localBroadcastManager.SendBroadcast(intent); _locationService.AddLocation(location); _locationUploaderService.UploadLocations(); Task.Run(() => { var model = new LocationChangedModel(location); var json = JsonConvert.SerializeObject(model); var intent = new Intent("LocationChanged"); intent.PutExtra("Location", json); _localBroadcastManager.SendBroadcast(intent); }); var settings = _settingsService.GetSettings(); if (!settings.IsTelegramUploadEnabled) { return; } Task.Run(() => { try { _telegramClient.SendLocation(location.Latitude, location.Longitude); var intentTelegram = new Intent("testAction"); intentTelegram.PutExtra("x", $"{DateTime.Now.ToString("HH:mm:ss")} - location sent in Telegram"); //_localBroadcastManager.SendBroadcast(intentTelegram); } catch (Exception ex) { var intentTelegram = new Intent("testAction"); intentTelegram.PutExtra("x", $"{DateTime.Now.ToString("HH:mm:ss")} - location sending in Telegram failed"); _localBroadcastManager.SendBroadcast(intentTelegram); throw; } }); }
private void LocationChanged(LocationChangedModel model) { var dateTime = GetDateTime(model.Time); if (!isStarted) { isStarted = true; startTime = dateTime; } var coordinatesText = $"N{FormatValue(model.Latitude)} E{FormatValue(model.Longitude)}"; textViewTrackingCoordinates.Text = coordinatesText; var duration = dateTime - startTime; var durationText = $"Duration: {duration.Hours}h {duration.Minutes}m {duration.Seconds}s"; textViewTrackingDuration.Text = durationText; var startedText = $"Started: {startTime.ToLocalTime().ToString("MM.dd.yyyy HH:mm")}"; textViewTrackingStarted.Text = startedText; // TODO? if (currentModel != null && dateTime > GetDateTime(currentModel.Time)) { var delta = CalculateDistance(currentModel.Latitude, currentModel.Longitude, model.Latitude, model.Longitude); distance += delta; } textViewTrackingDistance.Text = distance.ToString("Distance: 0.00km"); currentModel = model; string FormatValue(double value) { return(value.ToString("0.000000")); } }