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.

148 lines
4.2 KiB

  1. using CommunityToolkit.Maui.Views;
  2. using GMCabsDriverAssistant.Services;
  3. using GMCabsDriverAssistant.Utils;
  4. namespace GMCabsDriverAssistantSolution.Views;
  5. [XamlCompilation(XamlCompilationOptions.Compile)]
  6. public partial class AppPermissiontSetDialogPage : Popup
  7. {
  8. #region Fields
  9. bool isLocationPermitted, isBatteryOptimizationDisabled;
  10. string flag;
  11. #endregion
  12. #region Constructor
  13. public AppPermissiontSetDialogPage(Page page, string flag)
  14. {
  15. InitializeComponent();
  16. this.flag = flag;
  17. isLocationPermitted = Preferences.Get(SecureStorageData.IsLocationPermitted, false);
  18. isBatteryOptimizationDisabled = Preferences.Get(SecureStorageData.IsBatteryOptimizationDisabled, false);
  19. PermissionAllocationLayout.IsVisible = true;
  20. PermissionLayout.IsVisible = false;
  21. LocationWarningLayout.IsVisible = false;
  22. }
  23. #endregion
  24. #region Events
  25. private async void Ignore_Clicked(object sender, EventArgs e)
  26. {
  27. if (isLocationPermitted)
  28. {
  29. if (flag == Constant.FROM_PERMISSION_PAGE)
  30. {
  31. //Dismiss(null);
  32. Close();
  33. await ShowSplashScreen();
  34. }
  35. else
  36. {
  37. //Dismiss(null);
  38. Close();
  39. }
  40. }
  41. else
  42. {
  43. if (LocationWarningLayout.IsVisible)
  44. {
  45. if (flag == Constant.FROM_PERMISSION_PAGE)
  46. {
  47. //Dismiss(null);
  48. Close();
  49. await ShowSplashScreen();
  50. }
  51. else
  52. {
  53. //Dismiss(null);
  54. Close();
  55. }
  56. }
  57. else
  58. {
  59. PermissionAllocationLayout.IsVisible = false;
  60. PermissionLayout.IsVisible = false;
  61. LocationWarningLayout.IsVisible = true;
  62. }
  63. }
  64. }
  65. [Obsolete]
  66. private void Permission_Clicked(object sender, EventArgs e)
  67. {
  68. PermissionAllocationLayout.IsVisible = false;
  69. PermissionLayout.IsVisible = true;
  70. LocationWarningLayout.IsVisible = false;
  71. if (Device.RuntimePlatform == Device.iOS)
  72. {
  73. BatteyOptimisedLayout.IsVisible = false;
  74. }
  75. else
  76. {
  77. if (isLocationPermitted)
  78. {
  79. PermissionLayout.IsVisible = true;
  80. LocationLayout.IsVisible = false;
  81. }
  82. if (isBatteryOptimizationDisabled)
  83. {
  84. PermissionLayout.IsVisible = true;
  85. BatteyOptimisedLayout.IsVisible = false;
  86. }
  87. }
  88. }
  89. private async void Location_Clicked(object sender, EventArgs e)
  90. {
  91. //Dismiss(null);
  92. Close();
  93. await Permissions.RequestAsync<Permissions.LocationAlways>();
  94. var status = await OnLocationCheck();
  95. }
  96. private void Batteryoptimisation_Clicked(object sender, EventArgs e)
  97. {
  98. //Dismiss(null);
  99. Close();
  100. if (!DependencyService.Get<IBatteryInfo>().CheckIsIgnoringBatteryOptimizations())
  101. {
  102. DependencyService.Get<IBatteryInfo>().StartSetting();
  103. }
  104. }
  105. private async void ChangeLocation_Clicked(object sender, EventArgs e)
  106. {
  107. //Dismiss(null);
  108. Close();
  109. await Permissions.RequestAsync<Permissions.LocationAlways>();
  110. var status = await OnLocationCheck();
  111. }
  112. #endregion
  113. #region Methods
  114. private async Task ShowSplashScreen()
  115. {
  116. await Shell.Current.GoToAsync($"//{nameof(SplashPage)}");
  117. }
  118. public async Task<PermissionStatus> OnLocationCheck()
  119. {
  120. var status = await Permissions.CheckStatusAsync<Permissions.LocationAlways>();
  121. if (status == PermissionStatus.Granted)
  122. return status;
  123. try
  124. {
  125. if ((DeviceInfo.Platform == DevicePlatform.Android && int.Parse(DeviceInfo.VersionString) >= 12) || DeviceInfo.Platform == DevicePlatform.iOS)
  126. {
  127. AppInfo.ShowSettingsUI();
  128. }
  129. }
  130. catch (Exception ex)
  131. {
  132. }
  133. return status;
  134. }
  135. #endregion
  136. }