Skip to content

Commit 857f3da

Browse files
committed
MOBILE-3411 h5pactivity: Download automatically if size is low
1 parent e681852 commit 857f3da

File tree

9 files changed

+42
-9
lines changed

9 files changed

+42
-9
lines changed

scripts/langindex.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,12 @@
659659
"addon.mod_glossary.noentriesfound": "local_moodlemobileapp",
660660
"addon.mod_glossary.searchquery": "local_moodlemobileapp",
661661
"addon.mod_glossary.tagarea_glossary_entries": "glossary",
662+
"addon.mod_h5pactivity.downloadh5pfile": "local_moodlemobileapp",
663+
"addon.mod_h5pactivity.errorgetactivity": "local_moodlemobileapp",
664+
"addon.mod_h5pactivity.filestatenotdownloaded": "local_moodlemobileapp",
665+
"addon.mod_h5pactivity.filestateoutdated": "local_moodlemobileapp",
666+
"addon.mod_h5pactivity.modulenameplural": "h5pactivity",
667+
"addon.mod_h5pactivity.offlinedisabledwarning": "local_moodlemobileapp",
662668
"addon.mod_imscp.deploymenterror": "imscp",
663669
"addon.mod_imscp.modulenameplural": "imscp",
664670
"addon.mod_imscp.showmoduledescription": "local_moodlemobileapp",
@@ -2035,6 +2041,7 @@
20352041
"core.sort": "moodle",
20362042
"core.sortby": "moodle",
20372043
"core.start": "grouptool",
2044+
"core.storingfiles": "local_moodlemobileapp",
20382045
"core.strftimedate": "langconfig",
20392046
"core.strftimedatefullshort": "langconfig",
20402047
"core.strftimedateshort": "langconfig",

src/addon/mod/h5pactivity/components/index/addon-mod-h5pactivity-index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727

2828
<!-- Button to download the package. -->
2929
<ion-item *ngIf="!downloading && needsDownload" text-wrap>
30-
<a ion-button block (click)="downloadAndPlay($event)">{{ 'core.download' | translate }}</a>
30+
<a ion-button block (click)="downloadAndPlay($event)">{{ 'addon.mod_h5pactivity.downloadh5pfile' | translate }}</a>
3131
</ion-item>
3232

3333
<!-- Download progress. -->
3434
<ion-item text-center *ngIf="downloading">
3535
<ion-spinner></ion-spinner>
36-
<p *ngIf="progressMessage">{{ progressMessage | translate }}</p>
37-
<p *ngIf="percentage <= 100">{{ 'core.percentagenumber' | translate:{$a: percentage} }}</p>
36+
<h2 *ngIf="progressMessage">{{ progressMessage | translate }}</h2>
37+
<core-progress-bar *ngIf="percentage <= 100" [progress]="percentage"></core-progress-bar>
3838
</ion-item>
3939
</ion-list>
4040

src/addon/mod/h5pactivity/components/index/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
116116
if (!this.siteCanDownload || this.state == CoreConstants.DOWNLOADED) {
117117
// Cannot download the file or already downloaded, play the package directly.
118118
this.play();
119+
120+
} else if ((this.state == CoreConstants.NOT_DOWNLOADED || this.state == CoreConstants.OUTDATED) &&
121+
CoreFilepool.instance.shouldDownload(this.deployedFile.filesize) && CoreApp.instance.isOnline()) {
122+
// Package is small, download it automatically. Don't block this function for this.
123+
this.downloadAutomatically();
119124
}
120125
} finally {
121126
this.fillContextMenu(refresh);
@@ -244,6 +249,23 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
244249
}
245250
}
246251

