From 8dbde347908fe72cfc76e05bb4c8ac1a24ed390e Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 27 May 2021 13:18:47 +0200 Subject: [PATCH] MOBILE-3761 ios: Change open file config variable --- .../components/index/addon-mod-resource-index.html | 4 ++-- src/addons/mod/resource/components/index/index.ts | 9 +++++---- src/core/components/file/file.ts | 4 ++-- .../components/local-file/core-local-file.html | 2 +- src/core/components/local-file/local-file.ts | 4 ++-- src/core/constants.ts | 3 ++- src/core/services/file-helper.ts | 4 ++-- src/core/services/utils/utils.ts | 14 +++++++++++--- 8 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/addons/mod/resource/components/index/addon-mod-resource-index.html b/src/addons/mod/resource/components/index/addon-mod-resource-index.html index 769e29baa..da8328553 100644 --- a/src/addons/mod/resource/components/index/addon-mod-resource-index.html +++ b/src/addons/mod/resource/components/index/addon-mod-resource-index.html @@ -46,12 +46,12 @@ - + {{ 'addon.mod_resource.openthefile' | translate }} - + {{ 'core.openwith' | translate }} diff --git a/src/addons/mod/resource/components/index/index.ts b/src/addons/mod/resource/components/index/index.ts index be18c8f05..1245be191 100644 --- a/src/addons/mod/resource/components/index/index.ts +++ b/src/addons/mod/resource/components/index/index.ts @@ -23,7 +23,7 @@ import { CoreCourseModulePrefetchDelegate } from '@features/course/services/modu import { CoreApp } from '@services/app'; import { CoreSites } from '@services/sites'; import { CoreTextUtils } from '@services/utils/text'; -import { CoreUtils } from '@services/utils/utils'; +import { CoreUtils, OpenFileAction } from '@services/utils/utils'; import { Translate } from '@singletons'; import { AddonModResource, @@ -51,6 +51,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource displayDescription = true; warning = ''; isIOS = false; + openFileAction = OpenFileAction; constructor(@Optional() courseContentsPage?: CoreCourseContentsPage) { super('AddonModResourceIndexComponent', courseContentsPage); @@ -158,10 +159,10 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource /** * Opens a file. * - * @param useIOSPicker Whether to use the picker in iOS. + * @param iOSOpenFileAction Action to do in iOS. * @return Promise resolved when done. */ - async open(useIOSPicker?: boolean): Promise { + async open(iOSOpenFileAction?: OpenFileAction): Promise { let downloadable = await CoreCourseModulePrefetchDelegate.isModuleDownloadable(this.module, this.courseId); if (downloadable) { @@ -170,7 +171,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource downloadable = await AddonModResourceHelper.isMainFileDownloadable(this.module); if (downloadable) { - return AddonModResourceHelper.openModuleFile(this.module, this.courseId, { useIOSPicker }); + return AddonModResourceHelper.openModuleFile(this.module, this.courseId, { iOSOpenFileAction }); } } diff --git a/src/core/components/file/file.ts b/src/core/components/file/file.ts index 380c99897..f33a1ee4c 100644 --- a/src/core/components/file/file.ts +++ b/src/core/components/file/file.ts @@ -21,7 +21,7 @@ import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreUrlUtils } from '@services/utils/url'; -import { CoreUtils, CoreUtilsOpenFileOptions } from '@services/utils/utils'; +import { CoreUtils, CoreUtilsOpenFileOptions, OpenFileAction } from '@services/utils/utils'; import { CoreTextUtils } from '@services/utils/text'; import { CoreConstants } from '@/core/constants'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; @@ -151,7 +151,7 @@ export class CoreFileComponent implements OnInit, OnDestroy { const options: CoreUtilsOpenFileOptions = {}; if (isOpenButton) { // Use the non-default method. - options.useIOSPicker = !this.defaultIsOpenWithPicker; + options.iOSOpenFileAction = this.defaultIsOpenWithPicker ? OpenFileAction.OPEN : OpenFileAction.OPEN_WITH; } return CoreFileHelper.downloadAndOpenFile(this.file!, this.component, this.componentId, this.state, (event) => { diff --git a/src/core/components/local-file/core-local-file.html b/src/core/components/local-file/core-local-file.html index 0e8552f0a..0b8925ab7 100644 --- a/src/core/components/local-file/core-local-file.html +++ b/src/core/components/local-file/core-local-file.html @@ -17,7 +17,7 @@ (click)="$event.stopPropagation()" core-auto-focus [(ngModel)]="newFileName" *ngIf="editMode"> -
+
diff --git a/src/core/components/local-file/local-file.ts b/src/core/components/local-file/local-file.ts index 204eca8e8..8f942bc6a 100644 --- a/src/core/components/local-file/local-file.ts +++ b/src/core/components/local-file/local-file.ts @@ -23,7 +23,7 @@ import { CoreDomUtils } from '@services/utils/dom'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreTextUtils } from '@services/utils/text'; import { CoreTimeUtils } from '@services/utils/time'; -import { CoreUtils, CoreUtilsOpenFileOptions } from '@services/utils/utils'; +import { CoreUtils, CoreUtilsOpenFileOptions, OpenFileAction } from '@services/utils/utils'; import { CoreForms } from '@singletons/form'; import { CoreApp } from '@services/app'; @@ -135,7 +135,7 @@ export class CoreLocalFileComponent implements OnInit { const options: CoreUtilsOpenFileOptions = {}; if (isOpenButton) { // Use the non-default method. - options.useIOSPicker = !this.defaultIsOpenWithPicker; + options.iOSOpenFileAction = this.defaultIsOpenWithPicker ? OpenFileAction.OPEN : OpenFileAction.OPEN_WITH; } CoreUtils.openFile(this.file!.toURL(), options); diff --git a/src/core/constants.ts b/src/core/constants.ts index abf5e5e11..68f1f721e 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -17,6 +17,7 @@ import { CoreColorScheme, CoreZoomLevel } from '@features/settings/services/settings-helper'; import { CoreSitesDemoSiteData } from '@services/sites'; import envJson from '@/assets/env.json'; +import { OpenFileAction } from '@services/utils/utils'; /** * Context levels enumeration. @@ -173,7 +174,7 @@ export interface EnvironmentConfig { displayqroncredentialscreen?: boolean; displayqronsitescreen?: boolean; forceOpenLinksIn: 'app' | 'browser'; - iosopenfilepicker?: boolean; + iOSDefaultOpenFileAction?: OpenFileAction; }; export interface EnvironmentBuild { diff --git a/src/core/services/file-helper.ts b/src/core/services/file-helper.ts index c90f46183..4df8e5e71 100644 --- a/src/core/services/file-helper.ts +++ b/src/core/services/file-helper.ts @@ -22,7 +22,7 @@ import { CoreSites } from '@services/sites'; import { CoreWS, CoreWSFile } from '@services/ws'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUrlUtils } from '@services/utils/url'; -import { CoreUtils, CoreUtilsOpenFileOptions } from '@services/utils/utils'; +import { CoreUtils, CoreUtilsOpenFileOptions, OpenFileAction } from '@services/utils/utils'; import { CoreConstants } from '@/core/constants'; import { CoreError } from '@classes/errors/error'; import { makeSingleton, Translate } from '@singletons'; @@ -40,7 +40,7 @@ export class CoreFileHelperProvider { * @return Boolean. */ defaultIsOpenWithPicker(): boolean { - return CoreApp.isIOS() && !!CoreConstants.CONFIG.iosopenfilepicker; + return CoreApp.isIOS() && CoreConstants.CONFIG.iOSDefaultOpenFileAction === OpenFileAction.OPEN_WITH; } /** diff --git a/src/core/services/utils/utils.ts b/src/core/services/utils/utils.ts index 2493c1592..9849c55ce 100644 --- a/src/core/services/utils/utils.ts +++ b/src/core/services/utils/utils.ts @@ -933,8 +933,8 @@ export class CoreUtilsProvider { } try { - const useIOSPicker = options.useIOSPicker ?? CoreConstants.CONFIG.iosopenfilepicker; - if (useIOSPicker && CoreApp.isIOS()) { + const openFileAction = options.iOSOpenFileAction ?? CoreConstants.CONFIG.iOSDefaultOpenFileAction; + if (CoreApp.isIOS() && openFileAction == OpenFileAction.OPEN_WITH) { await FileOpener.showOpenWithDialog(path, mimetype || ''); } else { await FileOpener.open(path, mimetype || ''); @@ -1715,5 +1715,13 @@ export type CoreMenuItem = { * Options for opening a file. */ export type CoreUtilsOpenFileOptions = { - useIOSPicker?: boolean; // Whether to let user choose app to open the file in iOS. Defaults to false (preview). + iOSOpenFileAction?: OpenFileAction; // Action to do when opening a file. }; + +/** + * Possible default picker actions. + */ +export enum OpenFileAction { + OPEN = 'open', + OPEN_WITH = 'open-with', +}