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.

220 lines
9.3 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. using GMCabsDriverAssistant.Models;
  2. using GMCabsDriverAssistant.Services;
  3. using GMCabsDriverAssistant.Utils;
  4. using GMCabsDriverAssistantSolution.Styles;
  5. using Plugin.FirebasePushNotification;
  6. using Plugin.SimpleAudioPlayer;
  7. using System.Diagnostics;
  8. namespace GMCabsDriverAssistantSolution;
  9. public partial class App : Application
  10. {
  11. private static SQLiteDatabaseService database;
  12. public static SQLiteDatabaseService Database
  13. {
  14. get
  15. {
  16. if (database == null)
  17. {
  18. string databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "AvailableBooking.db3");
  19. database = new SQLiteDatabaseService(databasePath);
  20. }
  21. return database;
  22. }
  23. }
  24. public App()
  25. {
  26. InitializeComponent();
  27. dictionary.MergedDictionaries.Add(PhoneLayoutStyle.SharedInstance);
  28. MainPage = new AppShell();
  29. }
  30. [Obsolete]
  31. protected override async void OnStart()
  32. {
  33. try
  34. {
  35. ShareConstant.IsInForeground = true;
  36. Preferences.Set(SecureStorageData.InitLaunched, "");
  37. CrossFirebasePushNotification.Current.Subscribe("all");
  38. CrossFirebasePushNotification.Current.OnTokenRefresh += (s, e) =>
  39. {
  40. Debug.WriteLine($"Token: {e.Token}");
  41. };
  42. Debug.WriteLine($"TOKEN: {CrossFirebasePushNotification.Current.Token}");
  43. CrossFirebasePushNotification.Current.OnNotificationReceived += (s, e) =>
  44. {
  45. try
  46. {
  47. Debug.WriteLine("Received");
  48. if (e.Data.ContainsKey("category"))
  49. {
  50. if (e.Data["category"].ToString().Equals("BookingCancelled"))
  51. {
  52. Device.BeginInvokeOnMainThread(() =>
  53. {
  54. CancelledBookingResponseDto cancelledBookingResponseDto = new CancelledBookingResponseDto();
  55. cancelledBookingResponseDto.PickUPAddress = e.Data["fromAddress"].ToString();
  56. cancelledBookingResponseDto.DropUpAddress = e.Data["toAddress"].ToString();
  57. MessagingCenter.Send(this, nameof(App), cancelledBookingResponseDto);
  58. if (Device.RuntimePlatform == Device.iOS)
  59. {
  60. if (ShareConstant.IsInForeground)
  61. {
  62. var player = CrossSimpleAudioPlayer.Current;
  63. player.Load("system.wav");
  64. player.Play();
  65. }
  66. }
  67. });
  68. }
  69. else if (e.Data["category"].ToString().Equals("BookingClearAccepted"))
  70. {
  71. Device.BeginInvokeOnMainThread(() =>
  72. {
  73. MessagingCenter.Send(this, "ClearAcceptance", string.Empty);
  74. });
  75. }
  76. else if (e.Data["category"].ToString().Equals("CouponRedeemed"))
  77. {
  78. Device.BeginInvokeOnMainThread(() =>
  79. {
  80. CouponDto coupon = new CouponDto();
  81. coupon.Id = e.Data["couponid"].ToString();
  82. coupon.Status = e.Data["status"].ToString();
  83. MessagingCenter.Send(this, nameof(App), coupon);
  84. });
  85. }
  86. else if (e.Data["category"].ToString().Equals("NotificationAvailable"))
  87. {
  88. Device.BeginInvokeOnMainThread(() =>
  89. {
  90. NotificationDto notification = new NotificationDto();
  91. notification.Id = e.Data["id"].ToString();
  92. notification.Subject = e.Data["subject"].ToString();
  93. notification.Body = e.Data["notification_body"].ToString();
  94. MessagingCenter.Send(this, nameof(App), notification);
  95. if (Device.RuntimePlatform == Device.iOS)
  96. {
  97. if (ShareConstant.IsInForeground)
  98. {
  99. var player = CrossSimpleAudioPlayer.Current;
  100. player.Load("system.wav");
  101. player.Play();
  102. }
  103. }
  104. });
  105. }
  106. else if (e.Data["category"].ToString().Equals("IsTabletInstallation"))
  107. {
  108. Debug.WriteLine($"{e.Data["category"]}");
  109. var istablet = Convert.ToBoolean(e.Data["istabletinstallation"].ToString());
  110. Preferences.Set("IsTablet", istablet);
  111. MessagingCenter.Send(this, nameof(App), e.Data["category"].ToString());
  112. }
  113. else if (e.Data["category"].ToString().Equals("DriverAlertNotification"))
  114. {
  115. Device.BeginInvokeOnMainThread(() =>
  116. {
  117. Debug.WriteLine($"{e.Data["category"]}");
  118. MessagingCenter.Send(this, nameof(App), e.Data["category"].ToString());
  119. });
  120. }
  121. else if (e.Data["category"].ToString().Equals("CouponAvailable"))
  122. {
  123. Device.BeginInvokeOnMainThread(() =>
  124. {
  125. Debug.WriteLine($"{e.Data["category"]}");
  126. MessagingCenter.Send(this, nameof(App), e.Data["category"].ToString());
  127. if (Device.RuntimePlatform == Device.iOS)
  128. {
  129. if (ShareConstant.IsInForeground)
  130. {
  131. var player = CrossSimpleAudioPlayer.Current;
  132. player.Load("system.wav");
  133. player.Play();
  134. }
  135. }
  136. });
  137. }
  138. else if (e.Data["category"].ToString().Equals("BookingAvailable"))
  139. {
  140. Device.BeginInvokeOnMainThread(() =>
  141. {
  142. Debug.WriteLine($"{e.Data["category"]}");
  143. MessagingCenter.Send(this, nameof(App), e.Data["category"].ToString());
  144. if (Device.RuntimePlatform == Device.iOS)
  145. {
  146. if (ShareConstant.IsInForeground)
  147. {
  148. var player = CrossSimpleAudioPlayer.Current;
  149. player.Load("newbooking.wav");
  150. player.Play();
  151. }
  152. }
  153. });
  154. }
  155. else
  156. {
  157. Device.BeginInvokeOnMainThread(() =>
  158. {
  159. Debug.WriteLine($"{e.Data["category"]}");
  160. MessagingCenter.Send(this, nameof(App), e.Data["category"].ToString());
  161. });
  162. }
  163. }
  164. else if (e.Data.ContainsKey("coupon_category"))
  165. {
  166. if (e.Data["coupon_category"].ToString().Equals("CouponRedeemed"))
  167. {
  168. Device.BeginInvokeOnMainThread(() =>
  169. {
  170. MessagingCenter.Send(this, nameof(App), e.Data["coupon_category"].ToString());
  171. });
  172. }
  173. }
  174. }
  175. catch (Exception ex)
  176. {
  177. }
  178. };
  179. }
  180. catch (Exception ex)
  181. {
  182. Debug.WriteLine($"Onstart Error Entry: {ex.StackTrace}");
  183. }
  184. }
  185. protected override void OnSleep()
  186. {
  187. try
  188. {
  189. ShareConstant.IsInForeground = false;
  190. }
  191. catch (Exception ex)
  192. {
  193. Debug.WriteLine($"Onsleep Error Entry: {ex.StackTrace}");
  194. }
  195. }
  196. protected override void OnResume()
  197. {
  198. try
  199. {
  200. ShareConstant.IsInForeground = true;
  201. }
  202. catch (Exception ex)
  203. {
  204. Debug.WriteLine($"OnResume Error Entry: {ex.StackTrace}");
  205. }
  206. }
  207. }