252+
/**
253+
* Download the file automatically.
254+
*
255+
* @return Promise resolved when done.
256+
*/
257+
protected async downloadAutomatically(): Promise<void> {
258+
try {
259+
await this.downloadDeployedFile();
260+
261+
if (!this.isDestroyed) {
262+
this.play();
263+
}
264+
} catch (error) {
265+
CoreDomUtils.instance.showErrorModalDefault(error, 'core.errordownloading', true);
266+
}
267+
}
268+
247269
/**
248270
* Download athe H5P deployed file or restores an ongoing download.
249271
*
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2+
"downloadh5pfile": "Download H5P file",
23
"errorgetactivity": "Error getting H5P activity data.",
34
"filestatenotdownloaded": "The H5P package is not downloaded. You need to download it to be able to use it.",
45
"filestateoutdated": "The H5P package has been modified since the last download. You need to download it again to be able to use it.",
56
"modulenameplural": "H5P",
6-
"offlinedisabledwarning": "You will need to be online to view the H5P package.",
7-
"storingfiles": "Storing files"
7+
"offlinedisabledwarning": "You will need to be online to view the H5P package."
88
}

src/assets/lang/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,12 +659,12 @@
659659
"addon.mod_glossary.noentriesfound": "No entries were found.",
660660
"addon.mod_glossary.searchquery": "Search query",
661661
"addon.mod_glossary.tagarea_glossary_entries": "Glossary entries",
662+
"addon.mod_h5pactivity.downloadh5pfile": "Download H5P file",
662663
"addon.mod_h5pactivity.errorgetactivity": "Error getting H5P activity data.",
663664
"addon.mod_h5pactivity.filestatenotdownloaded": "The H5P package is not downloaded. You need to download it to be able to use it.",
664665
"addon.mod_h5pactivity.filestateoutdated": "The H5P package has been modified since the last download. You need to download it again to be able to use it.",
665666
"addon.mod_h5pactivity.modulenameplural": "H5P",
666667
"addon.mod_h5pactivity.offlinedisabledwarning": "You will need to be online to view the H5P package.",
667-
"addon.mod_h5pactivity.storingfiles": "Storing files",
668668
"addon.mod_imscp.deploymenterror": "Content package error!",
669669
"addon.mod_imscp.modulenameplural": "IMS content packages",
670670
"addon.mod_imscp.showmoduledescription": "Show description",
@@ -2041,6 +2041,7 @@
20412041
"core.sort": "Sort",
20422042
"core.sortby": "Sort by",
20432043
"core.start": "Start",
2044+
"core.storingfiles": "Storing files",
20442045
"core.strftimedate": "%d %B %Y",
20452046
"core.strftimedatefullshort": "%d/%m/%y",
20462047
"core.strftimedateshort": "%d %B",

src/core/h5p/classes/helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class CoreH5PHelper {
144144

145145
try {
146146
// Notify that the unzip is starting.
147-
onProgress && onProgress({message: 'addon.mod_h5pactivity.storingfiles'});
147+
onProgress && onProgress({message: 'core.storingfiles'});
148148

149149
// Read the contents of the unzipped dir, process them and store them.
150150
const contents = await CoreFile.instance.getDirectoryContents(destFolder);

src/core/h5p/classes/player.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ export class CoreH5PPlayer {
4040
* @return URL.
4141
*/
4242
calculateOnlinePlayerUrl(siteUrl: string, fileUrl: string, displayOptions?: CoreH5PDisplayOptions, component?: string): string {
43+
fileUrl = CoreH5P.instance.treatH5PUrl(fileUrl, siteUrl);
44+
4345
const params = this.getUrlParamsFromDisplayOptions(displayOptions);
44-
params.url = fileUrl;
46+
params.url = encodeURIComponent(fileUrl);
4547
if (component) {
4648
params.component = component;
4749
}

src/core/h5p/providers/h5p.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ export class CoreH5PProvider {
428428
* @param siteUrl Site URL.
429429
* @return Treated url.
430430
*/
431-
protected treatH5PUrl(url: string, siteUrl: string): string {
431+
treatH5PUrl(url: string, siteUrl: string): string {
432432
if (url.indexOf(CoreTextUtils.instance.concatenatePaths(siteUrl, '/webservice/pluginfile.php')) === 0) {
433433
url = url.replace('/webservice/pluginfile', '/pluginfile');
434434
}

src/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@
252252
"sort": "Sort",
253253
"sortby": "Sort by",
254254
"start": "Start",
255+
"storingfiles": "Storing files",
255256
"strftimedate": "%d %B %Y",
256257
"strftimedatefullshort": "%d/%m/%y",
257258
"strftimedateshort": "%d %B",

0 commit comments

Comments
 (0)