MOBILE-3532 utils: Wrap is('android') calls

main
Pau Ferrer Ocaña 2020-09-03 15:50:11 +02:00
parent fd92f7cb03
commit 1b014ba3ba
17 changed files with 148 additions and 113 deletions

View File

@ -146,7 +146,7 @@ export class MoodleMobileApp implements OnInit {
});
this.utils.closeInAppBrowser(false);
} else if (this.platform.is('android')) {
} else if (CoreApp.instance.isAndroid()) {
// Check if the URL has a custom URL scheme. In Android they need to be opened manually.
const urlScheme = this.urlUtils.getUrlProtocol(url);
if (urlScheme && urlScheme !== 'file' && urlScheme !== 'cdvfile') {
@ -260,7 +260,7 @@ export class MoodleMobileApp implements OnInit {
// Pause Youtube videos in Android when app is put in background or screen is locked.
this.platform.pause.subscribe(() => {
if (!this.platform.is('android')) {
if (!CoreApp.instance.isAndroid()) {
return;
}

View File

@ -15,7 +15,7 @@
import { Component, OnInit, AfterViewInit, Input, ElementRef } from '@angular/core';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { Platform } from 'ionic-angular';
import { CoreApp } from '@providers/app';
/**
* Component to allow showing and hiding a password. The affected input MUST have a name to identify it.
@ -47,8 +47,11 @@ export class CoreShowPasswordComponent implements OnInit, AfterViewInit {
protected input: HTMLInputElement; // Input affected.
protected element: HTMLElement; // Current element.
constructor(element: ElementRef, private utils: CoreUtilsProvider, private domUtils: CoreDomUtilsProvider,
private platform: Platform) {
constructor(
element: ElementRef,
private utils: CoreUtilsProvider,
private domUtils: CoreDomUtilsProvider
) {
this.element = element.nativeElement;
}
@ -114,7 +117,7 @@ export class CoreShowPasswordComponent implements OnInit, AfterViewInit {
this.shown = !this.shown;
this.setData();
if (isFocused && this.platform.is('android')) {
if (isFocused && CoreApp.instance.isAndroid()) {
// In Android, the keyboard is closed when the input type changes. Focus it again.
setTimeout(() => {
this.domUtils.focusElement(this.input);

View File

@ -218,7 +218,7 @@ export class CoreEditorRichTextEditorComponent implements AfterContentInit, OnDe
setTimeout(() => {
let contentVisibleHeight = this.domUtils.getContentHeight(this.content);
if (!this.platform.is('android')) {
if (!CoreApp.instance.isAndroid()) {
// In Android we ignore the keyboard height because it is not part of the web view.
contentVisibleHeight -= this.kbHeight;
}
@ -233,7 +233,7 @@ export class CoreEditorRichTextEditorComponent implements AfterContentInit, OnDe
// Editor is ready, adjust Height if needed.
let height;
if (this.platform.is('android')) {
if (CoreApp.instance.isAndroid()) {
// In Android we ignore the keyboard height because it is not part of the web view.
height = this.domUtils.getContentHeight(this.content) - this.getSurroundingHeight(this.element);
} else if (CoreApp.instance.isIOS() && this.kbHeight > 0 && this.platform.version().major < 12) {

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Injectable } from '@angular/core';
import { Platform } from 'ionic-angular';
import { CoreApp } from '@providers/app';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreFileUploaderHandler, CoreFileUploaderHandlerData } from './delegate';
@ -28,7 +27,6 @@ export class CoreFileUploaderAudioHandler implements CoreFileUploaderHandler {
constructor(
private utils: CoreUtilsProvider,
private platform: Platform,
private uploaderHelper: CoreFileUploaderHelperProvider
) { }
@ -51,7 +49,7 @@ export class CoreFileUploaderAudioHandler implements CoreFileUploaderHandler {
if (CoreApp.instance.isIOS()) {
// In iOS it's recorded as WAV.
return this.utils.filterByRegexp(mimetypes, /^audio\/wav$/);
} else if (this.platform.is('android')) {
} else if (CoreApp.instance.isAndroid()) {
// In Android we don't know the format the audio will be recorded, so accept any audio mimetype.
return this.utils.filterByRegexp(mimetypes, /^audio\//);
} else {

View File

@ -14,7 +14,7 @@
import { Injectable } from '@angular/core';
import { Platform } from 'ionic-angular';
import { CoreApp, CoreAppProvider } from '@providers/app';
import { CoreApp } from '@providers/app';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreTimeUtilsProvider } from '@providers/utils/time';
import { CoreFileUploaderHandler, CoreFileUploaderHandlerData } from './delegate';
@ -30,7 +30,7 @@ export class CoreFileUploaderFileHandler implements CoreFileUploaderHandler {
name = 'CoreFileUploaderFile';
priority = 1200;
constructor(protected appProvider: CoreAppProvider,
constructor(
protected platform: Platform,
protected timeUtils: CoreTimeUtilsProvider,
protected uploaderHelper: CoreFileUploaderHelperProvider,
@ -44,7 +44,7 @@ export class CoreFileUploaderFileHandler implements CoreFileUploaderHandler {
* @return True or promise resolved with true if enabled.
*/
isEnabled(): boolean | Promise<boolean> {
return this.platform.is('android') || !this.appProvider.isMobile() ||
return CoreApp.instance.isAndroid() || !CoreApp.instance.isMobile() ||
(CoreApp.instance.isIOS() && this.platform.version().major >= 9);
}
@ -70,7 +70,7 @@ export class CoreFileUploaderFileHandler implements CoreFileUploaderHandler {
icon: 'folder',
};
if (this.appProvider.isMobile()) {
if (CoreApp.instance.isMobile()) {
handler.action = (maxSize?: number, upload?: boolean, allowOffline?: boolean, mimetypes?: string[]): Promise<any> => {
return this.uploaderHelper.chooseAndUploadFile(maxSize, upload, allowOffline, mimetypes).then((result) => {
return {
@ -89,7 +89,7 @@ export class CoreFileUploaderFileHandler implements CoreFileUploaderHandler {
const input = document.createElement('input');
input.setAttribute('type', 'file');
input.classList.add('core-fileuploader-file-handler-input');
if (mimetypes && mimetypes.length && (!this.platform.is('android') || mimetypes.length == 1)) {
if (mimetypes && mimetypes.length && (!CoreApp.instance.isAndroid() || mimetypes.length == 1)) {
// Don't use accept attribute in Android with several mimetypes, it's not supported.
input.setAttribute('accept', mimetypes.join(', '));
}

View File

@ -13,7 +13,7 @@
// limitations under the License.
import { Injectable } from '@angular/core';
import { Platform, ModalController } from 'ionic-angular';
import { ModalController } from 'ionic-angular';
import { Camera, CameraOptions } from '@ionic-native/camera';
import { MediaCapture, MediaFile, CaptureError, CaptureAudioOptions, CaptureVideoOptions } from '@ionic-native/media-capture';
import { TranslateService } from '@ngx-translate/core';
@ -62,7 +62,6 @@ export class CoreFileUploaderProvider {
protected timeUtils: CoreTimeUtilsProvider,
protected mimeUtils: CoreMimetypeUtilsProvider,
protected filepoolProvider: CoreFilepoolProvider,
protected platform: Platform,
protected translate: TranslateService,
protected mediaCapture: MediaCapture,
protected camera: Camera,
@ -207,7 +206,7 @@ export class CoreFileUploaderProvider {
// If the file was picked from the album, delete it only if it was copied to the app's folder.
options.deleteAfterUpload = this.fileProvider.isFileInAppFolder(uri);
if (this.platform.is('android')) {
if (CoreApp.instance.isAndroid()) {
// Picking an image from album in Android adds a timestamp at the end of the file. Delete it.
options.fileName = options.fileName.replace(/(\.[^\.]*)\?[^\.]*$/, '$1');
}

View File

@ -13,8 +13,7 @@
// limitations under the License.
import { Injectable } from '@angular/core';
import { Platform } from 'ionic-angular';
import { CoreApp, CoreAppProvider } from '@providers/app';
import { CoreApp } from '@providers/app';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreFileUploaderHandler, CoreFileUploaderHandlerData } from './delegate';
import { CoreFileUploaderHelperProvider } from './helper';
@ -26,8 +25,10 @@ export class CoreFileUploaderVideoHandler implements CoreFileUploaderHandler {
name = 'CoreFileUploaderVideo';
priority = 1400;
constructor(private appProvider: CoreAppProvider, private utils: CoreUtilsProvider, private platform: Platform,
private uploaderHelper: CoreFileUploaderHelperProvider) { }
constructor(
private utils: CoreUtilsProvider,
private uploaderHelper: CoreFileUploaderHelperProvider
) { }
/**
* Whether or not the handler is enabled on a site level.
@ -35,7 +36,7 @@ export class CoreFileUploaderVideoHandler implements CoreFileUploaderHandler {
* @return True or promise resolved with true if enabled.
*/
isEnabled(): boolean | Promise<boolean> {
return this.appProvider.isMobile() || (this.appProvider.canGetUserMedia() && this.appProvider.canRecordMedia());
return CoreApp.instance.isMobile() || (CoreApp.instance.canGetUserMedia() && CoreApp.instance.canRecordMedia());
}
/**
@ -48,7 +49,7 @@ export class CoreFileUploaderVideoHandler implements CoreFileUploaderHandler {
if (CoreApp.instance.isIOS()) {
// In iOS it's recorded as MOV.
return this.utils.filterByRegexp(mimetypes, /^video\/quicktime$/);
} else if (this.platform.is('android')) {
} else if (CoreApp.instance.isAndroid()) {
// In Android we don't know the format the video will be recorded, so accept any video mimetype.
return this.utils.filterByRegexp(mimetypes, /^video\//);
} else {

View File

@ -14,9 +14,9 @@
import { Injectable } from '@angular/core';
import { Location } from '@angular/common';
import { Platform, AlertController, NavController, NavOptions } from 'ionic-angular';
import { AlertController, NavController, NavOptions } from 'ionic-angular';
import { TranslateService } from '@ngx-translate/core';
import { CoreApp, CoreAppProvider, CoreStoreConfig } from '@providers/app';
import { CoreApp, CoreStoreConfig } from '@providers/app';
import { CoreConfigProvider } from '@providers/config';
import { CoreEventsProvider } from '@providers/events';
import { CoreInitDelegate } from '@providers/init';
@ -87,12 +87,23 @@ export class CoreLoginHelperProvider {
protected isOpeningReconnect = false;
waitingForBrowser = false;
constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private domUtils: CoreDomUtilsProvider,
private wsProvider: CoreWSProvider, private translate: TranslateService, private textUtils: CoreTextUtilsProvider,
private eventsProvider: CoreEventsProvider, private appProvider: CoreAppProvider, private utils: CoreUtilsProvider,
private urlUtils: CoreUrlUtilsProvider, private configProvider: CoreConfigProvider, private platform: Platform,
private initDelegate: CoreInitDelegate, private sitePluginsProvider: CoreSitePluginsProvider,
private location: Location, private alertCtrl: AlertController, private courseProvider: CoreCourseProvider) {
constructor(
logger: CoreLoggerProvider,
private sitesProvider: CoreSitesProvider,
private domUtils: CoreDomUtilsProvider,
private wsProvider: CoreWSProvider,
private translate: TranslateService,
private textUtils: CoreTextUtilsProvider,
private eventsProvider: CoreEventsProvider,
private utils: CoreUtilsProvider,
private urlUtils: CoreUrlUtilsProvider,
private configProvider: CoreConfigProvider,
private initDelegate: CoreInitDelegate,
private sitePluginsProvider: CoreSitePluginsProvider,
private location: Location,
private alertCtrl: AlertController,
private courseProvider: CoreCourseProvider
) {
this.logger = logger.getInstance('CoreLoginHelper');
this.eventsProvider.on(CoreEventsProvider.MAIN_MENU_OPEN, () => {
@ -149,17 +160,17 @@ export class CoreLoginHelperProvider {
return false;
}
if (this.appProvider.isSSOAuthenticationOngoing()) {
if (CoreApp.instance.isSSOAuthenticationOngoing()) {
// Authentication ongoing, probably duplicated request.
return true;
}
if (this.appProvider.isDesktop()) {
if (CoreApp.instance.isDesktop()) {
// In desktop, make sure InAppBrowser is closed.
this.utils.closeInAppBrowser(true);
}
// App opened using custom URL scheme. Probably an SSO authentication.
this.appProvider.startSSOAuthentication();
CoreApp.instance.startSSOAuthentication();
this.logger.debug('App launched by URL with an SSO');
// Delete the sso scheme from the URL.
@ -195,7 +206,7 @@ export class CoreLoginHelperProvider {
}).then(() => {
if (siteData.pageName) {
// State defined, go to that state instead of site initial page.
this.appProvider.getRootNavController().push(siteData.pageName, siteData.pageParams);
CoreApp.instance.getRootNavController().push(siteData.pageName, siteData.pageParams);
} else {
this.goToSiteInitialPage();
}
@ -207,7 +218,7 @@ export class CoreLoginHelperProvider {
}
}).finally(() => {
modal.dismiss();
this.appProvider.finishSSOAuthentication();
CoreApp.instance.finishSSOAuthentication();
});
return true;
@ -232,8 +243,8 @@ export class CoreLoginHelperProvider {
* Function called when an SSO InAppBrowser is closed or the app is resumed. Check if user needs to be logged out.
*/
checkLogout(): void {
const navCtrl = this.appProvider.getRootNavController();
if (!this.appProvider.isSSOAuthenticationOngoing() && this.sitesProvider.isLoggedIn() &&
const navCtrl = CoreApp.instance.getRootNavController();
if (!CoreApp.instance.isSSOAuthenticationOngoing() && this.sitesProvider.isLoggedIn() &&
this.sitesProvider.getCurrentSite().isLoggedOut() && navCtrl.getActive().name == 'CoreLoginReconnectPage') {
// User must reauthenticate but he closed the InAppBrowser without doing so, logout him.
this.sitesProvider.logout();
@ -515,9 +526,9 @@ export class CoreLoginHelperProvider {
}
if (setRoot) {
return this.appProvider.getRootNavController().setRoot(pageName, params, { animate: false });
return CoreApp.instance.getRootNavController().setRoot(pageName, params, { animate: false });
} else {
return this.appProvider.getRootNavController().push(pageName, params);
return CoreApp.instance.getRootNavController().push(pageName, params);
}
}
@ -530,7 +541,7 @@ export class CoreLoginHelperProvider {
* @return Promise resolved when done.
*/
goToNoSitePage(navCtrl: NavController, page: string, params?: any): Promise<any> {
navCtrl = navCtrl || this.appProvider.getRootNavController();
navCtrl = navCtrl || CoreApp.instance.getRootNavController();
const currentPage = navCtrl && navCtrl.getActive().component.name;
@ -728,7 +739,7 @@ export class CoreLoginHelperProvider {
* @return True if embedded browser, false othwerise.
*/
isSSOEmbeddedBrowser(code: number): boolean {
if (this.appProvider.isLinux()) {
if (CoreApp.instance.isLinux()) {
// In Linux desktop app, always use embedded browser.
return true;
}
@ -755,7 +766,7 @@ export class CoreLoginHelperProvider {
* @return Promise resolved when done.
*/
protected loadSiteAndPage(page: string, params: any, siteId: string): Promise<any> {
const navCtrl = this.appProvider.getRootNavController();
const navCtrl = CoreApp.instance.getRootNavController();
if (siteId == CoreConstants.NO_SITE_ID) {
// Page doesn't belong to a site, just load the page.
@ -783,7 +794,7 @@ export class CoreLoginHelperProvider {
* @param params Params to pass to the page.
*/
loadPageInMainMenu(page: string, params: any): void {
if (!this.appProvider.isMainMenuOpen()) {
if (!CoreApp.instance.isMainMenuOpen()) {
// Main menu not open. Store the page to be loaded later.
this.pageToLoad = {
page: page,
@ -813,7 +824,7 @@ export class CoreLoginHelperProvider {
* @return Promise resolved when done.
*/
protected openMainMenu(navCtrl: NavController, page: string, params: any, options?: NavOptions, url?: string): Promise<any> {
navCtrl = navCtrl || this.appProvider.getRootNavController();
navCtrl = navCtrl || CoreApp.instance.getRootNavController();
// Due to DeepLinker, we need to remove the path from the URL before going to main menu.
// IonTabs checks the URL to determine which path to load for deep linking, so we clear the URL.
@ -857,7 +868,7 @@ export class CoreLoginHelperProvider {
oauthsso: params.id,
});
if (this.appProvider.isLinux()) {
if (CoreApp.instance.isLinux()) {
// In Linux desktop app, always use embedded browser.
this.utils.openInApp(loginUrl);
} else {
@ -974,7 +985,7 @@ export class CoreLoginHelperProvider {
return; // Site that triggered the event is not current site.
}
const rootNavCtrl = this.appProvider.getRootNavController(),
const rootNavCtrl = CoreApp.instance.getRootNavController(),
activePage = rootNavCtrl.getActive();
// If current page is already change password, stop.
@ -1041,7 +1052,7 @@ export class CoreLoginHelperProvider {
// Target page belongs to a different site. Change site.
if (this.sitePluginsProvider.hasSitePluginsLoaded) {
// The site has site plugins so the app will be restarted. Store the data and logout.
this.appProvider.storeRedirect(siteId, page, params);
CoreApp.instance.storeRedirect(siteId, page, params);
return this.sitesProvider.logout();
} else {
@ -1056,7 +1067,7 @@ export class CoreLoginHelperProvider {
if (siteId) {
return this.loadSiteAndPage(page, params, siteId);
} else {
return this.appProvider.getRootNavController().setRoot('CoreLoginSitesPage');
return CoreApp.instance.getRootNavController().setRoot('CoreLoginSitesPage');
}
}
@ -1113,7 +1124,7 @@ export class CoreLoginHelperProvider {
if (this.isSSOLoginNeeded(result.code)) {
// SSO. User needs to authenticate in a browser. Check if we need to display a message.
if (!this.appProvider.isSSOAuthenticationOngoing() && !this.isSSOConfirmShown && !this.waitingForBrowser) {
if (!CoreApp.instance.isSSOAuthenticationOngoing() && !this.isSSOConfirmShown && !this.waitingForBrowser) {
this.isSSOConfirmShown = true;
if (this.shouldShowSSOConfirm(result.code)) {
@ -1146,7 +1157,7 @@ export class CoreLoginHelperProvider {
});
if (providerToUse) {
if (!this.appProvider.isSSOAuthenticationOngoing() && !this.isSSOConfirmShown && !this.waitingForBrowser) {
if (!CoreApp.instance.isSSOAuthenticationOngoing() && !this.isSSOConfirmShown && !this.waitingForBrowser) {
// Open browser to perform the OAuth.
this.isSSOConfirmShown = true;
@ -1173,7 +1184,7 @@ export class CoreLoginHelperProvider {
const info = currentSite.getInfo();
if (typeof info != 'undefined' && typeof info.username != 'undefined' && !this.isOpeningReconnect) {
const rootNavCtrl = this.appProvider.getRootNavController(),
const rootNavCtrl = CoreApp.instance.getRootNavController(),
activePage = rootNavCtrl.getActive();
// If current page is already reconnect, stop.
@ -1222,7 +1233,7 @@ export class CoreLoginHelperProvider {
* @param message The warning message.
*/
protected showWorkplaceNoticeModal(message: string): void {
const link = this.appProvider.getAppStoreUrl({android: 'com.moodle.workplace', ios: 'id1470929705' });
const link = CoreApp.instance.getAppStoreUrl({android: 'com.moodle.workplace', ios: 'id1470929705' });
this.showDownloadAppNoticeModal(message, link);
}
@ -1238,7 +1249,7 @@ export class CoreLoginHelperProvider {
storesConfig.mobile = 'https://download.moodle.org/mobile/';
storesConfig.default = 'https://download.moodle.org/mobile/';
const link = this.appProvider.getAppStoreUrl(storesConfig);
const link = CoreApp.instance.getAppStoreUrl(storesConfig);
this.showDownloadAppNoticeModal(message, link);
}
@ -1272,7 +1283,7 @@ export class CoreLoginHelperProvider {
});
alert.present().then(() => {
const isDevice = this.platform.is('android') || CoreApp.instance.isIOS();
const isDevice = CoreApp.instance.isAndroid() || CoreApp.instance.isIOS();
if (!isDevice) {
// Treat all anchors so they don't override the app.
const alertMessageEl: HTMLElement = alert.pageRef().nativeElement.querySelector('.alert-message');
@ -1358,7 +1369,7 @@ export class CoreLoginHelperProvider {
return;
}
const rootNavCtrl = this.appProvider.getRootNavController(),
const rootNavCtrl = CoreApp.instance.getRootNavController(),
activePage = rootNavCtrl.getActive();
// If current page is already site policy, stop.

View File

@ -18,7 +18,7 @@ import { Badge } from '@ionic-native/badge';
import { Push, PushObject, PushOptions } from '@ionic-native/push';
import { Device } from '@ionic-native/device';
import { TranslateService } from '@ngx-translate/core';
import { CoreAppProvider, CoreAppSchema } from '@providers/app';
import { CoreApp, CoreAppProvider, CoreAppSchema } from '@providers/app';
import { CoreInitDelegate } from '@providers/init';
import { CoreLoggerProvider } from '@providers/logger';
import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites';
@ -178,13 +178,26 @@ export class CorePushNotificationsProvider {
],
};
constructor(logger: CoreLoggerProvider, protected appProvider: CoreAppProvider, private initDelegate: CoreInitDelegate,
protected pushNotificationsDelegate: CorePushNotificationsDelegate, protected sitesProvider: CoreSitesProvider,
private badge: Badge, private localNotificationsProvider: CoreLocalNotificationsProvider,
private utils: CoreUtilsProvider, private textUtils: CoreTextUtilsProvider, private push: Push,
private configProvider: CoreConfigProvider, private device: Device, private zone: NgZone,
private translate: TranslateService, private platform: Platform, private sitesFactory: CoreSitesFactoryProvider,
private filterProvider: CoreFilterProvider, private filterDelegate: CoreFilterDelegate) {
constructor(
logger: CoreLoggerProvider,
private initDelegate: CoreInitDelegate,
protected pushNotificationsDelegate: CorePushNotificationsDelegate,
protected sitesProvider: CoreSitesProvider,
private badge: Badge,
private localNotificationsProvider: CoreLocalNotificationsProvider,
private utils: CoreUtilsProvider,
private textUtils: CoreTextUtilsProvider,
private push: Push,
private configProvider: CoreConfigProvider,
private device: Device,
private zone: NgZone,
private translate: TranslateService,
platform: Platform,
appProvider: CoreAppProvider,
private sitesFactory: CoreSitesFactoryProvider,
private filterProvider: CoreFilterProvider,
private filterDelegate: CoreFilterDelegate
) {
this.logger = logger.getInstance('CorePushNotificationsProvider');
this.appDB = appProvider.getDB();
this.dbReady = appProvider.createTablesFromSchema(this.appTablesSchema).catch(() => {
@ -209,7 +222,7 @@ export class CorePushNotificationsProvider {
* @return Whether the device can be registered in Moodle.
*/
canRegisterOnMoodle(): boolean {
return this.pushID && this.appProvider.isMobile();
return this.pushID && CoreApp.instance.isMobile();
}
/**
@ -234,7 +247,7 @@ export class CorePushNotificationsProvider {
* @return Promise resolved when done.
*/
protected createDefaultChannel(): Promise<any> {
if (!this.platform.is('android')) {
if (!CoreApp.instance.isAndroid()) {
return Promise.resolve();
}
@ -467,7 +480,7 @@ export class CorePushNotificationsProvider {
instanceId: 0,
filter: true
},
isAndroid = this.platform.is('android'),
isAndroid = CoreApp.instance.isAndroid(),
extraFeatures = this.utils.isTrueOrOne(data.extrafeatures);
// Get the filters to apply to text and message. Don't use FIlterHelper to prevent circular dependencies.
@ -544,7 +557,7 @@ export class CorePushNotificationsProvider {
* @return Promise resolved when device is unregistered.
*/
async unregisterDeviceOnMoodle(site: CoreSite): Promise<any> {
if (!site || !this.appProvider.isMobile()) {
if (!site || !CoreApp.instance.isMobile()) {
return Promise.reject(null);
}
@ -632,7 +645,7 @@ export class CorePushNotificationsProvider {
return previous + parseInt(counter, 10);
}, 0);
if (!this.appProvider.isDesktop() && !this.appProvider.isMobile()) {
if (!CoreApp.instance.isDesktop() && !CoreApp.instance.isMobile()) {
// Browser doesn't have an app badge, stop.
return total;
}

View File

@ -14,7 +14,7 @@
import { Directive, Input, AfterViewInit, ElementRef, OnChanges, SimpleChange, Output, EventEmitter } from '@angular/core';
import { Platform } from 'ionic-angular';
import { CoreAppProvider } from '@providers/app';
import { CoreApp } from '@providers/app';
import { CoreLoggerProvider } from '@providers/logger';
import { CoreFile } from '@providers/file';
import { CoreFilepoolProvider } from '@providers/filepool';
@ -60,7 +60,6 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges {
protected sitesProvider: CoreSitesProvider,
protected domUtils: CoreDomUtilsProvider,
protected urlUtils: CoreUrlUtilsProvider,
protected appProvider: CoreAppProvider,
protected utils: CoreUtilsProvider) {
this.element = element.nativeElement;
@ -104,7 +103,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges {
newSource.setAttribute('src', url);
if (type) {
if (this.platform.is('android') && type == 'video/quicktime') {
if (CoreApp.instance.isAndroid() && type == 'video/quicktime') {
// Fix for VideoJS/Chrome bug https://github.com/videojs/video.js/issues/423 .
newSource.setAttribute('type', 'video/mp4');
} else {
@ -198,7 +197,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges {
const track = <TextTrack> event.track;
if (track) {
track.oncuechange = (): void => {
const line = this.platform.is('tablet') || this.platform.is('android') ? 90 : 80;
const line = this.platform.is('tablet') || CoreApp.instance.isAndroid() ? 90 : 80;
// Position all subtitles to a percentage of video height.
Array.from(track.cues).forEach((cue: any) => {
cue.snapToLines = false;
@ -281,7 +280,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges {
clickableEl.addEventListener(eventName, () => {
// User played media or opened a downloadable link.
// Download the file if in wifi and it hasn't been downloaded already (for big files).
if (this.appProvider.isWifi()) {
if (CoreApp.instance.isWifi()) {
// We aren't using the result, so it doesn't matter which of the 2 functions we call.
this.filepoolProvider.getUrlByUrl(siteId, url, this.component, this.componentId, 0, false);
}

View File

@ -17,7 +17,6 @@ import {
} from '@angular/core';
import { Platform, NavController, Content } from 'ionic-angular';
import { TranslateService } from '@ngx-translate/core';
import { CoreAppProvider } from '@providers/app';
import { CoreEventsProvider } from '@providers/events';
import { CoreFilepoolProvider } from '@providers/filepool';
import { CoreLoggerProvider } from '@providers/logger';
@ -84,7 +83,6 @@ export class CoreFormatTextDirective implements OnChanges {
protected urlUtils: CoreUrlUtilsProvider,
protected loggerProvider: CoreLoggerProvider,
protected filepoolProvider: CoreFilepoolProvider,
protected appProvider: CoreAppProvider,
protected contentLinksHelper: CoreContentLinksHelperProvider,
@Optional() protected navCtrl: NavController,
@Optional() protected content: Content, @Optional()
@ -124,7 +122,7 @@ export class CoreFormatTextDirective implements OnChanges {
protected addExternalContent(element: Element): CoreExternalContentDirective {
// Angular 2 doesn't let adding directives dynamically. Create the CoreExternalContentDirective manually.
const extContent = new CoreExternalContentDirective(new ElementRef(element), this.loggerProvider, this.filepoolProvider,
this.platform, this.sitesProvider, this.domUtils, this.urlUtils, this.appProvider, this.utils);
this.platform, this.sitesProvider, this.domUtils, this.urlUtils, this.utils);
extContent.component = this.component;
extContent.componentId = this.componentId;

View File

@ -804,7 +804,7 @@ export class CoreAppProvider {
this.statusBar.overlaysWebView(false);
this.statusBar.backgroundColorByHexString(CoreConfigConstants.statusbarbgios);
CoreConfigConstants.statusbarlighttextios ? this.statusBar.styleLightContent() : this.statusBar.styleDefault();
} else if (typeof CoreConfigConstants.statusbarbgandroid == 'string' && this.platform.is('android')) {
} else if (typeof CoreConfigConstants.statusbarbgandroid == 'string' && this.isAndroid()) {
// Android Status bar properties.
this.statusBar.backgroundColorByHexString(CoreConfigConstants.statusbarbgandroid);
CoreConfigConstants.statusbarlighttextandroid ? this.statusBar.styleLightContent() : this.statusBar.styleDefault();
@ -815,7 +815,7 @@ export class CoreAppProvider {
CoreConfigConstants.statusbarlighttext ? this.statusBar.styleLightContent() : this.statusBar.styleDefault();
} else {
// Default Status bar properties.
this.platform.is('android') ? this.statusBar.styleLightContent() : this.statusBar.styleDefault();
this.isAndroid() ? this.statusBar.styleLightContent() : this.statusBar.styleDefault();
}
}
@ -825,7 +825,7 @@ export class CoreAppProvider {
resetStatusBarColor(): void {
if (typeof CoreConfigConstants.statusbarbgremotetheme == 'string' &&
((typeof CoreConfigConstants.statusbarbgios == 'string' && this.isIOS()) ||
(typeof CoreConfigConstants.statusbarbgandroid == 'string' && this.platform.is('android')) ||
(typeof CoreConfigConstants.statusbarbgandroid == 'string' && this.isAndroid()) ||
typeof CoreConfigConstants.statusbarbg == 'string')) {
// If the status bar has been overriden and there's a fallback color for remote themes, use it now.
this.isIOS() && this.statusBar.overlaysWebView(false);

View File

@ -15,7 +15,7 @@
import { Injectable } from '@angular/core';
import { Platform } from 'ionic-angular';
import { File, FileEntry, DirectoryEntry, Entry, Metadata } from '@ionic-native/file';
import { CoreApp } from './app';
import { CoreApp, CoreAppProvider } from './app';
import { CoreLoggerProvider } from './logger';
import { CoreMimetypeUtilsProvider } from './utils/mimetype';
import { CoreTextUtilsProvider } from './utils/text';
@ -72,6 +72,7 @@ export class CoreFileProvider {
protected isHTMLAPI = false;
constructor(logger: CoreLoggerProvider,
appProvider: CoreAppProvider,
protected platform: Platform,
protected file: File,
protected textUtils: CoreTextUtilsProvider,
@ -80,7 +81,7 @@ export class CoreFileProvider {
this.logger = logger.getInstance('CoreFileProvider');
if (platform.is('android') && !Object.getOwnPropertyDescriptor(FileReader.prototype, 'onloadend')) {
if (appProvider.isAndroid() && !Object.getOwnPropertyDescriptor(FileReader.prototype, 'onloadend')) {
// Cordova File plugin creates some getters and setter for FileReader, but Ionic's polyfills override them in Android.
// Create the getters and setters again. This code comes from FileReader.js in cordova-plugin-file.
this.defineGetterSetter(FileReader.prototype, 'readyState', function(): any {
@ -176,7 +177,7 @@ export class CoreFileProvider {
return this.platform.ready().then(() => {
if (this.platform.is('android')) {
if (CoreApp.instance.isAndroid()) {
this.basePath = this.file.externalApplicationStorageDirectory || this.basePath;
} else if (CoreApp.instance.isIOS()) {
this.basePath = this.file.documentsDirectory || this.basePath;

View File

@ -17,7 +17,7 @@ import { Platform, Alert, AlertController } from 'ionic-angular';
import { LocalNotifications, ILocalNotification } from '@ionic-native/local-notifications';
import { Push } from '@ionic-native/push';
import { TranslateService } from '@ngx-translate/core';
import { CoreAppProvider, CoreAppSchema } from './app';
import { CoreApp, CoreAppProvider, CoreAppSchema } from './app';
import { CoreConfigProvider } from './config';
import { CoreEventsProvider } from './events';
import { CoreLoggerProvider } from './logger';
@ -115,10 +115,19 @@ export class CoreLocalNotificationsProvider {
protected updateSubscription: Subscription;
protected queueRunner: CoreQueueRunner; // Queue to decrease the number of concurrent calls to the plugin (see MOBILE-3477).
constructor(logger: CoreLoggerProvider, private localNotifications: LocalNotifications, private platform: Platform,
private appProvider: CoreAppProvider, private utils: CoreUtilsProvider, private configProvider: CoreConfigProvider,
private textUtils: CoreTextUtilsProvider, private translate: TranslateService, private alertCtrl: AlertController,
eventsProvider: CoreEventsProvider, private push: Push, private zone: NgZone) {
constructor(
logger: CoreLoggerProvider,
private localNotifications: LocalNotifications,
private platform: Platform,
private utils: CoreUtilsProvider,
private configProvider: CoreConfigProvider,
private textUtils: CoreTextUtilsProvider,
private translate: TranslateService,
private alertCtrl: AlertController,
eventsProvider: CoreEventsProvider,
appProvider: CoreAppProvider,
private push: Push,
private zone: NgZone) {
this.logger = logger.getInstance('CoreLocalNotificationsProvider');
this.queueRunner = new CoreQueueRunner(10);
@ -228,7 +237,7 @@ export class CoreLocalNotificationsProvider {
*/
canDisableSound(): boolean {
// Only allow disabling sound in Android 7 or lower. In iOS and Android 8+ it can easily be done with system settings.
return this.isAvailable() && !this.appProvider.isDesktop() && this.platform.is('android') &&
return this.isAvailable() && !CoreApp.instance.isDesktop() && CoreApp.instance.isAndroid() &&
this.platform.version().major < 8;
}
@ -238,7 +247,7 @@ export class CoreLocalNotificationsProvider {
* @return Promise resolved when done.
*/
protected createDefaultChannel(): Promise<any> {
if (!this.platform.is('android')) {
if (!CoreApp.instance.isAndroid()) {
return Promise.resolve();
}
@ -368,7 +377,7 @@ export class CoreLocalNotificationsProvider {
isAvailable(): boolean {
const win = <any> window;
return this.appProvider.isDesktop() || !!(win.cordova && win.cordova.plugins && win.cordova.plugins.notification &&
return CoreApp.instance.isDesktop() || !!(win.cordova && win.cordova.plugins && win.cordova.plugins.notification &&
win.cordova.plugins.notification.local);
}
@ -609,7 +618,7 @@ export class CoreLocalNotificationsProvider {
notification.data.component = component;
notification.data.siteId = siteId;
if (this.platform.is('android')) {
if (CoreApp.instance.isAndroid()) {
notification.icon = notification.icon || 'res://icon';
notification.smallIcon = notification.smallIcon || 'res://smallicon';
notification.color = notification.color || CoreConfigConstants.notificoncolor;

View File

@ -14,13 +14,13 @@
import { Injectable, SimpleChange, ElementRef } from '@angular/core';
import {
LoadingController, Loading, ToastController, Toast, AlertController, Alert, Platform, Content, PopoverController,
LoadingController, Loading, ToastController, Toast, AlertController, Alert, Content, PopoverController,
ModalController, AlertButton, AlertOptions
} from 'ionic-angular';
import { DomSanitizer } from '@angular/platform-browser';
import { TranslateService } from '@ngx-translate/core';
import { CoreTextUtilsProvider } from './text';
import { CoreAppProvider } from '../app';
import { CoreApp } from '../app';
import { CoreConfigProvider } from '../config';
import { CoreEventsProvider } from '../events';
import { CoreLoggerProvider } from '../logger';
@ -71,8 +71,6 @@ export class CoreDomUtilsProvider {
protected toastCtrl: ToastController,
protected alertCtrl: AlertController,
protected textUtils: CoreTextUtilsProvider,
protected appProvider: CoreAppProvider,
protected platform: Platform,
protected configProvider: CoreConfigProvider,
protected urlUtils: CoreUrlUtilsProvider,
protected modalCtrl: ModalController,
@ -147,12 +145,12 @@ export class CoreDomUtilsProvider {
const readableSize = this.textUtils.bytesToSize(size.size, 2);
const getAvailableBytes = new Promise((resolve): void => {
if (this.appProvider.isDesktop()) {
if (CoreApp.instance.isDesktop()) {
// Free space calculation is not supported on desktop.
resolve(null);
} else {
this.fileProvider.calculateFreeSpace().then((availableBytes) => {
if (this.platform.is('android')) {
if (CoreApp.instance.isAndroid()) {
return availableBytes;
} else {
// Space calculation is not accurate on iOS, but it gets more accurate when space is lower.
@ -174,7 +172,7 @@ export class CoreDomUtilsProvider {
return '';
} else {
const availableSize = this.textUtils.bytesToSize(availableBytes, 2);
if (this.platform.is('android') && size.size > availableBytes - CoreConstants.MINIMUM_FREE_SPACE) {
if (CoreApp.instance.isAndroid() && size.size > availableBytes - CoreConstants.MINIMUM_FREE_SPACE) {
return Promise.reject(this.translate.instant('core.course.insufficientavailablespace', { size: readableSize }));
}
@ -187,7 +185,7 @@ export class CoreDomUtilsProvider {
limitedThreshold = typeof limitedThreshold == 'undefined' ? CoreConstants.DOWNLOAD_THRESHOLD : limitedThreshold;
let wifiPrefix = '';
if (this.appProvider.isNetworkAccessLimited()) {
if (CoreApp.instance.isNetworkAccessLimited()) {
wifiPrefix = this.translate.instant('core.course.confirmlimiteddownload');
}
@ -202,7 +200,7 @@ export class CoreDomUtilsProvider {
return this.showConfirm(wifiPrefix + this.translate.instant('core.course.confirmpartialdownloadsize',
{ size: readableSize, availableSpace: availableSpace }));
} else if (alwaysConfirm || size.size >= wifiThreshold ||
(this.appProvider.isNetworkAccessLimited() && size.size >= limitedThreshold)) {
(CoreApp.instance.isNetworkAccessLimited() && size.size >= limitedThreshold)) {
message = message || (size.size === 0 ? 'core.course.confirmdownloadzerosize' : 'core.course.confirmdownload');
return this.showConfirm(wifiPrefix + this.translate.instant(message,
@ -377,9 +375,9 @@ export class CoreDomUtilsProvider {
focusElement(el: HTMLElement): void {
if (el && el.focus) {
el.focus();
if (this.platform.is('android') && this.supportsInputKeyboard(el)) {
if (CoreApp.instance.isAndroid() && this.supportsInputKeyboard(el)) {
// On some Android versions the keyboard doesn't open automatically.
this.appProvider.openKeyboard();
CoreApp.instance.openKeyboard();
}
}
}
@ -1562,7 +1560,7 @@ export class CoreDomUtilsProvider {
event.stopPropagation();
// We cannot use CoreDomUtilsProvider.openInBrowser due to circular dependencies.
if (this.appProvider.isDesktop()) {
if (CoreApp.instance.isDesktop()) {
// It's a desktop app, use Electron shell library to open the browser.
const shell = require('electron').shell;
if (!shell.openExternal(href)) {

View File

@ -14,10 +14,11 @@
import { Injectable } from '@angular/core';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
import { ModalController, Platform } from 'ionic-angular';
import { ModalController } from 'ionic-angular';
import { TranslateService } from '@ngx-translate/core';
import { CoreLangProvider } from '../lang';
import { makeSingleton } from '@singletons/core.singletons';
import { CoreApp } from '../app';
/**
* Different type of errors the app can treat.
@ -84,8 +85,12 @@ export class CoreTextUtilsProvider {
protected template = document.createElement('template'); // A template element to convert HTML to element.
constructor(private translate: TranslateService, private langProvider: CoreLangProvider, private modalCtrl: ModalController,
private sanitizer: DomSanitizer, private platform: Platform) { }
constructor(
private translate: TranslateService,
private langProvider: CoreLangProvider,
private modalCtrl: ModalController,
private sanitizer: DomSanitizer
) { }
/**
* Add ending slash from a path or URL.
@ -139,7 +144,7 @@ export class CoreTextUtilsProvider {
* @return URL to view the address.
*/
buildAddressURL(address: string): SafeUrl {
return this.sanitizer.bypassSecurityTrustUrl((this.platform.is('android') ? 'geo:0,0?q=' : 'http://maps.google.com?q=') +
return this.sanitizer.bypassSecurityTrustUrl((CoreApp.instance.isAndroid() ? 'geo:0,0?q=' : 'http://maps.google.com?q=') +
encodeURIComponent(address));
}

View File

@ -903,7 +903,7 @@ export class CoreUtilsProvider {
const extension = this.mimetypeUtils.getFileExtension(path);
const mimetype = this.mimetypeUtils.getMimeType(extension);
if (mimetype == 'text/html' && this.platform.is('android')) {
if (mimetype == 'text/html' && CoreApp.instance.isAndroid()) {
// Open HTML local files in InAppBrowser, in system browser some embedded files aren't loaded.
this.openInApp(path);
@ -984,7 +984,7 @@ export class CoreUtilsProvider {
});
});
if (this.platform.is('android')) {
if (CoreApp.instance.isAndroid()) {
// Load stop is needed with InAppBrowser v3. Custom URL schemes no longer trigger load start, simulate it.
loadStopSubscription = this.iabInstance.on('loadstop').subscribe((event) => {
// Execute the callback in the Angular zone, so change detection doesn't stop working.
@ -1038,7 +1038,7 @@ export class CoreUtilsProvider {
* @return Promise resolved when opened.
*/
openOnlineFile(url: string): Promise<void> {
if (this.platform.is('android')) {
if (CoreApp.instance.isAndroid()) {
// In Android we need the mimetype to open it.
return this.getMimeTypeFromUrl(url).catch(() => {
// Error getting mimetype, return undefined.