diff --git a/src/addons/storagemanager/pages/course-storage/course-storage.ts b/src/addons/storagemanager/pages/course-storage/course-storage.ts index 8b22a4fb4..3c3d001ef 100644 --- a/src/addons/storagemanager/pages/course-storage/course-storage.ts +++ b/src/addons/storagemanager/pages/course-storage/course-storage.ts @@ -482,9 +482,9 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { * Mark course as not downloaded. */ protected markCourseAsNotDownloaded(): void { - // @TODO This is a workaround that should be more specific solving MOBILE-3305. - // Also should take into account all modules are not downloaded. - // Check after MOBILE-3188 is integrated. + // @TODO In order to correctly check the status of the course we should check all module statuses. + // We are currently marking as not downloaded if size is 0 but we should take into account that + // resources without files can be downloaded and cached. CoreCourse.setCourseStatus(this.courseId, CoreConstants.NOT_DOWNLOADED); } @@ -506,7 +506,6 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { * Confirm and prefetch a section. If the section is "all sections", prefetch all the sections. * * @param section Section to download. - * @param refresh Refresh clicked (not used). */ async prefecthSection(section: AddonStorageManagerCourseSection): Promise { section.isCalculating = true; diff --git a/src/core/features/compile/services/compile.ts b/src/core/features/compile/services/compile.ts index 550a59994..fc93a3b82 100644 --- a/src/core/features/compile/services/compile.ts +++ b/src/core/features/compile/services/compile.ts @@ -94,6 +94,7 @@ import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/ import { CoreCourseResourcePrefetchHandlerBase } from '@features/course/classes/resource-prefetch-handler'; import { CoreGeolocationError, CoreGeolocationErrorReason } from '@services/geolocation'; import { CORE_ERRORS_CLASSES } from '@classes/errors/errors'; +import { CoreNetwork } from '@services/network'; // Import all core modules that define components, directives and pipes. import { CoreSharedModule } from '@/core/shared.module'; @@ -343,6 +344,7 @@ export class CoreCompileProvider { instance['CoreLoggerProvider'] = CoreLogger; instance['moment'] = moment; instance['Md5'] = Md5; + instance['Network'] = CoreNetwork.instance; instance['CoreSyncBaseProvider'] = CoreSyncBaseProvider; instance['CoreArray'] = CoreArray; instance['CoreComponentsRegistry'] = CoreComponentsRegistry; diff --git a/src/core/features/emulator/emulator.module.ts b/src/core/features/emulator/emulator.module.ts index 17538020d..4eedc99bb 100644 --- a/src/core/features/emulator/emulator.module.ts +++ b/src/core/features/emulator/emulator.module.ts @@ -82,7 +82,6 @@ import { GeolocationMock } from './services/geolocation'; import { InAppBrowserMock } from './services/inappbrowser'; import { MediaCaptureMock } from './services/media-capture'; import { ZipMock } from './services/zip'; -import { CoreNetworkService } from '@services/network'; /** * This module handles the emulation of Cordova plugins in browser and desktop. @@ -142,17 +141,12 @@ import { CoreNetworkService } from '@services/network'; }, Keyboard, LocalNotifications, - { - provide: Media, - deps: [], - useFactory: (): Media => new Media(), - }, + Media, { provide: MediaCapture, deps: [Platform], useFactory: (platform: Platform): MediaCapture => platform.is('cordova') ? new MediaCapture() : new MediaCaptureMock(), }, - CoreNetworkService, Push, QRScanner, SplashScreen, diff --git a/src/core/initializers/initialize-services.ts b/src/core/initializers/initialize-services.ts index 81aab20ed..521afe534 100644 --- a/src/core/initializers/initialize-services.ts +++ b/src/core/initializers/initialize-services.ts @@ -16,6 +16,7 @@ import { CoreConfig } from '@services/config'; import { CoreFilepool } from '@services/filepool'; import { CoreLang } from '@services/lang'; import { CoreLocalNotifications } from '@services/local-notifications'; +import { CoreNetwork } from '@services/network'; import { CoreSites } from '@services/sites'; import { CoreUpdateManager } from '@services/update-manager'; import { CoreTimeUtils } from '@services/utils/time'; @@ -27,6 +28,7 @@ export default async function(): Promise { CoreSites.initialize(), CoreLang.initialize(), CoreLocalNotifications.initialize(), + CoreNetwork.initialize(), CoreUpdateManager.initialize(), CoreTimeUtils.initialize(), ]); diff --git a/src/core/services/network.ts b/src/core/services/network.ts index d400f4fb0..d8a2f9a64 100644 --- a/src/core/services/network.ts +++ b/src/core/services/network.ts @@ -14,17 +14,15 @@ import { Injectable } from '@angular/core'; import { CorePlatform } from '@services/platform'; -import { Network as NetworkService } from '@ionic-native/network/ngx'; +import { Network } from '@ionic-native/network/ngx'; import { makeSingleton } from '@singletons'; import { Observable, Subject, merge } from 'rxjs'; -const Network = makeSingleton(NetworkService); - /** * Service to manage network connections. */ @Injectable({ providedIn: 'root' }) -export class CoreNetworkService extends NetworkService { +export class CoreNetworkService extends Network { type!: string; @@ -33,13 +31,14 @@ export class CoreNetworkService extends NetworkService { protected forceOffline = false; protected online = false; - constructor() { - super(); - + /** + * Initialize the service. + */ + initialize(): void { this.checkOnline(); if (CorePlatform.isMobile()) { - Network.onChange().subscribe(() => { + this.onChange().subscribe(() => { this.fireObservable(); }); } else { @@ -165,13 +164,13 @@ export class CoreNetworkService extends NetworkService { } const limited = [ - Network.Connection.CELL_2G, - Network.Connection.CELL_3G, - Network.Connection.CELL_4G, - Network.Connection.CELL, + this.Connection.CELL_2G, + this.Connection.CELL_3G, + this.Connection.CELL_4G, + this.Connection.CELL, ]; - return limited.indexOf(Network.type) > -1; + return limited.indexOf(this.type) > -1; } /** diff --git a/src/core/singletons/index.ts b/src/core/singletons/index.ts index 695442589..0ef9ac7fc 100644 --- a/src/core/singletons/index.ts +++ b/src/core/singletons/index.ts @@ -55,7 +55,6 @@ import { Keyboard as KeyboardService } from '@ionic-native/keyboard/ngx'; import { LocalNotifications as LocalNotificationsService } from '@ionic-native/local-notifications/ngx'; import { Media as MediaService } from '@ionic-native/media/ngx'; import { MediaCapture as MediaCaptureService } from '@ionic-native/media-capture/ngx'; -import { Network as NetworkService } from '@ionic-native/network/ngx'; import { Push as PushService } from '@ionic-native/push/ngx'; import { QRScanner as QRScannerService } from '@ionic-native/qr-scanner/ngx'; import { StatusBar as StatusBarService } from '@ionic-native/status-bar/ngx'; @@ -187,10 +186,6 @@ export const LocalNotifications = makeSingleton(LocalNotificationsService); export const Media = makeSingleton(MediaService); export const MediaCapture = makeSingleton(MediaCaptureService); export const NativeHttp = makeSingleton(HTTP); -/** - * @deprecated on 4.1 use CoreNetwork instead. - */ -export const Network = makeSingleton(NetworkService); export const Push = makeSingleton(PushService); export const QRScanner = makeSingleton(QRScannerService); export const StatusBar = makeSingleton(StatusBarService);