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.
 

149 lines
4.2 KiB

using CommunityToolkit.Maui.Views;
using GMCabsDriverAssistant.Services;
using GMCabsDriverAssistant.Utils;
namespace GMCabsDriverAssistantSolution.Views;
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class AppPermissiontSetDialogPage : Popup
{
#region Fields
bool isLocationPermitted, isBatteryOptimizationDisabled;
string flag;
#endregion
#region Constructor
public AppPermissiontSetDialogPage(Page page, string flag)
{
InitializeComponent();
this.flag = flag;
isLocationPermitted = Preferences.Get(SecureStorageData.IsLocationPermitted, false);
isBatteryOptimizationDisabled = Preferences.Get(SecureStorageData.IsBatteryOptimizationDisabled, false);
PermissionAllocationLayout.IsVisible = true;
PermissionLayout.IsVisible = false;
LocationWarningLayout.IsVisible = false;
}
#endregion
#region Events
private async void Ignore_Clicked(object sender, EventArgs e)
{
if (isLocationPermitted)
{
if (flag == Constant.FROM_PERMISSION_PAGE)
{
//Dismiss(null);
Close();
await ShowSplashScreen();
}
else
{
//Dismiss(null);
Close();
}
}
else
{
if (LocationWarningLayout.IsVisible)
{
if (flag == Constant.FROM_PERMISSION_PAGE)
{
//Dismiss(null);
Close();
await ShowSplashScreen();
}
else
{
//Dismiss(null);
Close();
}
}
else
{
PermissionAllocationLayout.IsVisible = false;
PermissionLayout.IsVisible = false;
LocationWarningLayout.IsVisible = true;
}
}
}
[Obsolete]
private void Permission_Clicked(object sender, EventArgs e)
{
PermissionAllocationLayout.IsVisible = false;
PermissionLayout.IsVisible = true;
LocationWarningLayout.IsVisible = false;
if (Device.RuntimePlatform == Device.iOS)
{
BatteyOptimisedLayout.IsVisible = false;
}
else
{
if (isLocationPermitted)
{
PermissionLayout.IsVisible = true;
LocationLayout.IsVisible = false;
}
if (isBatteryOptimizationDisabled)
{
PermissionLayout.IsVisible = true;
BatteyOptimisedLayout.IsVisible = false;
}
}
}
private async void Location_Clicked(object sender, EventArgs e)
{
//Dismiss(null);
Close();
await Permissions.RequestAsync<Permissions.LocationAlways>();
var status = await OnLocationCheck();
}
private void Batteryoptimisation_Clicked(object sender, EventArgs e)
{
//Dismiss(null);
Close();
if (!DependencyService.Get<IBatteryInfo>().CheckIsIgnoringBatteryOptimizations())
{
DependencyService.Get<IBatteryInfo>().StartSetting();
}
}
private async void ChangeLocation_Clicked(object sender, EventArgs e)
{
//Dismiss(null);
Close();
await Permissions.RequestAsync<Permissions.LocationAlways>();
var status = await OnLocationCheck();
}
#endregion
#region Methods
private async Task ShowSplashScreen()
{
await Shell.Current.GoToAsync($"//{nameof(SplashPage)}");
}
public async Task<PermissionStatus> OnLocationCheck()
{
var status = await Permissions.CheckStatusAsync<Permissions.LocationAlways>();
if (status == PermissionStatus.Granted)
return status;
try
{
if ((DeviceInfo.Platform == DevicePlatform.Android && int.Parse(DeviceInfo.VersionString) >= 12) || DeviceInfo.Platform == DevicePlatform.iOS)
{
AppInfo.ShowSettingsUI();
}
}
catch (Exception ex)
{
}
return status;
}
#endregion
}