MOBILE-2404 config: Don't support booleans in config provider

main
Dani Palou 2018-05-30 11:38:38 +02:00
parent 1059781fdd
commit 6b45763095
5 changed files with 11 additions and 9 deletions

View File

@ -58,7 +58,7 @@ export class AddonNotificationsSettingsPage implements OnDestroy {
this.canChangeSound = localNotificationsProvider.isAvailable() && !appProvider.isDesktop(); this.canChangeSound = localNotificationsProvider.isAvailable() && !appProvider.isDesktop();
if (this.canChangeSound) { if (this.canChangeSound) {
configProvider.get(CoreConstants.SETTINGS_NOTIFICATION_SOUND, true).then((enabled) => { configProvider.get(CoreConstants.SETTINGS_NOTIFICATION_SOUND, true).then((enabled) => {
this.notificationSound = enabled; this.notificationSound = !!enabled;
}); });
} }
} }
@ -245,7 +245,7 @@ export class AddonNotificationsSettingsPage implements OnDestroy {
* @param {enabled} enabled True to enable the notification sound, false to disable it. * @param {enabled} enabled True to enable the notification sound, false to disable it.
*/ */
changeNotificationSound(enabled: boolean): void { changeNotificationSound(enabled: boolean): void {
this.configProvider.set(CoreConstants.SETTINGS_NOTIFICATION_SOUND, enabled).finally(() => { this.configProvider.set(CoreConstants.SETTINGS_NOTIFICATION_SOUND, enabled ? 1 : 0).finally(() => {
const siteId = this.sitesProvider.getCurrentSiteId(); const siteId = this.sitesProvider.getCurrentSiteId();
this.eventsProvider.trigger(CoreEventsProvider.NOTIFICATION_SOUND_CHANGED, {enabled}, siteId); this.eventsProvider.trigger(CoreEventsProvider.NOTIFICATION_SOUND_CHANGED, {enabled}, siteId);
this.localNotificationsProvider.rescheduleAll(); this.localNotificationsProvider.rescheduleAll();

View File

@ -56,7 +56,7 @@ export class CoreSettingsGeneralPage {
this.rteSupported = this.domUtils.isRichTextEditorSupported(); this.rteSupported = this.domUtils.isRichTextEditorSupported();
if (this.rteSupported) { if (this.rteSupported) {
this.configProvider.get(CoreConstants.SETTINGS_RICH_TEXT_EDITOR, true).then((richTextEditorEnabled) => { this.configProvider.get(CoreConstants.SETTINGS_RICH_TEXT_EDITOR, true).then((richTextEditorEnabled) => {
this.richTextEditor = richTextEditorEnabled; this.richTextEditor = !!richTextEditorEnabled;
}); });
} }
@ -81,7 +81,7 @@ export class CoreSettingsGeneralPage {
* Called when the rich text editor is enabled or disabled. * Called when the rich text editor is enabled or disabled.
*/ */
richTextEditorChanged(): void { richTextEditorChanged(): void {
this.configProvider.set(CoreConstants.SETTINGS_RICH_TEXT_EDITOR, this.richTextEditor); this.configProvider.set(CoreConstants.SETTINGS_RICH_TEXT_EDITOR, this.richTextEditor ? 1 : 0);
} }
/** /**

View File

@ -68,7 +68,7 @@ export class CoreSettingsSynchronizationPage implements OnDestroy {
}); });
this.configProvider.get(CoreConstants.SETTINGS_SYNC_ONLY_ON_WIFI, true).then((syncOnlyOnWifi) => { this.configProvider.get(CoreConstants.SETTINGS_SYNC_ONLY_ON_WIFI, true).then((syncOnlyOnWifi) => {
this.syncOnlyOnWifi = syncOnlyOnWifi; this.syncOnlyOnWifi = !!syncOnlyOnWifi;
}); });
} }
@ -76,7 +76,7 @@ export class CoreSettingsSynchronizationPage implements OnDestroy {
* Called when sync only on wifi setting is enabled or disabled. * Called when sync only on wifi setting is enabled or disabled.
*/ */
syncOnlyOnWifiChanged(): void { syncOnlyOnWifiChanged(): void {
this.configProvider.set(CoreConstants.SETTINGS_SYNC_ONLY_ON_WIFI, this.syncOnlyOnWifi); this.configProvider.set(CoreConstants.SETTINGS_SYNC_ONLY_ON_WIFI, this.syncOnlyOnWifi ? 1 : 0);
} }
/** /**

View File

@ -77,10 +77,10 @@ export class CoreConfigProvider {
* Set an app setting. * Set an app setting.
* *
* @param {string} name The config name. * @param {string} name The config name.
* @param {boolean|number|string} value The config value. Can only store primitive values, not objects. * @param {number|string} value The config value. Can only store number or strings.
* @return {Promise<any>} Promise resolved when done. * @return {Promise<any>} Promise resolved when done.
*/ */
set(name: string, value: boolean | number | string): Promise<any> { set(name: string, value: number | string): Promise<any> {
return this.appDB.insertRecord(this.TABLE_NAME, { name: name, value: value }); return this.appDB.insertRecord(this.TABLE_NAME, { name: name, value: value });
} }
} }

View File

@ -548,7 +548,9 @@ export class CoreDomUtilsProvider {
*/ */
isRichTextEditorEnabled(): Promise<boolean> { isRichTextEditorEnabled(): Promise<boolean> {
if (this.isRichTextEditorSupported()) { if (this.isRichTextEditorSupported()) {
return this.configProvider.get(CoreConstants.SETTINGS_RICH_TEXT_EDITOR, true); return this.configProvider.get(CoreConstants.SETTINGS_RICH_TEXT_EDITOR, true).then((enabled) => {
return !!enabled;
});
} }
return Promise.resolve(false); return Promise.resolve(false);