You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

668 lines
26 KiB

1 year ago
  1. using GMCabsDriverAssistant.Models;
  2. using GMCabsDriverAssistant.Services;
  3. using GMCabsDriverAssistant.Utils;
  4. using GMCabsDriverAssistant.ViewModels;
  5. using GMCabsDriverAssistantSolution.Views;
  6. //using Plugin.BluetoothLE;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.ComponentModel;
  11. using System.Text;
  12. using System.Threading;
  13. //using Xamarin.CommunityToolkit.Extensions;
  14. using Microsoft.Maui;
  15. using Microsoft.Maui.Controls;
  16. using GMCabsDriverAssistantSolution.ViewModels;
  17. namespace GMCabsDriverAssistant.UserControl.ViewModels
  18. {
  19. public delegate void BluetoothStatusChanged();
  20. class TripInformationViewModel : BaseViewModel
  21. {
  22. [Browsable(true)]
  23. [Category("Action")]
  24. [Description("Invoked when user clicks button")]
  25. public event BluetoothStatusChanged BluetoothStatusChanged;
  26. #region Fields
  27. private bool hasUnreadNotifications;
  28. public int seconds = 0;
  29. public string timerSeconds = "00:00:00";
  30. public string pickUpAddress = "";
  31. public string dropUpAddress = "";
  32. private bool isBookingAvailable;
  33. private string startTripButtonText;
  34. private bool visibleTrip;
  35. private string startSuburb;
  36. private bool isStartTripButtonVisible;
  37. private string pickUpDateTimeOrEndSuburb;
  38. //private List<IGattCharacteristic> Characteristics;
  39. private bool foundDevice = false;
  40. //private IAdapter adapter;
  41. public bool MeterTripStarted;
  42. private int lastMeterTripStatus = -1;
  43. private string startTimeOrEndLocation;
  44. private bool isOkButtonVisible = false;
  45. public int autocloseOkSecond = 30;
  46. Page _page;
  47. private int mainStackLayoutMargin;
  48. private int indicatorMargin;
  49. private int logoMargin;
  50. private bool isDummyButtonsVisible;
  51. private int controlsMargin;
  52. private int dummyButtonLayoutMargin;
  53. private bool duressReleased;
  54. private int duressSeconds;
  55. private string duressButtonText;
  56. private string bluetoothConnectionStatusText;
  57. private string imageIcon;
  58. private int topLayoutMargin;
  59. private int rightLayoutMargin;
  60. private bool isPlotButtonVisible;
  61. #endregion
  62. #region Properties
  63. public Command OnStartEndTripClick { get; }
  64. MeterTrip meterTrip = new MeterTrip();
  65. public ObservableCollection<BookingDto> Bookings { get; }
  66. public Command<BookingDto> BookingTapped { get; }
  67. public double CurrentLat { get; set; }
  68. public double CurrentLng { get; set; }
  69. public Location CurrentLocation { get; set; }
  70. public Command onStartTripClick { get; }
  71. public Command OnOkButtonClick { get; }
  72. public string StartTripButtonText
  73. {
  74. get => startTripButtonText;
  75. set => SetProperty(ref startTripButtonText, value);
  76. }
  77. public bool HasUnreadNotifications
  78. {
  79. get => hasUnreadNotifications;
  80. set => SetProperty(ref hasUnreadNotifications, value);
  81. }
  82. public string TimerSeconds
  83. {
  84. get => timerSeconds;
  85. set => SetProperty(ref timerSeconds, value);
  86. }
  87. public string PickUpAddress
  88. {
  89. get => pickUpAddress;
  90. set
  91. {
  92. SetProperty(ref pickUpAddress, value);
  93. }
  94. }
  95. public string DropUpAddress
  96. {
  97. get => dropUpAddress;
  98. set
  99. {
  100. SetProperty(ref dropUpAddress, value);
  101. }
  102. }
  103. public bool IsBookingAvailable
  104. {
  105. get => isBookingAvailable;
  106. set => SetProperty(ref isBookingAvailable, value);
  107. }
  108. public bool VisibleTrip
  109. {
  110. get => visibleTrip;
  111. set => SetProperty(ref visibleTrip, value);
  112. }
  113. public string StartSuburb
  114. {
  115. get => startSuburb;
  116. set
  117. {
  118. SetProperty(ref startSuburb, value);
  119. }
  120. }
  121. public bool IsStartTripButtonVisible
  122. {
  123. get => isStartTripButtonVisible;
  124. set => SetProperty(ref isStartTripButtonVisible, value);
  125. }
  126. public string PickUpDateTimeOrEndSuburb
  127. {
  128. get => pickUpDateTimeOrEndSuburb;
  129. set => SetProperty(ref pickUpDateTimeOrEndSuburb, value);
  130. }
  131. public Thickness MainStackLayoutMargin
  132. {
  133. get { return new Thickness(mainStackLayoutMargin, 0, mainStackLayoutMargin, 20); }
  134. }
  135. public Thickness IndicatorMargin
  136. {
  137. get { return new Thickness(0, indicatorMargin, 0, 0); }
  138. }
  139. public Thickness LogoMargin
  140. {
  141. #if DEBUG
  142. get { return new Thickness(0, logoMargin, 0, 0); }
  143. #else
  144. get { return new Thickness(logoMargin, 0 , 0, 0); }
  145. #endif
  146. }
  147. public Thickness ImageLayoutMargin
  148. {
  149. #if DEBUG
  150. get { return new Thickness(0, topLayoutMargin, rightLayoutMargin, 0); }
  151. #else
  152. get { return new Thickness(0, topLayoutMargin, rightLayoutMargin, 0); }
  153. #endif
  154. }
  155. public Thickness ControlsMargin
  156. {
  157. get { return new Thickness(0, controlsMargin, 0, 0); }
  158. }
  159. public Thickness DummyButtonLayoutMargin
  160. {
  161. get { return new Thickness(0, dummyButtonLayoutMargin, 0, 0); }
  162. }
  163. public bool IsDummyButtonsVisible
  164. {
  165. get => isDummyButtonsVisible;
  166. set
  167. {
  168. SetProperty(ref isDummyButtonsVisible, value);
  169. }
  170. }
  171. public Command onCancelTripClick { get; }
  172. public Command OnMeterStartTripClick { get; }
  173. public Command OnMeterEndTripClick { get; }
  174. public string StartTimeOrEndLocation
  175. {
  176. get => startTimeOrEndLocation;
  177. set => SetProperty(ref startTimeOrEndLocation, value);
  178. }
  179. public bool IsOkButtonVisible
  180. {
  181. get => isOkButtonVisible;
  182. set => SetProperty(ref isOkButtonVisible, value);
  183. }
  184. public string BluetoothConnectionStatusText
  185. {
  186. get => bluetoothConnectionStatusText;
  187. set
  188. {
  189. SetProperty(ref bluetoothConnectionStatusText, value);
  190. BluetoothStatusChanged?.Invoke();
  191. }
  192. }
  193. public string DuressButtonText
  194. {
  195. get => duressButtonText;
  196. set
  197. {
  198. SetProperty(ref duressButtonText, value);
  199. }
  200. }
  201. public string ImageIcon
  202. {
  203. get => imageIcon;
  204. set
  205. {
  206. SetProperty(ref imageIcon, value);
  207. }
  208. }
  209. public bool IsPlotButtonVisible
  210. {
  211. get => isPlotButtonVisible;
  212. set => SetProperty(ref isPlotButtonVisible, value);
  213. }
  214. #endregion
  215. #region Constructor
  216. public TripInformationViewModel()
  217. {
  218. ContinuouslyShowAllPropertiesStatus();
  219. ShowStartTimerDuration(DispatchAppComponentService.isTripStarted);
  220. CountEndTripDuration(DispatchAppComponentService.isTripEndeded);
  221. lastMeterTripStatus = Preferences.Get("MeterTripStatus", 0);
  222. OnOkButtonClick = new Command(OnOkClick);
  223. OnStartEndTripClick = new Command(OnStartEndTripButtonClick);
  224. OnMeterStartTripClick = new Command(CallMeterStartTrip);
  225. OnMeterEndTripClick = new Command(MeterEndTrip);
  226. DuressButtonText = "!";
  227. CheckForConnectedMeter();
  228. #if DEBUG
  229. mainStackLayoutMargin = 30;
  230. indicatorMargin = 5;
  231. logoMargin = 20;
  232. IsDummyButtonsVisible = true;
  233. controlsMargin = 20;
  234. dummyButtonLayoutMargin = 10;
  235. topLayoutMargin = -5;
  236. rightLayoutMargin = -15;
  237. #else
  238. mainStackLayoutMargin = 30;
  239. indicatorMargin = 5;
  240. logoMargin = 20;
  241. IsDummyButtonsVisible = true;
  242. controlsMargin = 20;
  243. dummyButtonLayoutMargin = 10;
  244. topLayoutMargin = -5;
  245. rightLayoutMargin = -15;
  246. #endif
  247. }
  248. #endregion
  249. #region Methods
  250. private void OnStartEndTripButtonClick(object obj)
  251. {
  252. ManageDriverTrip(false);
  253. }
  254. private void OnOkClick()
  255. {
  256. DispatchAppComponentService.OnOkClick();
  257. DispatchAppComponentService.isPlotButtonVisible = true;
  258. ShowAllPropertiesStatus();
  259. }
  260. private void MeterStartTrip()
  261. {
  262. // setting MeterTripStarted only here to ensure a manual trip does not get mistaken for a meter trip
  263. if (!MeterTripStarted)
  264. {
  265. StartTripButtonText = DispatchAppComponentService.MeterStartTrip();
  266. ManageDriverTrip(true);
  267. }
  268. }
  269. private void MeterEndTrip()
  270. {
  271. if (MeterTripStarted)
  272. {
  273. StartTripButtonText = DispatchAppComponentService.MeterEndTrip();
  274. ManageDriverTrip(true);
  275. }
  276. }
  277. public void StartDriverDuress()
  278. {
  279. duressReleased = false;
  280. duressSeconds = 0;
  281. bool hasVibrated = false;
  282. Device.StartTimer(TimeSpan.FromSeconds(1), () =>
  283. {
  284. duressSeconds++;
  285. if (duressSeconds > 2)
  286. {
  287. if (!hasVibrated)
  288. {
  289. hasVibrated = true;
  290. Vibration.Vibrate(TimeSpan.FromSeconds(1));
  291. }
  292. }
  293. if (duressReleased)
  294. {
  295. return false;
  296. }
  297. else
  298. {
  299. return true;
  300. }
  301. });
  302. }
  303. public async void EndDriverDuress()
  304. {
  305. duressReleased = true;
  306. Vibration.Cancel();
  307. if (duressSeconds > 2)
  308. {
  309. var token = Preferences.Get(SecureStorageData.Token,"");
  310. GMCabsDriverService gmCabsDriverService = new GMCabsDriverService();
  311. var currentLocation = Geolocation.GetLastKnownLocationAsync();
  312. double currentLat = 0;
  313. double currentLng = 0;
  314. if (currentLocation != null && currentLocation.Result != null)
  315. {
  316. currentLat = currentLocation.Result.Latitude;
  317. currentLng = currentLocation.Result.Longitude;
  318. }
  319. await gmCabsDriverService.DriverDistress(token, currentLat, currentLng);
  320. DuressButtonText = "...";
  321. await System.Threading.Tasks.Task.Delay(2000);
  322. DuressButtonText = "!";
  323. }
  324. }
  325. private void ShowStartTimerDuration(bool isTripStarted)
  326. {
  327. seconds = DispatchAppComponentService.seconds;
  328. if (isTripStarted)
  329. {
  330. Device.StartTimer(TimeSpan.FromSeconds(1), () =>
  331. {
  332. var meterRunningStatus = Preferences.Get("MeterRunningStatus", "");
  333. if (meterRunningStatus == "Running")
  334. {
  335. Device.BeginInvokeOnMainThread(() =>
  336. {
  337. ++seconds;
  338. DispatchAppComponentService.StartTrip(seconds);
  339. TimerSeconds = DispatchAppComponentService.timerSeconds;
  340. DispatchAppComponentService.seconds = seconds;
  341. });
  342. }
  343. if (meterRunningStatus == "Running")
  344. return true;
  345. else
  346. return false;
  347. });
  348. }
  349. }
  350. private void CountEndTripDuration(bool isTripEnded)
  351. {
  352. autocloseOkSecond = DispatchAppComponentService.autocloseOkSecond;
  353. if (isTripEnded)
  354. {
  355. Device.StartTimer(TimeSpan.FromSeconds(1), () =>
  356. {
  357. var meterRunningStatus = Preferences.Get("MeterRunningStatus", "");
  358. if (meterRunningStatus == "Stopped")
  359. {
  360. if (autocloseOkSecond == 0)
  361. {
  362. Device.BeginInvokeOnMainThread(() =>
  363. {
  364. OnOkClick();
  365. });
  366. }
  367. else
  368. {
  369. --autocloseOkSecond;
  370. DispatchAppComponentService.autocloseOkSecond = autocloseOkSecond;
  371. }
  372. }
  373. if (meterRunningStatus == "Stopped")
  374. return true;
  375. else
  376. return false;
  377. });
  378. }
  379. }
  380. private void ShowAllPropertiesStatus()
  381. {
  382. ImageIcon = DispatchAppComponentService.imageIcon;
  383. IsStartTripButtonVisible = DispatchAppComponentService.isStartTripButtonVisible;
  384. IsPlotButtonVisible = DispatchAppComponentService.isPlotButtonVisible;
  385. StartTripButtonText = DispatchAppComponentService.startTripButtonText;
  386. MeterTripStarted = DispatchAppComponentService.meterTripStarted;
  387. VisibleTrip = DispatchAppComponentService.visibleTrip;
  388. StartSuburb = DispatchAppComponentService.startSuburb;
  389. PickUpDateTimeOrEndSuburb = DispatchAppComponentService.pickUpDateTimeOrEndSuburb;
  390. StartTimeOrEndLocation = DispatchAppComponentService.startTimeOrEndLocation;
  391. IsOkButtonVisible = DispatchAppComponentService.isOkButtonVisible;
  392. TimerSeconds = DispatchAppComponentService.timerSeconds;
  393. }
  394. private void ContinuouslyShowAllPropertiesStatus()
  395. {
  396. Device.StartTimer(TimeSpan.FromSeconds(1), () =>
  397. {
  398. Device.BeginInvokeOnMainThread(() =>
  399. {
  400. ShowAllPropertiesStatus();
  401. });
  402. return true;
  403. });
  404. }
  405. public void SetTripStartEndButtonPosition()
  406. {
  407. DispatchAppComponentService.isPlotButtonVisible= false;
  408. ShowAllPropertiesStatus();
  409. }
  410. #endregion
  411. #region Trip Handling
  412. private void ManageDriverTrip(bool fromMeter)
  413. {
  414. if (StartTripButtonText.Equals("START TRIP"))
  415. {
  416. DispatchAppComponentService.isTripStarted = true;
  417. DispatchAppComponentService.isTripEndeded = false;
  418. DispatchAppComponentService.ManageDriverTrip(fromMeter);
  419. StartTimeOrEndLocation = DispatchAppComponentService.startTimeOrEndLocation;
  420. StartTrip(fromMeter);
  421. TimerSeconds = DispatchAppComponentService.timerSeconds;
  422. DispatchAppComponentService.seconds = seconds = 0;
  423. ShowStartTimerDuration(DispatchAppComponentService.isTripStarted);
  424. DispatchAppComponentService.isPlotButtonVisible = false;
  425. }
  426. else if (StartTripButtonText.Equals("DROP OFF"))
  427. {
  428. DispatchAppComponentService.isTripStarted = false;
  429. DispatchAppComponentService.isTripEndeded = true;
  430. DispatchAppComponentService.ManageDriverTrip(fromMeter);
  431. StartTimeOrEndLocation = DispatchAppComponentService.startTimeOrEndLocation;
  432. EndTrip(fromMeter);
  433. IsOkButtonVisible = DispatchAppComponentService.isOkButtonVisible;
  434. DispatchAppComponentService.autocloseOkSecond = autocloseOkSecond = 30;
  435. CountEndTripDuration(DispatchAppComponentService.isTripEndeded);
  436. }
  437. }
  438. private async void StartTrip(bool fromMeter)
  439. {
  440. DispatchAppComponentService.startSuburb = await DispatchAppComponentService.GetSuburbName(fromMeter, true);
  441. MeterTripStarted = DispatchAppComponentService.meterTripStarted;
  442. ImageIcon = DispatchAppComponentService.imageIcon;
  443. VisibleTrip = DispatchAppComponentService.visibleTrip;
  444. StartSuburb = DispatchAppComponentService.startSuburb;
  445. PickUpDateTimeOrEndSuburb = DispatchAppComponentService.pickUpDateTimeOrEndSuburb;
  446. StartTripButtonText = DispatchAppComponentService.startTripButtonText;
  447. }
  448. private async void EndTrip(bool fromMeter)
  449. {
  450. DispatchAppComponentService.pickUpDateTimeOrEndSuburb = await DispatchAppComponentService.GetSuburbName(fromMeter, false);
  451. MeterTripStarted = DispatchAppComponentService.meterTripStarted;
  452. PickUpDateTimeOrEndSuburb = DispatchAppComponentService.pickUpDateTimeOrEndSuburb;
  453. ImageIcon = DispatchAppComponentService.imageIcon;
  454. IsStartTripButtonVisible = DispatchAppComponentService.isStartTripButtonVisible;
  455. }
  456. private void CallMeterStartTrip()
  457. {
  458. DispatchAppComponentService.startTripButtonText = "START TRIP";
  459. DispatchAppComponentService.meterTripStarted = false;
  460. DispatchAppComponentService.isTripStarted = true;
  461. DispatchAppComponentService.isTripEndeded = false;
  462. DispatchAppComponentService.isOkButtonVisible = false;
  463. DispatchAppComponentService.isStartTripButtonVisible = true;
  464. DispatchAppComponentService.ManageDriverTrip(false);
  465. StartTimeOrEndLocation = DispatchAppComponentService.startTimeOrEndLocation;
  466. StartTrip(false);
  467. TimerSeconds = DispatchAppComponentService.timerSeconds;
  468. DispatchAppComponentService.seconds = seconds = 0;
  469. ShowStartTimerDuration(DispatchAppComponentService.isTripStarted);
  470. }
  471. #endregion Trip Handling
  472. #region Meter Handling
  473. private void CheckForConnectedMeter()
  474. {
  475. // ConnectToMeter();
  476. }
  477. //private void ConnectToMeter()
  478. //{
  479. // adapter = CrossBleAdapter.Current;
  480. // var status = adapter.Status.ToString();
  481. // if (status.Contains("Off"))
  482. // {
  483. // bluetoothConnectionStatusText = "Bluetooth connection off...";
  484. // }
  485. // else
  486. // {
  487. // BluetoothConnectionStatusText = "Checking meter connection...";
  488. // BluetoothConnectionStatusText = $"Adapter status {CrossBleAdapter.Current.Status.ToString()}";
  489. // IDevice bondedDevice = null;
  490. // CrossBleAdapter.Current.GetConnectedDevices().Subscribe(deviceResult =>
  491. // {
  492. // bondedDevice = deviceResult.GetEnumerator().Current;
  493. // });
  494. // if (bondedDevice != null && bondedDevice.Status == ConnectionStatus.Connected)
  495. // {
  496. // ListenForCharacteristic(bondedDevice);
  497. // }
  498. // else
  499. // {
  500. // CrossBleAdapter.Current.GetPairedDevices().Subscribe(devices =>
  501. // {
  502. // if (devices != null)
  503. // {
  504. // ConnectionConfig conConfig = new ConnectionConfig();
  505. // conConfig.AutoConnect = true;
  506. // BluetoothConnectionStatusText = $"Listening for paired device";
  507. // foreach (var pairedDevice in devices)
  508. // {
  509. // pairedDevice.ConnectWait(conConfig).Subscribe(device =>
  510. // {
  511. // Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { BluetoothConnectionStatusText = $"{device.Status}"; });
  512. // ListenForCharacteristic(pairedDevice);
  513. // });
  514. // }
  515. // }
  516. // });
  517. // if (CrossBleAdapter.Current.IsScanning)
  518. // {
  519. // BluetoothConnectionStatusText = $"resuming scan";
  520. // }
  521. // else
  522. // {
  523. // BluetoothConnectionStatusText = $"Adapter status {CrossBleAdapter.Current.Status.ToString()} - Scanning";
  524. // Characteristics = new List<IGattCharacteristic>();
  525. // var scanResult = CrossBleAdapter.Current.Scan().Subscribe(scResult => { CheckDevice(scResult); }, exception =>
  526. // {
  527. // Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { BluetoothConnectionStatusText = $"Error: {exception.Message}"; });
  528. // });
  529. // }
  530. // }
  531. // }
  532. //}
  533. //private void CheckDevice(IScanResult scanResult)
  534. //{
  535. // if (scanResult.Device.Name != null && scanResult.Device.Name.StartsWith("MTI_") && !foundDevice)
  536. // {
  537. // BluetoothConnectionStatusText = $"Meter found - {scanResult.Device.Name}";
  538. // foundDevice = true;
  539. // CrossBleAdapter.Current.StopScan();
  540. // ConnectToDevice(scanResult.Device);
  541. // }
  542. //}
  543. //private void ConnectToDevice(IDevice discoveredDevice)
  544. //{
  545. // ConnectionConfig conConfig = new ConnectionConfig();
  546. // conConfig.AutoConnect = true;
  547. // Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { BluetoothConnectionStatusText = $"Device Details - P:{discoveredDevice.PairingStatus.ToString()} - C:{discoveredDevice.IsConnected()}"; });
  548. // if (discoveredDevice.IsConnected())
  549. // {
  550. // Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { BluetoothConnectionStatusText = $"Searching for GUIDs"; });
  551. // ListenForCharacteristic(discoveredDevice);
  552. // }
  553. // else
  554. // {
  555. // if (discoveredDevice.PairingStatus == PairingStatus.NotPaired)
  556. // {
  557. // Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { BluetoothConnectionStatusText = $"Pairing"; });
  558. // discoveredDevice.PairingRequest("191135");
  559. // }
  560. // Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { BluetoothConnectionStatusText = $"Connecting"; });
  561. // discoveredDevice.ConnectWait(conConfig).Subscribe(device =>
  562. // {
  563. // Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { BluetoothConnectionStatusText = $"{device.Status}"; });
  564. // ListenForCharacteristic(device);
  565. // });
  566. // }
  567. //}
  568. //private void ListenForCharacteristic(IDevice device)
  569. //{
  570. // bool subscribed = false;
  571. // try
  572. // {
  573. // device.GetKnownCharacteristics(Guid.Parse("de201840-063f-11e5-be3e-0002a5d5c51b"), new Guid[] { Guid.Parse("de000180-063f-11e5-9e69-0002a5d5c503") }).Subscribe(characteristics =>
  574. // {
  575. // Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { BluetoothConnectionStatusText = $"Service Detected"; });
  576. // if (characteristics != null)
  577. // {
  578. // characteristics.RegisterAndNotify().Subscribe(registerResult =>
  579. // {
  580. // // RegisterAndNotify seems to keep firing each time, there must be a better way
  581. // // to do this only once, currently just setting a local flag.
  582. // if (!subscribed)
  583. // {
  584. // Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
  585. // {
  586. // BluetoothConnectionStatusText = "Ready";
  587. // });
  588. // subscribed = true;
  589. // characteristics.WhenNotificationReceived().Subscribe(notification => { CheckNotification(notification); });
  590. // }
  591. // });
  592. // }
  593. // });
  594. // }
  595. // catch(Exception ex)
  596. // {
  597. // }
  598. //}
  599. //private void CheckNotification(CharacteristicGattResult notification)
  600. //{
  601. // if (notification != null && notification.Data != null && notification.Characteristic != null && notification.Characteristic.Uuid.ToString() == "de000180-063f-11e5-9e69-0002a5d5c503")
  602. // {
  603. // string data = $"Date:{DateTime.Now.ToString("HH:mm:ss")}, Description:{notification.Characteristic.Uuid},Data:{BitConverter.ToString(notification.Data)}\n";
  604. // Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
  605. // {
  606. // int tripStatus = 0;
  607. // if (notification.Data[0] != 0) { tripStatus = 1; }
  608. // if (lastMeterTripStatus != tripStatus)
  609. // {
  610. // lastMeterTripStatus = tripStatus;
  611. // Preferences.Set("MeterTripStatus", tripStatus);
  612. // if (tripStatus == 0)
  613. // {
  614. // MeterEndTrip();
  615. // }
  616. // else if (tripStatus == 1)
  617. // {
  618. // //MeterStartTrip();
  619. // CallMeterStartTrip();
  620. // }
  621. // }
  622. // });
  623. // }
  624. //}
  625. #endregion Meter Handling
  626. }
  627. }