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.

120 lines
4.0 KiB

  1. using GMCabsDriverAssistant.Services;
  2. using GMCabsDriverAssistant.Utils;
  3. namespace GMCabsDriverAssistantSolution.Views;
  4. public partial class PermissionCheckPage : ContentPage
  5. {
  6. bool isFirstTime = true;
  7. public PermissionCheckPage()
  8. {
  9. InitializeComponent();
  10. }
  11. [Obsolete]
  12. protected async override void OnAppearing()
  13. {
  14. base.OnAppearing();
  15. isFirstTime = Preferences.Get("isFirstTime", true);
  16. var status = await Permissions.CheckStatusAsync<Permissions.LocationAlways>();
  17. if (status == PermissionStatus.Granted)
  18. {
  19. Preferences.Set(SecureStorageData.IsLocationPermitted, true);
  20. }
  21. else
  22. {
  23. Preferences.Set(SecureStorageData.IsLocationPermitted, false);
  24. }
  25. if (Device.RuntimePlatform == Device.Android)
  26. {
  27. if (DependencyService.Get<IBatteryInfo>().CheckIsIgnoringBatteryOptimizations())
  28. {
  29. Preferences.Set(SecureStorageData.IsBatteryOptimizationDisabled, true);
  30. }
  31. else
  32. {
  33. Preferences.Set(SecureStorageData.IsBatteryOptimizationDisabled, false);
  34. }
  35. }
  36. if ((Preferences.Get(SecureStorageData.IsLocationPermitted, false)) || !string.IsNullOrWhiteSpace(Preferences.Get(SecureStorageData.Token, "")))
  37. {
  38. if (Device.RuntimePlatform == Device.Android && Preferences.Get(SecureStorageData.IsBatteryOptimizationDisabled, false))
  39. {
  40. await ShowSplashScreen();
  41. }
  42. else if (Device.RuntimePlatform == Device.iOS)
  43. {
  44. await ShowSplashScreen();
  45. }
  46. }
  47. }
  48. public void OnPermissionCheckClicked(object sender, EventArgs e)
  49. {
  50. //Navigation.ShowPopup(new AppPermissiontSetDialogPage(this, Constant.FROM_PERMISSION_PAGE));
  51. /*if (!isFirstTime)
  52. {
  53. Navigation.ShowPopup(new LocationNotSetDialogPage(this));
  54. }
  55. else
  56. {
  57. Preferences.Set("isFirstTime", false);
  58. var status = await OnLocationCheck();
  59. if (status == PermissionStatus.Granted)
  60. {
  61. await ShowSplashScreen();
  62. }
  63. }*/
  64. }
  65. public async Task<PermissionStatus> OnLocationCheck()
  66. {
  67. var status = await Permissions.CheckStatusAsync<Permissions.LocationAlways>();
  68. if (status == PermissionStatus.Granted)
  69. return status;
  70. try
  71. {
  72. if (DeviceInfo.Platform == DevicePlatform.Android && int.Parse(DeviceInfo.VersionString) >= 12)
  73. {
  74. bool answer = await DisplayAlert("Location", "Please allow your location permission from setting Page and Select 'All the time'", "YES", "NO");
  75. if (answer)
  76. AppInfo.ShowSettingsUI();
  77. }
  78. else
  79. {
  80. if (DeviceInfo.Platform == DevicePlatform.iOS && status == PermissionStatus.Denied)
  81. {
  82. // Prompt the user to turn on in settings
  83. // On iOS once a permission has been denied it may not be requested again from the application
  84. // Navigation.ShowPopup(new LocationNotSetDialogPage(this));
  85. return status;
  86. }
  87. status = await Permissions.RequestAsync<Permissions.LocationAlways>();
  88. if (status == PermissionStatus.Granted)
  89. {
  90. return status;
  91. }
  92. if (!Permissions.ShouldShowRationale<Permissions.LocationAlways>())
  93. {
  94. bool answer = await DisplayAlert("Location", "Please allow your location permission from setting Page", "YES", "NO");
  95. if (answer)
  96. AppInfo.ShowSettingsUI();
  97. }
  98. }
  99. }
  100. catch (Exception ex)
  101. {
  102. }
  103. return status;
  104. }
  105. private async Task ShowSplashScreen()
  106. {
  107. await Shell.Current.GoToAsync($"//{nameof(SplashPage)}");
  108. }
  109. }