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.

219 lines
9.4 KiB

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