diff --git a/src/addon/mod/url/components/index/addon-mod-url-index.html b/src/addon/mod/url/components/index/addon-mod-url-index.html
index 8bfe7d722..422095419 100644
--- a/src/addon/mod/url/components/index/addon-mod-url-index.html
+++ b/src/addon/mod/url/components/index/addon-mod-url-index.html
@@ -12,20 +12,20 @@
{{ url }}
diff --git a/src/addon/mod/url/components/index/index.ts b/src/addon/mod/url/components/index/index.ts index 3b5c581ba..589de7cbf 100644 --- a/src/addon/mod/url/components/index/index.ts +++ b/src/addon/mod/url/components/index/index.ts @@ -39,6 +39,7 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo isImage = false; isAudio = false; isVideo = false; + isOther = false; mimetype: string; displayDescription = true; @@ -148,6 +149,7 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo this.isImage = this.mimeUtils.isExtensionInGroup(extension, ['web_image']); this.isAudio = this.mimeUtils.isExtensionInGroup(extension, ['web_audio']); this.isVideo = this.mimeUtils.isExtensionInGroup(extension, ['web_video']); + this.isOther = !this.isImage && !this.isAudio && !this.isVideo; } if (this.shouldIframe || (this.shouldEmbed && !this.isImage && !this.isAudio && !this.isVideo)) { diff --git a/src/addon/mod/url/providers/module-handler.ts b/src/addon/mod/url/providers/module-handler.ts index 54ccb6ead..e182343fb 100644 --- a/src/addon/mod/url/providers/module-handler.ts +++ b/src/addon/mod/url/providers/module-handler.ts @@ -18,6 +18,7 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { AddonModUrlIndexComponent } from '../components/index/index'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@core/course/providers/module-delegate'; import { CoreCourseProvider } from '@core/course/providers/course'; +import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper'; import { AddonModUrlProvider } from './url'; import { AddonModUrlHelperProvider } from './helper'; import { CoreConstants } from '@core/constants'; @@ -31,7 +32,8 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler { modName = 'url'; constructor(private courseProvider: CoreCourseProvider, private urlProvider: AddonModUrlProvider, - private urlHelper: AddonModUrlHelperProvider, private domUtils: CoreDomUtilsProvider) { } + private urlHelper: AddonModUrlHelperProvider, private domUtils: CoreDomUtilsProvider, + private contentLinksHelper: CoreContentLinksHelperProvider) { } /** * Check if the handler is enabled on a site level. @@ -59,32 +61,37 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler { class: 'addon-mod_url-handler', showDownloadButton: false, action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - // Check if we need to open the URL directly. - let promise; + const modal = handler.domUtils.showModalLoading(); - if (handler.urlProvider.isGetUrlWSAvailable()) { - const modal = handler.domUtils.showModalLoading(); + // First of all, check if the URL can be handled by the app. If so, always open it directly. + handler.contentLinksHelper.canHandleLink(module.contents[0].fileurl, courseId).then((canHandle) => { + if (canHandle) { + // URL handled by the app, open it directly. + return true; + } - promise = handler.urlProvider.getUrl(courseId, module.id).catch(() => { - // Ignore errors. - }).then((url) => { - modal.dismiss(); + // Not handled by the app, check the display type. + if (handler.urlProvider.isGetUrlWSAvailable()) { + return handler.urlProvider.getUrl(courseId, module.id).catch(() => { + // Ignore errors. + }).then((url) => { + const displayType = handler.urlProvider.getFinalDisplayType(url); - const displayType = handler.urlProvider.getFinalDisplayType(url); + return displayType == CoreConstants.RESOURCELIB_DISPLAY_OPEN || + displayType == CoreConstants.RESOURCELIB_DISPLAY_POPUP; + }); + } else { + return false; + } - return displayType == CoreConstants.RESOURCELIB_DISPLAY_OPEN || - displayType == CoreConstants.RESOURCELIB_DISPLAY_POPUP; - }); - } else { - promise = Promise.resolve(false); - } - - return promise.then((shouldOpen) => { + }).then((shouldOpen) => { if (shouldOpen) { handler.openUrl(module, courseId); } else { navCtrl.push('AddonModUrlIndexPage', {module: module, courseId: courseId}, options); } + }).finally(() => { + modal.dismiss(); }); }, buttons: [ { @@ -120,24 +127,7 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler { protected hideLinkButton(module: any, courseId: number): Promise