Implementattion of Permission Check Page.
This commit is contained in:
parent
59d36aa24d
commit
2d55f127b6
44
GMCabsDriverAssistantSolution/Views/PermissionCheckPage.xaml
Normal file
44
GMCabsDriverAssistantSolution/Views/PermissionCheckPage.xaml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="GMCabsDriverAssistantSolution.Views.PermissionCheckPage"
|
||||
xmlns:custom="clr-namespace:GMCabsDriverAssistantSolution.CustomControls"
|
||||
Shell.FlyoutBehavior="Disabled"
|
||||
Shell.NavBarIsVisible="False">
|
||||
<ContentPage.Resources>
|
||||
<ResourceDictionary>
|
||||
<Style x:Key="NoUnderlineEntryFrameStyle" TargetType="Frame">
|
||||
<Setter Property="Padding" Value="16,4"></Setter>
|
||||
<Setter Property="CornerRadius" Value="12"></Setter>
|
||||
<Setter Property="Margin" Value="4,8,4,4"></Setter>
|
||||
<Setter Property="HasShadow" Value="True"></Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</ContentPage.Resources>
|
||||
<ContentPage.Content>
|
||||
<StackLayout Orientation="Vertical"
|
||||
BackgroundColor="#DCDCDC"
|
||||
Padding="10">
|
||||
<Image Source="{OnIdiom Phone='gmlogo.png',Tablet='gmlogo_tablet.png'}"
|
||||
Margin="{OnIdiom Phone='48,30,48,12',Tablet='0,-50,0,-50'}"
|
||||
Scale="{OnIdiom Phone='1.2',Tablet='0.3'}"/>
|
||||
|
||||
<Label Text="GM Cabs require access to your location in order to send jobs to you. GM Cabs Driver App collects location data to enable identification of nearby Rydo bookings even when the app is closed or not in use."
|
||||
HorizontalTextAlignment="Center"
|
||||
Margin="20,20,20,0"
|
||||
FontSize="20"
|
||||
TextColor="Black"/>
|
||||
<Label Text="Please press the continue button below and allow the permissions request to use this application."
|
||||
HorizontalTextAlignment="Center"
|
||||
Margin="20,20,20,0"
|
||||
FontSize="20"
|
||||
TextColor="Black"/>
|
||||
<Button
|
||||
Text="Continue"
|
||||
VerticalOptions="EndAndExpand"
|
||||
FontSize="20"
|
||||
Clicked="OnPermissionCheckClicked"
|
||||
Margin="20,0,20,20"/>
|
||||
</StackLayout>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
121
GMCabsDriverAssistantSolution/Views/PermissionCheckPage.xaml.cs
Normal file
121
GMCabsDriverAssistantSolution/Views/PermissionCheckPage.xaml.cs
Normal file
@ -0,0 +1,121 @@
|
||||
using GMCabsDriverAssistant.Services;
|
||||
using GMCabsDriverAssistant.Utils;
|
||||
|
||||
namespace GMCabsDriverAssistantSolution.Views;
|
||||
|
||||
public partial class PermissionCheckPage : ContentPage
|
||||
{
|
||||
bool isFirstTime = true;
|
||||
|
||||
public PermissionCheckPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
protected async override void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
isFirstTime = Preferences.Get("isFirstTime", true);
|
||||
var status = await Permissions.CheckStatusAsync<Permissions.LocationAlways>();
|
||||
if (status == PermissionStatus.Granted)
|
||||
{
|
||||
Preferences.Set(SecureStorageData.IsLocationPermitted, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Preferences.Set(SecureStorageData.IsLocationPermitted, false);
|
||||
}
|
||||
if (Device.RuntimePlatform == Device.Android)
|
||||
{
|
||||
if (DependencyService.Get<IBatteryInfo>().CheckIsIgnoringBatteryOptimizations())
|
||||
{
|
||||
Preferences.Set(SecureStorageData.IsBatteryOptimizationDisabled, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Preferences.Set(SecureStorageData.IsBatteryOptimizationDisabled, false);
|
||||
}
|
||||
}
|
||||
if ((Preferences.Get(SecureStorageData.IsLocationPermitted, false)) || !string.IsNullOrWhiteSpace(Preferences.Get(SecureStorageData.Token, "")))
|
||||
{
|
||||
if (Device.RuntimePlatform == Device.Android && Preferences.Get(SecureStorageData.IsBatteryOptimizationDisabled, false))
|
||||
{
|
||||
await ShowSplashScreen();
|
||||
}
|
||||
else if (Device.RuntimePlatform == Device.iOS)
|
||||
{
|
||||
await ShowSplashScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPermissionCheckClicked(object sender, EventArgs e)
|
||||
{
|
||||
//Navigation.ShowPopup(new AppPermissiontSetDialogPage(this, Constant.FROM_PERMISSION_PAGE));
|
||||
/*if (!isFirstTime)
|
||||
{
|
||||
Navigation.ShowPopup(new LocationNotSetDialogPage(this));
|
||||
}
|
||||
else
|
||||
{
|
||||
Preferences.Set("isFirstTime", false);
|
||||
var status = await OnLocationCheck();
|
||||
if (status == PermissionStatus.Granted)
|
||||
{
|
||||
await ShowSplashScreen();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
||||
|
||||
bool answer = await DisplayAlert("Location", "Please allow your location permission from setting Page and Select 'All the time'", "YES", "NO");
|
||||
if (answer)
|
||||
AppInfo.ShowSettingsUI();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DeviceInfo.Platform == DevicePlatform.iOS && status == PermissionStatus.Denied)
|
||||
{
|
||||
// Prompt the user to turn on in settings
|
||||
// On iOS once a permission has been denied it may not be requested again from the application
|
||||
// Navigation.ShowPopup(new LocationNotSetDialogPage(this));
|
||||
return status;
|
||||
}
|
||||
status = await Permissions.RequestAsync<Permissions.LocationAlways>();
|
||||
if (status == PermissionStatus.Granted)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
if (!Permissions.ShouldShowRationale<Permissions.LocationAlways>())
|
||||
{
|
||||
bool answer = await DisplayAlert("Location", "Please allow your location permission from setting Page", "YES", "NO");
|
||||
if (answer)
|
||||
AppInfo.ShowSettingsUI();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
return status;
|
||||
}
|
||||
private async Task ShowSplashScreen()
|
||||
{
|
||||
await Shell.Current.GoToAsync($"//{nameof(SplashPage)}");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user