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>
<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>
{{ 'addon.mod_resource.openthefile' | translate }}
</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>
{{ 'core.openwith' | translate }}
</ion-button>

View File

@ -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<void> {
async open(iOSOpenFileAction?: OpenFileAction): Promise<void> {
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 });
}
}

View File

@ -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) => {

View File

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

View File

@ -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 {

View File

@ -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;
}
/**

View File

@ -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<T = number> = {
* 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',
}