Skip to content

Commit

Permalink
Merge pull request #3959 from dpalou/MOBILE-4539
Browse files Browse the repository at this point in the history
Mobile 4539
  • Loading branch information
crazyserver authored Mar 11, 2024
2 parents 1c93299 + 054160f commit ebbfe03
Show file tree
Hide file tree
Showing 38 changed files with 442 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { IonSearchbar } from '@ionic/angular';
import { CoreNavigator } from '@services/navigator';
import { PageLoadWatcher } from '@classes/page-load-watcher';
import { PageLoadsManager } from '@classes/page-loads-manager';
import { DownloadStatus } from '@/core/constants';

const FILTER_PRIORITY: AddonBlockMyOverviewTimeFilters[] =
['all', 'inprogress', 'future', 'past', 'favourite', 'allincludinghidden', 'hidden'];
Expand All @@ -54,7 +55,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
prefetchCoursesData: CorePrefetchStatusInfo = {
icon: '',
statusTranslatable: 'core.loading',
status: '',
status: DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED,
loading: true,
};

Expand Down
4 changes: 2 additions & 2 deletions src/addons/mod/book/pages/contents/contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { CoreConstants } from '@/core/constants';
import { DownloadStatus } from '@/core/constants';
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { CoreError } from '@classes/errors/error';
import { CoreSwipeSlidesItemsManager } from '@classes/items-management/swipe-slides-items-manager';
Expand Down Expand Up @@ -180,7 +180,7 @@ export class AddonModBookContentsPage implements OnInit, OnDestroy {
// Get module status to determine if it needs to be downloaded.
const status = await CoreCourseModulePrefetchDelegate.getModuleStatus(module, this.courseId, undefined, refresh);

if (status !== CoreConstants.DOWNLOADED) {
if (status !== DownloadStatus.DOWNLOADED) {
// Download content. This function also loads module contents if needed.
try {
await CoreCourseModulePrefetchDelegate.downloadModule(module, this.courseId);
Expand Down
18 changes: 11 additions & 7 deletions src/addons/mod/h5pactivity/components/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import { Component, Optional, OnInit, OnDestroy, Output, EventEmitter } from '@angular/core';
import { IonContent } from '@ionic/angular';

import { CoreConstants } from '@/core/constants';
import { DownloadStatus } from '@/core/constants';
import { CoreSite } from '@classes/sites/site';
import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component';
import { CoreCourseContentsPage } from '@features/course/pages/contents/contents';
Expand Down Expand Up @@ -161,12 +161,16 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
);
}

if (!this.siteCanDownload || this.state == CoreConstants.DOWNLOADED) {
if (!this.siteCanDownload || this.state === DownloadStatus.DOWNLOADED) {
// Cannot download the file or already downloaded, play the package directly.
this.play();

} else if ((this.state == CoreConstants.NOT_DOWNLOADED || this.state == CoreConstants.OUTDATED) && CoreNetwork.isOnline() &&
this.deployedFile?.filesize && CoreFilepool.shouldDownload(this.deployedFile.filesize)) {
} else if (
(this.state == DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED || this.state == DownloadStatus.OUTDATED) &&
CoreNetwork.isOnline() &&
this.deployedFile?.filesize &&
CoreFilepool.shouldDownload(this.deployedFile.filesize)
) {
// Package is small, download it automatically. Don't block this function for this.
this.downloadAutomatically();
}
Expand Down Expand Up @@ -295,13 +299,13 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
* Displays some data based on the state of the main file.
*/
protected async showFileState(): Promise<void> {
if (this.state == CoreConstants.OUTDATED) {
if (this.state === DownloadStatus.OUTDATED) {
this.stateMessage = 'addon.mod_h5pactivity.filestateoutdated';
this.needsDownload = true;
} else if (this.state == CoreConstants.NOT_DOWNLOADED) {
} else if (this.state === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
this.stateMessage = 'addon.mod_h5pactivity.filestatenotdownloaded';
this.needsDownload = true;
} else if (this.state == CoreConstants.DOWNLOADING) {
} else if (this.state === DownloadStatus.DOWNLOADING) {
this.stateMessage = '';

if (!this.downloading) {
Expand Down
4 changes: 2 additions & 2 deletions src/addons/mod/h5pactivity/services/handlers/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { CoreConstants } from '@/core/constants';
import { DownloadStatus } from '@/core/constants';
import { Injectable } from '@angular/core';

import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler';
Expand Down Expand Up @@ -144,7 +144,7 @@ export class AddonModH5PActivityPrefetchHandlerService extends CoreCourseActivit
// If the file needs to be downloaded, delete the states because it means the package has changed or user deleted it.
const fileState = await CoreFilepool.getFileStateByUrl(siteId, CoreFileHelper.getFileUrl(deployedFile));

if (fileState !== CoreConstants.DOWNLOADED) {
if (fileState !== DownloadStatus.DOWNLOADED) {
await CoreUtils.ignoreErrors(CoreXAPIOffline.deleteStates(AddonModH5PActivityProvider.TRACK_COMPONENT, {
itemId: h5pActivity.context,
siteId,
Expand Down
4 changes: 2 additions & 2 deletions src/addons/mod/imscp/pages/view/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { CoreConstants } from '@/core/constants';
import { DownloadStatus } from '@/core/constants';
import { Component, OnInit } from '@angular/core';
import { CoreError } from '@classes/errors/error';
import { CoreNavigationBarItem } from '@components/navigation-bar/navigation-bar';
Expand Down Expand Up @@ -173,7 +173,7 @@ export class AddonModImscpViewPage implements OnInit {
// Get module status to determine if it needs to be downloaded.
const status = await CoreCourseModulePrefetchDelegate.getModuleStatus(module, this.courseId, undefined, refresh);

if (status !== CoreConstants.DOWNLOADED) {
if (status !== DownloadStatus.DOWNLOADED) {
// Download content. This function also loads module contents if needed.
try {
await CoreCourseModulePrefetchDelegate.downloadModule(module, this.courseId);
Expand Down
8 changes: 4 additions & 4 deletions src/addons/mod/lesson/components/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { CoreConstants } from '@/core/constants';
import { DownloadStatus, TDownloadStatus } from '@/core/constants';
import { Component, Input, ViewChild, ElementRef, OnInit, OnDestroy, Optional } from '@angular/core';

import { CoreTabsComponent } from '@components/tabs/tabs';
Expand Down Expand Up @@ -575,8 +575,8 @@ export class AddonModLessonIndexComponent extends CoreCourseModuleMainActivityCo
/**
* @inheritdoc
*/
protected showStatus(status: string): void {
this.showSpinner = status == CoreConstants.DOWNLOADING;
protected showStatus(status: TDownloadStatus): void {
this.showSpinner = status === DownloadStatus.DOWNLOADING;
}

/**
Expand All @@ -590,7 +590,7 @@ export class AddonModLessonIndexComponent extends CoreCourseModuleMainActivityCo
return;
}

if (!AddonModLesson.isLessonOffline(this.lesson) || this.currentStatus == CoreConstants.DOWNLOADED) {
if (!AddonModLesson.isLessonOffline(this.lesson) || this.currentStatus == DownloadStatus.DOWNLOADED) {
// Not downloadable or already downloaded, open it.
this.playLesson(continueLast);

Expand Down
10 changes: 5 additions & 5 deletions src/addons/mod/quiz/components/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { CoreConstants } from '@/core/constants';
import { DownloadStatus, TDownloadStatus } from '@/core/constants';
import { safeNumber, SafeNumber } from '@/core/utils/types';
import { Component, OnDestroy, OnInit, Optional } from '@angular/core';

Expand Down Expand Up @@ -141,7 +141,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp

// Quiz supports offline, check if it needs to be downloaded.
// If the site doesn't support check updates, always prefetch it because we cannot tell if there's something new.
const isDownloaded = this.currentStatus == CoreConstants.DOWNLOADED;
const isDownloaded = this.currentStatus === DownloadStatus.DOWNLOADED;

if (isDownloaded) {
// Already downloaded, open it.
Expand Down Expand Up @@ -543,10 +543,10 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
* @param status The current status.
* @param previousStatus The previous status. If not defined, there is no previous status.
*/
protected showStatus(status: string, previousStatus?: string): void {
this.showStatusSpinner = status == CoreConstants.DOWNLOADING;
protected showStatus(status: TDownloadStatus, previousStatus?: TDownloadStatus): void {
this.showStatusSpinner = status === DownloadStatus.DOWNLOADING;

if (status == CoreConstants.DOWNLOADED && previousStatus == CoreConstants.DOWNLOADING) {
if (status === DownloadStatus.DOWNLOADED && previousStatus === DownloadStatus.DOWNLOADING) {
// Quiz downloaded now, maybe a new attempt was created. Load content again.
this.showLoadingAndFetch();
}
Expand Down
6 changes: 3 additions & 3 deletions src/addons/mod/quiz/services/handlers/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { CoreConstants } from '@/core/constants';
import { DownloadStatus } from '@/core/constants';
import { isSafeNumber } from '@/core/utils/types';

import { Injectable } from '@angular/core';
Expand Down Expand Up @@ -604,15 +604,15 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
// Check the current status of the quiz.
const status = await CoreFilepool.getPackageStatus(options.siteId, this.component, quiz.coursemodule);

if (status === CoreConstants.NOT_DOWNLOADED) {
if (status === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
return;
}

// Quiz was downloaded, set the new status.
// If no attempts or last is finished we'll mark it as not downloaded to show download icon.
const lastAttempt = attempts[attempts.length - 1];
const isLastFinished = !lastAttempt || AddonModQuiz.isAttemptFinished(lastAttempt.state);
const newStatus = isLastFinished ? CoreConstants.NOT_DOWNLOADED : CoreConstants.DOWNLOADED;
const newStatus = isLastFinished ? DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED : DownloadStatus.DOWNLOADED;

await CoreFilepool.storePackageStatus(options.siteId, newStatus, this.component, quiz.coursemodule);
}
Expand Down
6 changes: 3 additions & 3 deletions src/addons/mod/resource/components/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { CoreConstants } from '@/core/constants';
import { DownloadStatus } from '@/core/constants';
import { Component, OnDestroy, OnInit, Optional } from '@angular/core';
import { CoreError } from '@classes/errors/error';
import { CoreCourseModuleMainResourceComponent } from '@features/course/classes/main-resource-component';
Expand Down Expand Up @@ -66,7 +66,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
timecreated = -1;
timemodified = -1;
isExternalFile = false;
outdatedStatus = CoreConstants.OUTDATED;
outdatedStatus = DownloadStatus.OUTDATED;

protected onlineObserver?: Subscription;

Expand Down Expand Up @@ -211,7 +211,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
downloadable = await AddonModResourceHelper.isMainFileDownloadable(this.module);

if (downloadable) {
if (this.currentStatus === CoreConstants.OUTDATED && !this.isOnline && !this.isExternalFile) {
if (this.currentStatus === DownloadStatus.OUTDATED && !this.isOnline && !this.isExternalFile) {
// Warn the user that the file isn't updated.
const alert = await CoreDomUtils.showAlert(
undefined,
Expand Down
6 changes: 3 additions & 3 deletions src/addons/mod/resource/services/handlers/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { CoreConstants, ModPurpose } from '@/core/constants';
import { CoreConstants, DownloadStatus, ModPurpose } from '@/core/constants';
import { Injectable, Type } from '@angular/core';
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
import { CoreCourse } from '@features/course/services/course';
Expand Down Expand Up @@ -76,7 +76,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
return;
}

handlerData.button.hidden = status !== CoreConstants.DOWNLOADED ||
handlerData.button.hidden = status !== DownloadStatus.DOWNLOADED ||
AddonModResourceHelper.isDisplayedInIframe(module);
};
handlerData.button = {
Expand Down Expand Up @@ -124,7 +124,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase

const status = await CoreCourseModulePrefetchDelegate.getModuleStatus(module, module.course);

return status !== CoreConstants.DOWNLOADED || AddonModResourceHelper.isDisplayedInIframe(module);
return status !== DownloadStatus.DOWNLOADED || AddonModResourceHelper.isDisplayedInIframe(module);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/addons/mod/resource/services/handlers/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { CoreConstants } from '@/core/constants';
import { DownloadStatus, TDownloadStatus } from '@/core/constants';
import { Injectable } from '@angular/core';
import { CoreCourseResourcePrefetchHandlerBase } from '@features/course/classes/resource-prefetch-handler';
import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course';
Expand All @@ -36,18 +36,18 @@ export class AddonModResourcePrefetchHandlerService extends CoreCourseResourcePr
/**
* @inheritdoc
*/
determineStatus(module: CoreCourseAnyModuleData, status: string): string {
if (status == CoreConstants.DOWNLOADED && module) {
determineStatus(module: CoreCourseAnyModuleData, status: TDownloadStatus): TDownloadStatus {
if (status === DownloadStatus.DOWNLOADED && module) {
// If the main file is an external file, always display the module as outdated.
if ('contentsinfo' in module && module.contentsinfo) {
if (module.contentsinfo.repositorytype) {
// It's an external file.
return CoreConstants.OUTDATED;
return DownloadStatus.OUTDATED;
}
} else if (module.contents) {
const mainFile = module.contents[0];
if (mainFile && mainFile.isexternalfile) {
return CoreConstants.OUTDATED;
return DownloadStatus.OUTDATED;
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/addons/mod/scorm/components/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { CoreConstants } from '@/core/constants';
import { DownloadStatus, TDownloadStatus } from '@/core/constants';
import { Component, Input, OnInit, Optional } from '@angular/core';
import { CoreError } from '@classes/errors/error';
import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component';
Expand Down Expand Up @@ -495,10 +495,10 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom
return;
}

const isOutdated = this.currentStatus === CoreConstants.OUTDATED;
const isOutdated = this.currentStatus === DownloadStatus.OUTDATED;
const scorm = this.scorm;

if (!isOutdated && this.currentStatus !== CoreConstants.NOT_DOWNLOADED) {
if (!isOutdated && this.currentStatus !== DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
// Already downloaded, open it.
this.openScorm(scoId, preview);

Expand Down Expand Up @@ -578,16 +578,16 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom
/**
* @inheritdoc
*/
protected async showStatus(status: string): Promise<void> {
protected async showStatus(status: TDownloadStatus): Promise<void> {

if (status === CoreConstants.OUTDATED && this.scorm) {
if (status === DownloadStatus.OUTDATED && this.scorm) {
// Only show the outdated message if the file should be downloaded.
const download = await AddonModScorm.shouldDownloadMainFile(this.scorm, true);

this.statusMessage = download ? 'addon.mod_scorm.scormstatusoutdated' : '';
} else if (status === CoreConstants.NOT_DOWNLOADED) {
} else if (status === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
this.statusMessage = 'addon.mod_scorm.scormstatusnotdownloaded';
} else if (status === CoreConstants.DOWNLOADING) {
} else if (status === DownloadStatus.DOWNLOADING) {
if (!this.downloading) {
// It's being downloaded right now but the view isn't tracking it. "Restore" the download.
this.downloadScormPackage();
Expand Down
6 changes: 3 additions & 3 deletions src/addons/mod/scorm/services/scorm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { CoreConstants } from '@/core/constants';
import { DownloadStatus } from '@/core/constants';
import { Injectable } from '@angular/core';
import { CoreError } from '@classes/errors/error';
import { CoreSite } from '@classes/sites/site';
Expand Down Expand Up @@ -1669,8 +1669,8 @@ export class AddonModScormProvider {
return false;
}

const isOutdated = data.status == CoreConstants.OUTDATED ||
(data.status == CoreConstants.DOWNLOADING && data.previous == CoreConstants.OUTDATED);
const isOutdated = data.status === DownloadStatus.OUTDATED ||
(data.status === DownloadStatus.DOWNLOADING && data.previous === DownloadStatus.OUTDATED);

// Package needs to be downloaded if it's not outdated (not downloaded) or if the hash has changed.
return !isOutdated || data.extra != scorm.sha1hash;
Expand Down
4 changes: 2 additions & 2 deletions src/addons/remotethemes/services/remotethemes-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { Injectable } from '@angular/core';
import { CoreConstants } from '@/core/constants';
import { DownloadStatus } from '@/core/constants';
import { CoreSitePublicConfigResponse } from '@classes/sites/unauthenticated-site';
import { CoreFile } from '@services/file';
import { CoreFilepool } from '@services/filepool';
Expand Down Expand Up @@ -124,7 +124,7 @@ export class AddonRemoteThemesHandlerService implements CoreStyleHandler {
// Check if the file is downloaded.
const state = await CoreFilepool.getFileStateByUrl(siteId, url);

if (state == CoreConstants.NOT_DOWNLOADED) {
if (state === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
// File not downloaded, URL has changed or first time. Delete downloaded CSS files.
await CoreFilepool.removeFilesByComponent(siteId, COMPONENT, 1);
}
Expand Down
Loading

0 comments on commit ebbfe03

Please sign in to comment.