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.

382 lines
14 KiB

  1. using GMCabsDriverAssistant.Models;
  2. using GMCabsDriverAssistant.Models.Rydo;
  3. using GMCabsDriverAssistant.Services;
  4. using GMCabsDriverAssistantSolution.Models.Rydo;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. using System.Net;
  10. using System.Text;
  11. using System.Text.Json;
  12. using System.Threading.Tasks;
  13. namespace GMCabsDriverAssistantSolution.ViewModels
  14. {
  15. [QueryProperty(nameof(RideRequestJson), nameof(RideRequestJson))]
  16. public class StartRideViewModel : BaseViewModel
  17. {
  18. #region Fields
  19. private string rideRequestJson;
  20. private string passengerName;
  21. private bool isCorporate;
  22. private string fullDestinationAddress;
  23. private StartRideResponse startRideResponse;
  24. private int frameWidth;
  25. private bool stopOver = false;
  26. private bool noStopOver = false;
  27. private int index = 0;
  28. private double destinationCircleColorOpecity = 0.2;
  29. private string destinationStopLabelColorCode = "#BECEDA";
  30. private bool isStopOver = false;
  31. private bool isNoStopOver = false;
  32. StartRideRequestDto startRideRequestDto;
  33. Page _page;
  34. public string meterRunningStatus;
  35. private string locationSuburbName;
  36. private string startSuburb;
  37. private string pickUpDateTime;
  38. private string timerSeconds;
  39. public int seconds = 0;
  40. private bool visibleTrip;
  41. private bool isEndTripButtonVisible = true;
  42. private string startTimeOrEndLocation;
  43. #endregion
  44. #region Properties
  45. public List<StopoverLocations> StopoverLocations { get; }
  46. public ObservableCollection<StopoverLocations> StopoverLocationsList { get; }
  47. public Command OnPassengerCollectedClick { get; }
  48. public string RideRequestJson
  49. {
  50. get => rideRequestJson;
  51. set
  52. {
  53. rideRequestJson = value;
  54. ProcessRiding(value);
  55. }
  56. }
  57. public string PassengerName
  58. {
  59. get => passengerName;
  60. set => SetProperty(ref passengerName, value);
  61. }
  62. public bool IsCorporate
  63. {
  64. get => isCorporate;
  65. set => SetProperty(ref isCorporate, value);
  66. }
  67. public string FullDestinationAddress
  68. {
  69. get => fullDestinationAddress;
  70. set => SetProperty(ref fullDestinationAddress, value);
  71. }
  72. public bool StopOver
  73. {
  74. get => stopOver;
  75. set => SetProperty(ref stopOver, value);
  76. }
  77. public bool NoStopOver
  78. {
  79. get => noStopOver;
  80. set => SetProperty(ref noStopOver, value);
  81. }
  82. public bool IsStopOver
  83. {
  84. get => isStopOver;
  85. set => SetProperty(ref isStopOver, value);
  86. }
  87. public bool IsNoStopOver
  88. {
  89. get => isNoStopOver;
  90. set => SetProperty(ref isNoStopOver, value);
  91. }
  92. public int FrameWidth
  93. {
  94. get => frameWidth;
  95. set => SetProperty(ref frameWidth, value);
  96. }
  97. public double DestinationCircleColorOpecity
  98. {
  99. get => destinationCircleColorOpecity;
  100. set => SetProperty(ref destinationCircleColorOpecity, value);
  101. }
  102. public string DestinationStopLabelColorCode
  103. {
  104. get => destinationStopLabelColorCode;
  105. set => SetProperty(ref destinationStopLabelColorCode, value);
  106. }
  107. public string StartSuburb
  108. {
  109. get => startSuburb;
  110. set
  111. {
  112. SetProperty(ref startSuburb, value);
  113. }
  114. }
  115. public string PickUpDateTime
  116. {
  117. get => pickUpDateTime;
  118. set => SetProperty(ref pickUpDateTime, value);
  119. }
  120. public string TimerSeconds
  121. {
  122. get => timerSeconds;
  123. set => SetProperty(ref timerSeconds, value);
  124. }
  125. public bool VisibleTrip
  126. {
  127. get => visibleTrip;
  128. set => SetProperty(ref visibleTrip, value);
  129. }
  130. public bool IsEndTripButtonVisible
  131. {
  132. get => isEndTripButtonVisible;
  133. set => SetProperty(ref isEndTripButtonVisible, value);
  134. }
  135. public string StartTimeOrEndLocation
  136. {
  137. get => startTimeOrEndLocation;
  138. set => SetProperty(ref startTimeOrEndLocation, value);
  139. }
  140. public Command OnPassengerDroppedOffClick { get; }
  141. public Command onEndTripClick { get; }
  142. #endregion
  143. #region Constructor
  144. public StartRideViewModel(Page page)
  145. {
  146. Title = "Passenger Collected";
  147. StopoverLocations = new List<StopoverLocations>();
  148. StopoverLocationsList = new ObservableCollection<StopoverLocations>();
  149. OnPassengerCollectedClick = new Command(PassengerCollected);
  150. startRideRequestDto = new StartRideRequestDto();
  151. OnPassengerDroppedOffClick = new Command(PassengerDroppedOff);
  152. _page = page;
  153. meterRunningStatus = Preferences.Get("MeterRunningStatus", "");
  154. StartTimeOrEndLocation = "Start Time";
  155. }
  156. #endregion
  157. #region Methods
  158. private async void ProcessRiding(string rideRequestJson)
  159. {
  160. string rydoAccessToken = Preferences.Get(EftposLoginResponse.RYDO_ACCESS_TOKEN, "");
  161. GMCabsDriverService gmCabsDriverService = new GMCabsDriverService();
  162. startRideRequestDto = JsonSerializer.Deserialize<StartRideRequestDto>(rideRequestJson);
  163. StartRideRequest startRideRequest = startRideRequestDto.startRideRequest;
  164. if (startRideRequest.DriverId == "")
  165. {
  166. await Shell.Current.GoToAsync("..");
  167. }
  168. startRideResponse = new StartRideResponse();
  169. startRideResponse = await gmCabsDriverService.StartRiding(startRideRequest, rydoAccessToken, startRideRequestDto.BookingId.ToString());
  170. if (startRideResponse.StatusCode == (int)HttpStatusCode.OK)
  171. {
  172. PassengerName = startRideResponse.PassengerName;
  173. IsCorporate = startRideResponse.IsCorporate;
  174. startRideResponse.DriverId = startRideRequest.DriverId;
  175. startRideResponse.BookingId = startRideRequestDto.BookingId;
  176. if (IsCorporate)
  177. {
  178. FrameWidth = 310;
  179. }
  180. else
  181. {
  182. FrameWidth = 370;
  183. }
  184. startRideResponse.FrameWidth = FrameWidth;
  185. FullDestinationAddress = startRideResponse.EndAddress + " " + startRideResponse.EndSuburb;
  186. var locations = new List<StopoverLocations>();
  187. //These below-mentioned commented out codes are witten for checking the lists of Stop Over Locations as a mock data
  188. //because of unable to fetch real stop over location data from the dev rydo booking page
  189. //locations.Add(new StopoverLocations
  190. //{
  191. // Latitude = -32.63,
  192. // Longitude = 151.55,
  193. // Address = "1 Milson St",
  194. // Suburb = "Charlestown",
  195. // StopNumber = 1
  196. //});
  197. //locations.Add(new StopoverLocations
  198. //{
  199. // Latitude = -36.17,
  200. // Longitude = 144.66,
  201. // Address = "1/1 Milson St",
  202. // Suburb = "Charlestown",
  203. // StopNumber = 2
  204. //});
  205. //locations.Add(new StopoverLocations
  206. //{
  207. // Latitude = -36.17,
  208. // Longitude = 144.66,
  209. // Address = "1/1 Milson St",
  210. // Suburb = "Charlestown",
  211. // StopNumber = 3
  212. //});
  213. //locations.Add(new StopoverLocations
  214. //{
  215. // Latitude = -36.17,
  216. // Longitude = 144.66,
  217. // Address = "1/1 Milson St",
  218. // Suburb = "Charlestown",
  219. // StopNumber = 2
  220. //});
  221. //locations.Add(new StopoverLocations
  222. //{
  223. // Latitude = -36.17,
  224. // Longitude = 144.66,
  225. // Address = "1/1 Milson St",
  226. // Suburb = "Charlestown",
  227. // StopNumber = 2
  228. //});
  229. //locations.Add(new StopoverLocations
  230. //{
  231. // Latitude = -36.17,
  232. // Longitude = 144.66,
  233. // Address = "1/1 Milson St",
  234. // Suburb = "Charlestown",
  235. // StopNumber = 2
  236. //});
  237. locations.Add(new StopoverLocations
  238. {
  239. Latitude = startRideResponse.EndLatitude,
  240. Longitude = startRideResponse.EndLongitude,
  241. Address = startRideResponse.EndAddress,
  242. Suburb = startRideResponse.EndSuburb,
  243. StopNumber = startRideResponse.StopoverLocations.Count + 1
  244. });
  245. startRideResponse.StopoverLocations.AddRange(locations);
  246. if (startRideResponse.StopoverLocations.Count > 0)
  247. {
  248. StopOver = true;
  249. NoStopOver = false;
  250. IsStopOver = true;
  251. IsNoStopOver = false;
  252. StopoverLocations.Clear();
  253. foreach (var locationlists in startRideResponse.StopoverLocations)
  254. {
  255. StopoverLocations.Add(locationlists);
  256. }
  257. setPrimaryStopOverLocation(StopoverLocations);
  258. }
  259. else
  260. {
  261. StopOver = false;
  262. NoStopOver = true;
  263. IsStopOver = false;
  264. IsNoStopOver = true;
  265. }
  266. if (startRideResponse.FixedAmount != null)
  267. {
  268. decimal amount = Convert.ToDecimal(startRideResponse.FixedAmount) / 100.0m;
  269. amount = amount * 1.00m;
  270. startRideResponse.FixedAmount = amount;
  271. }
  272. }
  273. }
  274. private void setPrimaryStopOverLocation(List<StopoverLocations> stopoverLocations)
  275. {
  276. StopoverLocationsList.Clear();
  277. int stopOverLocationCount = 1;
  278. foreach (var location in stopoverLocations)
  279. {
  280. if (stopOverLocationCount == stopoverLocations.Count)
  281. {
  282. location.IsLineVisible = false;
  283. }
  284. location.LabelColor = "#BBB9B9";
  285. location.CircleColorOpecity = 0.2;
  286. StopoverLocationsList.Add(location);
  287. if (stopoverLocations.Count == 1)
  288. {
  289. location.LabelColor = "Black";
  290. location.CircleColorOpecity = 0.5;
  291. IsStopOver = false;
  292. IsNoStopOver = true;
  293. }
  294. stopOverLocationCount++;
  295. }
  296. }
  297. private void setStopOverLocation(List<StopoverLocations> stopoverLocations)
  298. {
  299. StopoverLocationsList.Clear();
  300. int stopoverLocationIndex = 0;
  301. foreach (var location in stopoverLocations)
  302. {
  303. if (stopoverLocationIndex == stopoverLocations.Count - 1)
  304. {
  305. location.IsLineVisible = false;
  306. }
  307. if (stopoverLocationIndex == index)
  308. {
  309. location.LabelColor = "Black";
  310. location.CircleColorOpecity = 0.5;
  311. }
  312. else
  313. {
  314. location.LabelColor = "#BBB9B9";
  315. location.CircleColorOpecity = 0.2;
  316. }
  317. StopoverLocationsList.Add(location);
  318. stopoverLocationIndex++;
  319. }
  320. }
  321. private async void PassengerCollected()
  322. {
  323. int stop_number = StopoverLocationsList[index].StopNumber;
  324. string booking_id = startRideRequestDto.BookingId.ToString();
  325. string rydoAccessToken = Preferences.Get(EftposLoginResponse.RYDO_ACCESS_TOKEN, "");
  326. GMCabsDriverService gmCabsDriverService = new GMCabsDriverService();
  327. await gmCabsDriverService.NotifyStop(stop_number, rydoAccessToken, booking_id);
  328. int StopoverLocationsListCount = StopoverLocationsList.Count;
  329. setStopOverLocation(StopoverLocations);
  330. if (index == StopoverLocationsListCount - 1)
  331. {
  332. DestinationStopLabelColorCode = "Black";
  333. DestinationCircleColorOpecity = 0.5;
  334. IsStopOver = false;
  335. IsNoStopOver = true;
  336. }
  337. index = index + 1;
  338. }
  339. public async void PassengerDroppedOff()
  340. {
  341. //if (meterRunningStatus == "Stopped")
  342. //{
  343. //UpdateBookingStatus();
  344. //if (startRideResponse.PaymentMethodId == null && startRideResponse.FixedAmount == null)
  345. //{
  346. // await _page.Navigation.PushAsync(new PassengerDroppedWithNoPaymentMethodIdNoFixedFareTablet(startRideResponse));
  347. //}
  348. //else if (startRideResponse.PaymentMethodId == null && startRideResponse.FixedAmount != null)
  349. //{
  350. // await _page.Navigation.PushAsync(new PassengerDroppedWithNoPaymentMethodIdAndFixedFareTablet(startRideResponse));
  351. //}
  352. //else if (startRideResponse.PaymentMethodId != null && startRideResponse.FixedAmount != null)
  353. //{
  354. // await _page.Navigation.PushAsync(new PassengerDroppedWithPaymentMethodIdAndFixedFareTablet(startRideResponse));
  355. //}
  356. //else if (startRideResponse.PaymentMethodId != null && startRideResponse.FixedAmount == null)
  357. //{
  358. // await _page.Navigation.PushAsync(new PassengerDroppedWithPaymentMethodIdNoFixedFareTablet(startRideResponse));
  359. //}
  360. //}
  361. //else
  362. //{
  363. // _page.Navigation.ShowPopup(new MeterTripStatusDialogPage(this._page, startRideResponse));
  364. //}
  365. }
  366. #endregion
  367. }
  368. }