MOBILE-3761 ios: Change open file config variable

main
Dani Palou 2021-05-27 13:18:47 +02:00
parent 778ad6d803
commit 8dbde34790
8 changed files with 27 additions and 17 deletions

View File

@ -46,12 +46,12 @@
</div> </div>
<ng-container *ngIf="mode == 'external'"> <ng-container *ngIf="mode == 'external'">
<ion-button expand="block" class="ion-margin" (click)="open(false)"> <ion-button expand="block" class="ion-margin" (click)="open(openFileAction.OPEN)">
<ion-icon name="far-file" slot="start" aria-hidden="true"></ion-icon> <ion-icon name="far-file" slot="start" aria-hidden="true"></ion-icon>
{{ 'addon.mod_resource.openthefile' | translate }} {{ 'addon.mod_resource.openthefile' | translate }}
</ion-button> </ion-button>
<ion-button *ngIf="isIOS" expand="block" class="ion-margin" (click)="open(true)"> <ion-button *ngIf="isIOS" expand="block" class="ion-margin" (click)="open(openFileAction.OPEN_WITH)">
<ion-icon name="far-share-square" slot="start" aria-hidden="true"></ion-icon> <ion-icon name="far-share-square" slot="start" aria-hidden="true"></ion-icon>
{{ 'core.openwith' | translate }} {{ 'core.openwith' | translate }}
</ion-button> </ion-button>

View File

