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.

144 lines
5.1 KiB

1 year ago
  1. using GMCabsDriverAssistant.Models;
  2. using GMCabsDriverAssistant.Utils;
  3. using GMCabsDriverAssistant.ViewModels;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Microsoft.Maui;
  9. using Microsoft.Maui.Controls;
  10. using GMCabsDriverAssistantSolution.ViewModels;
  11. namespace GMCabsDriverAssistant.Services
  12. {
  13. public class DispatchAppComponentService : BaseViewModel
  14. {
  15. #region Properties
  16. public static DispatchAppComponentService _instance = null;
  17. public static object chekLock = new object();
  18. public static string startTripButtonText = "START TRIP";
  19. public static string startTimeOrEndLocation = "";
  20. public static string timerSeconds = "00:00:00";
  21. public static bool meterTripStarted = false;
  22. public static bool visibleTrip = false;
  23. public static string startSuburb = "";
  24. public static bool isOkButtonVisible = false;
  25. public static bool isStartTripButtonVisible = true;
  26. public static bool isPlotButtonVisible = true;
  27. public static string pickUpDateTimeOrEndSuburb = "";
  28. public static bool isTripStarted = false;
  29. public static bool isTripEndeded = false;
  30. public static int seconds = 0;
  31. public static int autocloseOkSecond = 30;
  32. public static string bluetoothConnectionStatusText;
  33. public static string imageIcon = "avail_button.png";
  34. #endregion
  35. #region Constructor
  36. private DispatchAppComponentService()
  37. {
  38. }
  39. public static DispatchAppComponentService Instance
  40. {
  41. get
  42. {
  43. lock (chekLock)
  44. {
  45. if (_instance == null)
  46. _instance = new DispatchAppComponentService();
  47. return _instance;
  48. }
  49. }
  50. }
  51. #endregion
  52. #region Methods
  53. public static void ManageDriverTrip(bool fromMeter)
  54. {
  55. if (startTripButtonText.Equals("START TRIP"))
  56. {
  57. startTimeOrEndLocation = "Start Time";
  58. startTrip(fromMeter);
  59. timerSeconds = "00:00:00";
  60. }
  61. else if (startTripButtonText.Equals("DROP OFF"))
  62. {
  63. startTimeOrEndLocation = "Ending At";
  64. endTrip(fromMeter);
  65. isOkButtonVisible = true;
  66. }
  67. }
  68. private static void startTrip(bool fromMeter)
  69. {
  70. meterTripStarted = true;
  71. imageIcon = "busy_button.png";
  72. visibleTrip = true;
  73. pickUpDateTimeOrEndSuburb = DateTime.Now.ToString("dd MMM hh:mm tt");
  74. startTripButtonText = "DROP OFF";
  75. Preferences.Set("MeterRunningStatus", "Running");
  76. }
  77. private static void endTrip(bool fromMeter)
  78. {
  79. meterTripStarted = true;
  80. imageIcon = "avail_button.png";
  81. isStartTripButtonVisible = false;
  82. Preferences.Set("MeterRunningStatus", "Stopped");
  83. }
  84. public async static Task<string> GetSuburbName(bool fromMeter, bool isStart)
  85. {
  86. int statusflags = 0;
  87. var token = Preferences.Get(SecureStorageData.Token,"");
  88. if (isStart)
  89. statusflags = Constant.DRIVER_STATUS_ON_TRIP;
  90. else
  91. statusflags = Constant.DRIVER_STATUS_AVAILABLE;
  92. GMCabsDriverService gmCabsDriverService = new GMCabsDriverService();
  93. var suburbName = await gmCabsDriverService.UpdateBookingStatus(token, statusflags, fromMeter);
  94. return suburbName;
  95. }
  96. public static void StartTrip(int seconds)
  97. {
  98. ++seconds;
  99. timerSeconds = (seconds / 3600 <= 9 ? "0" + seconds / 3600 : "" + seconds / 3600) + ":" + ((seconds % 3600) / 60 <= 9 ? "0" + (seconds % 3600) / 60 : "" + (seconds % 3600) / 60) + ":" + (seconds % 60 <= 9 ? "0" + seconds % 60 : "" + seconds % 60);
  100. }
  101. public static void OnOkClick()
  102. {
  103. visibleTrip = false;
  104. startTripButtonText = "START TRIP";
  105. isStartTripButtonVisible = true;
  106. isOkButtonVisible = false;
  107. Preferences.Set("MeterRunningStatus", "");
  108. }
  109. public static string MeterStartTrip()
  110. {
  111. startTripButtonText = "START TRIP";
  112. return startTripButtonText;
  113. }
  114. public static string MeterEndTrip()
  115. {
  116. startTripButtonText = "DROP OFF";
  117. return startTripButtonText;
  118. }
  119. public static void SetToInitialProperties()
  120. {
  121. startTripButtonText = "START TRIP";
  122. startTimeOrEndLocation = "";
  123. timerSeconds = "00:00:00";
  124. meterTripStarted = false;
  125. imageIcon = "avail_button.png";
  126. visibleTrip = false;
  127. startSuburb = "";
  128. isOkButtonVisible = false;
  129. isStartTripButtonVisible = true;
  130. pickUpDateTimeOrEndSuburb = "";
  131. isTripStarted = false;
  132. isTripEndeded = false;
  133. seconds = 0;
  134. autocloseOkSecond = 30;
  135. }
  136. #endregion
  137. }
  138. }