From a7f2016f9f230c61286d7e02c9cdd3ccf88cd697 Mon Sep 17 00:00:00 2001 From: Alfonso Salces Date: Tue, 17 May 2022 11:50:07 +0200 Subject: [PATCH] MOBILE-4074 configs: Add default zoom level --- moodle.config.json | 5 +++-- .../features/settings/pages/general/general.ts | 2 +- .../settings/services/settings-helper.ts | 10 +++++----- src/core/services/update-manager.ts | 18 ++++++++++++++++++ src/core/services/utils/dom.ts | 4 ++-- src/types/config.d.ts | 1 + upgrade.txt | 4 ++++ 7 files changed, 34 insertions(+), 10 deletions(-) diff --git a/moodle.config.json b/moodle.config.json index 02b2bbfba..17f6627ee 100644 --- a/moodle.config.json +++ b/moodle.config.json @@ -76,9 +76,10 @@ "password": "moodle" } }, + "defaultZoomLevel": "none", "zoomlevels": { - "normal": 100, - "low": 110, + "none": 100, + "medium": 110, "high": 120 }, "customurlscheme": "moodlemobile", diff --git a/src/core/features/settings/pages/general/general.ts b/src/core/features/settings/pages/general/general.ts index 9db912420..31ecf47e6 100644 --- a/src/core/features/settings/pages/general/general.ts +++ b/src/core/features/settings/pages/general/general.ts @@ -41,7 +41,7 @@ export class CoreSettingsGeneralPage { languages: { code: string; name: string }[] = []; selectedLanguage = ''; zoomLevels: { value: CoreZoomLevel; style: number; selected: boolean }[] = []; - selectedZoomLevel = CoreZoomLevel.NORMAL; + selectedZoomLevel = CoreZoomLevel.NONE; richTextEditor = true; debugDisplay = false; analyticsSupported = false; diff --git a/src/core/features/settings/services/settings-helper.ts b/src/core/features/settings/services/settings-helper.ts index 9f8a1d46a..dacb346ed 100644 --- a/src/core/features/settings/services/settings-helper.ts +++ b/src/core/features/settings/services/settings-helper.ts @@ -50,8 +50,8 @@ export const enum CoreColorScheme { * Constants to define zoom levels. */ export const enum CoreZoomLevel { - NORMAL = 'normal', - LOW = 'low', + NONE = 'none', + MEDIUM = 'medium', HIGH = 'high', } @@ -303,13 +303,13 @@ export class CoreSettingsHelperProvider { } // Reset the value to solve edge cases. - CoreConfig.set(CoreConstants.SETTINGS_ZOOM_LEVEL, CoreZoomLevel.NORMAL); + CoreConfig.set(CoreConstants.SETTINGS_ZOOM_LEVEL, CoreZoomLevel.NONE); if (fontSize < 100) { if (fontSize > 90) { CoreConfig.set(CoreConstants.SETTINGS_ZOOM_LEVEL, CoreZoomLevel.HIGH); } else if (fontSize > 70) { - CoreConfig.set(CoreConstants.SETTINGS_ZOOM_LEVEL, CoreZoomLevel.LOW); + CoreConfig.set(CoreConstants.SETTINGS_ZOOM_LEVEL, CoreZoomLevel.MEDIUM); } } @@ -326,7 +326,7 @@ export class CoreSettingsHelperProvider { * @return The saved zoom Level option. */ async getZoomLevel(): Promise { - return CoreConfig.get(CoreConstants.SETTINGS_ZOOM_LEVEL, CoreZoomLevel.NORMAL); + return CoreConfig.get(CoreConstants.SETTINGS_ZOOM_LEVEL, CoreConstants.CONFIG.defaultZoomLevel); } /** diff --git a/src/core/services/update-manager.ts b/src/core/services/update-manager.ts index e73e50fd6..3d1280923 100644 --- a/src/core/services/update-manager.ts +++ b/src/core/services/update-manager.ts @@ -23,6 +23,7 @@ import { CoreLoginHelper } from '@features/login/services/login-helper'; import { CoreSites } from './sites'; import { CoreUtils, PromiseDefer } from './utils/utils'; import { CoreApp } from './app'; +import { CoreZoomLevel } from '@features/settings/services/settings-helper'; const VERSION_APPLIED = 'version_applied'; @@ -71,6 +72,10 @@ export class CoreUpdateManagerProvider { promises.push(CoreH5P.h5pPlayer.deleteAllContentIndexes()); } + if (versionCode >= 41000 && versionApplied < 41000 && versionApplied > 0) { + promises.push(this.upgradeFontSizeNames()); + } + try { await Promise.all(promises); @@ -121,6 +126,19 @@ export class CoreUpdateManagerProvider { }); } + protected async upgradeFontSizeNames(): Promise { + const storedFontSizeName = await CoreConfig.get(CoreConstants.SETTINGS_ZOOM_LEVEL); + switch (storedFontSizeName) { + case 'low': + await CoreConfig.set(CoreConstants.SETTINGS_ZOOM_LEVEL, CoreZoomLevel.NONE); + break; + + case 'normal': + await CoreConfig.set(CoreConstants.SETTINGS_ZOOM_LEVEL, CoreZoomLevel.MEDIUM); + break; + } + } + } export const CoreUpdateManager = makeSingleton(CoreUpdateManagerProvider); diff --git a/src/core/services/utils/dom.ts b/src/core/services/utils/dom.ts index c6bbc23d4..e32d7d869 100644 --- a/src/core/services/utils/dom.ts +++ b/src/core/services/utils/dom.ts @@ -1792,12 +1792,12 @@ export class CoreDomUtilsProvider { const { waitForDismissCompleted, ...popoverOptions } = options; const popover = await PopoverController.create(popoverOptions); - const zoomLevel = await CoreConfig.get(CoreConstants.SETTINGS_ZOOM_LEVEL, CoreZoomLevel.NORMAL); + const zoomLevel = await CoreConfig.get(CoreConstants.SETTINGS_ZOOM_LEVEL, CoreConstants.CONFIG.defaultZoomLevel); await popover.present(); // Fix popover position if zoom is applied. - if (zoomLevel !== CoreZoomLevel.NORMAL) { + if (zoomLevel !== CoreZoomLevel.NONE) { switch (getMode()) { case 'ios': fixIOSPopoverPosition(popover, options.event); diff --git a/src/types/config.d.ts b/src/types/config.d.ts index 024c0dfb7..75c1e84f3 100644 --- a/src/types/config.d.ts +++ b/src/types/config.d.ts @@ -39,6 +39,7 @@ export interface EnvironmentConfig { wsservice: string; demo_sites: Record; zoomlevels: Record; + defaultZoomLevel?: CoreZoomLevel; // Set the default zoom level of the app. customurlscheme: string; siteurl: string; sitename: string; diff --git a/upgrade.txt b/upgrade.txt index b146617fb..ead37e419 100644 --- a/upgrade.txt +++ b/upgrade.txt @@ -1,6 +1,10 @@ This files describes API changes in the Moodle Mobile app, information provided here is intended especially for developers. +=== 4.0.1 === + +- Zoom levels changed from "normal / low / high" to " none / medium / high". + === 4.0.0 === - The versioncode in moodle.config.json has changed from 4 digits to 5 digits to match the actual value for the stores: the 4.0.0 version's versioncode is now 40000 instead of 4000. If you maintain a Moodle plugin with mobile support and you use the versioncode that is sent in every request, you might need to check if this change will affect your code.