@ -23,7 +23,7 @@ import { CoreCourseModulePrefetchDelegate } from '@features/course/services/modu
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils, OpenFileAction } from '@services/utils/utils';
import { Translate } from '@singletons'; import { Translate } from '@singletons';
import { import {
AddonModResource, AddonModResource,
@ -51,6 +51,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
displayDescription = true; displayDescription = true;
warning = ''; warning = '';
isIOS = false; isIOS = false;
openFileAction = OpenFileAction;
constructor(@Optional() courseContentsPage?: CoreCourseContentsPage) { constructor(@Optional() courseContentsPage?: CoreCourseContentsPage) {
super('AddonModResourceIndexComponent', courseContentsPage); super('AddonModResourceIndexComponent', courseContentsPage);
@ -158,10 +159,10 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
/** /**
* Opens a file. * Opens a file.
* *
* @param useIOSPicker Whether to use the picker in iOS. * @param iOSOpenFileAction Action to do in iOS.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
async open(useIOSPicker?: boolean): Promise<void> { async open(iOSOpenFileAction?: OpenFileAction): Promise<void> {
let downloadable = await CoreCourseModulePrefetchDelegate.isModuleDownloadable(this.module, this.courseId); let downloadable = await CoreCourseModulePrefetchDelegate.isModuleDownloadable(this.module, this.courseId);
if (downloadable) { if (downloadable) {
@ -170,7 +171,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
downloadable = await AddonModResourceHelper.isMainFileDownloadable(this.module); downloadable = await AddonModResourceHelper.isMainFileDownloadable(this.module);
if (downloadable) { if (downloadable) {
return AddonModResourceHelper.openModuleFile(this.module, this.courseId, { useIOSPicker }); return AddonModResourceHelper.openModuleFile(this.module, this.courseId, { iOSOpenFileAction });
} }
} }

View File

@ -21,7 +21,7 @@ import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreUrlUtils } from '@services/utils/url'; 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 { CoreTextUtils } from '@services/utils/text';
import { CoreConstants } from '@/core/constants'; import { CoreConstants } from '@/core/constants';
import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreEventObserver, CoreEvents } from '@singletons/events';
@ -151,7 +151,7 @@ export class CoreFileComponent implements OnInit, OnDestroy {
const options: CoreUtilsOpenFileOptions = {}; const options: CoreUtilsOpenFileOptions = {};
if (isOpenButton) { if (isOpenButton) {
// Use the non-default method. // 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) => { return CoreFileHelper.downloadAndOpenFile(this.file!, this.component, this.componentId, this.state, (event) => {

View File

@ -17,7 +17,7 @@
(click)="$event.stopPropagation()" core-auto-focus [(ngModel)]="newFileName" *ngIf="editMode"> (click)="$event.stopPropagation()" core-auto-focus [(ngModel)]="newFileName" *ngIf="editMode">
</ion-input> </ion-input>
<div class="buttons" slot="end" *ngIf="manage"> <div class="buttons" slot="end">
<ion-button fill="clear" *ngIf="isIOS" (click)="openFile($event, true)" <ion-button fill="clear" *ngIf="isIOS" (click)="openFile($event, true)"
[attr.aria-label]="openButtonLabel | translate"> [attr.aria-label]="openButtonLabel | translate">
<ion-icon slot="icon-only" [name]="openButtonIcon" aria-hidden="true"></ion-icon> <ion-icon slot="icon-only" [name]="openButtonIcon" aria-hidden="true"></ion-icon>

View File

@ -23,7 +23,7 @@ import { CoreDomUtils } from '@services/utils/dom';
import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreTimeUtils } from '@services/utils/time'; 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 { CoreForms } from '@singletons/form';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
@ -135,7 +135,7 @@ export class CoreLocalFileComponent implements OnInit {
const options: CoreUtilsOpenFileOptions = {}; const options: CoreUtilsOpenFileOptions = {};
if (isOpenButton) { if (isOpenButton) {
// Use the non-default method. // Use the non-default method.
options.useIOSPicker = !this.defaultIsOpenWithPicker; options.iOSOpenFileAction = this.defaultIsOpenWithPicker ? OpenFileAction.OPEN : OpenFileAction.OPEN_WITH;
} }
CoreUtils.openFile(this.file!.toURL(), options); CoreUtils.openFile(this.file!.toURL(), options);

View File

@ -17,6 +17,7 @@
import { CoreColorScheme, CoreZoomLevel } from '@features/settings/services/settings-helper'; import { CoreColorScheme, CoreZoomLevel } from '@features/settings/services/settings-helper';
import { CoreSitesDemoSiteData } from '@services/sites'; import { CoreSitesDemoSiteData } from '@services/sites';
import envJson from '@/assets/env.json'; import envJson from '@/assets/env.json';
import { OpenFileAction } from '@services/utils/utils';
/** /**
* Context levels enumeration. * Context levels enumeration.
@ -173,7 +174,7 @@ export interface EnvironmentConfig {
displayqroncredentialscreen?: boolean; displayqroncredentialscreen?: boolean;
displayqronsitescreen?: boolean; displayqronsitescreen?: boolean;
forceOpenLinksIn: 'app' | 'browser'; forceOpenLinksIn: 'app' | 'browser';
iosopenfilepicker?: boolean; iOSDefaultOpenFileAction?: OpenFileAction;
}; };
export interface EnvironmentBuild { export interface EnvironmentBuild {

View File

@ -22,7 +22,7 @@ import { CoreSites } from '@services/sites';
import { CoreWS, CoreWSFile } from '@services/ws'; import { CoreWS, CoreWSFile } from '@services/ws';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreUrlUtils } from '@services/utils/url'; 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 { CoreConstants } from '@/core/constants';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
@ -40,7 +40,7 @@ export class CoreFileHelperProvider {
* @return Boolean. * @return Boolean.
*/ */
defaultIsOpenWithPicker(): boolean { defaultIsOpenWithPicker(): boolean {
return CoreApp.isIOS() && !!CoreConstants.CONFIG.iosopenfilepicker; return CoreApp.isIOS() && CoreConstants.CONFIG.iOSDefaultOpenFileAction === OpenFileAction.OPEN_WITH;
} }
/** /**

View File

@ -933,8 +933,8 @@ export class CoreUtilsProvider {
} }
try { try {
const useIOSPicker = options.useIOSPicker ?? CoreConstants.CONFIG.iosopenfilepicker; const openFileAction = options.iOSOpenFileAction ?? CoreConstants.CONFIG.iOSDefaultOpenFileAction;
if (useIOSPicker && CoreApp.isIOS()) { if (CoreApp.isIOS() && openFileAction == OpenFileAction.OPEN_WITH) {
await FileOpener.showOpenWithDialog(path, mimetype || ''); await FileOpener.showOpenWithDialog(path, mimetype || '');
} else { } else {
await FileOpener.open(path, mimetype || ''); await FileOpener.open(path, mimetype || '');
@ -1715,5 +1715,13 @@ export type CoreMenuItem<T = number> = {
* Options for opening a file. * Options for opening a file.
*/ */
export type CoreUtilsOpenFileOptions = { 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',
}