MOBILE-3640 database: Location service improvements on error handling
parent
1363951920
commit
bfbfd350b1
|
@ -11,7 +11,7 @@
|
|||
<ion-input type="text" [formControlName]="'f_'+field.id+'_1'" maxlength="10"></ion-input>
|
||||
<span class="placeholder-icon" item-right>°E</span>
|
||||
</div>
|
||||
<div class="addon-data-latlong">
|
||||
<div class="addon-data-latlong" *ngIf="locationServicesEnabled">
|
||||
<ion-button (click)="getLocation($event)">
|
||||
<ion-icon name="fas-crosshairs" slot="start"></ion-icon>
|
||||
{{ 'addon.mod_data.mylocation' | translate }}
|
||||
|
|
|
@ -33,6 +33,7 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo
|
|||
|
||||
north?: number;
|
||||
east?: number;
|
||||
locationServicesEnabled = false;
|
||||
|
||||
constructor(
|
||||
fb: FormBuilder,
|
||||
|
@ -87,7 +88,7 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected init(): void {
|
||||
protected async init(): Promise<void> {
|
||||
if (this.value) {
|
||||
this.updateValue(this.value);
|
||||
}
|
||||
|
@ -95,6 +96,8 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo
|
|||
if (this.editMode) {
|
||||
this.addControl('f_' + this.field.id + '_0', this.north);
|
||||
this.addControl('f_' + this.field.id + '_1', this.east);
|
||||
this.locationServicesEnabled = await CoreGeolocation.canRequest();
|
||||
|
||||
} else if (this.searchMode) {
|
||||
this.addControl('f_' + this.field.id);
|
||||
}
|
||||
|
@ -136,7 +139,7 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo
|
|||
*
|
||||
* @param error Location error.
|
||||
*/
|
||||
protected showLocationErrorModal(error: CoreAnyError): void {
|
||||
protected showLocationErrorModal(error: CoreAnyError | CoreGeolocationError): void {
|
||||
if (error instanceof CoreGeolocationError) {
|
||||
CoreDomUtils.showErrorModal(this.getGeolocationErrorMessage(error), true);
|
||||
|
||||
|
|
|
@ -16,8 +16,9 @@ import { Injectable } from '@angular/core';
|
|||
import { Coordinates } from '@ionic-native/geolocation';
|
||||
|
||||
import { CoreApp } from '@services/app';
|
||||
import { CoreError } from '@classes/errors/error';
|
||||
import { CoreAnyError, CoreError } from '@classes/errors/error';
|
||||
import { Geolocation, Diagnostic, makeSingleton } from '@singletons';
|
||||
import { CoreUtils } from './utils/utils';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreGeolocationProvider {
|
||||
|
@ -89,7 +90,6 @@ export class CoreGeolocationProvider {
|
|||
*/
|
||||
protected async doAuthorizeLocation(failOnDeniedOnce: boolean = false): Promise<void> {
|
||||
const authorizationStatus = await Diagnostic.getLocationAuthorizationStatus();
|
||||
|
||||
switch (authorizationStatus) {
|
||||
case Diagnostic.permissionStatus.DENIED_ONCE:
|
||||
if (failOnDeniedOnce) {
|
||||
|
@ -116,9 +116,21 @@ export class CoreGeolocationProvider {
|
|||
*
|
||||
* @param error Error.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
protected isCordovaPermissionDeniedError(error?: any): boolean {
|
||||
return error && 'code' in error && 'PERMISSION_DENIED' in error && error.code === error.PERMISSION_DENIED;
|
||||
protected isCordovaPermissionDeniedError(error?: CoreAnyError | GeolocationPositionError): boolean {
|
||||
return !!error &&
|
||||
typeof error == 'object' &&
|
||||
'code' in error &&
|
||||
'PERMISSION_DENIED' in error &&
|
||||
error.code === error.PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prechecks if it can request location services.
|
||||
*
|
||||
* @return If location can be requested.
|
||||
*/
|
||||
async canRequest(): Promise<boolean> {
|
||||
return CoreUtils.promiseWorks(Diagnostic.getLocationAuthorizationStatus());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -141,3 +153,15 @@ export class CoreGeolocationError extends CoreError {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Imported interface type from Web api.
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/GeolocationPositionError
|
||||
*/
|
||||
interface GeolocationPositionError {
|
||||
code: number;
|
||||
message: string;
|
||||
PERMISSION_DENIED: number; // eslint-disable-line @typescript-eslint/naming-convention
|
||||
POSITION_UNAVAILABLE: number; // eslint-disable-line @typescript-eslint/naming-convention
|
||||
TIMEOUT: number; // eslint-disable-line @typescript-eslint/naming-convention
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue