diff --git a/scripts/langindex.json b/scripts/langindex.json index 92ad0f979..15958c458 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -68,6 +68,7 @@ "addon.blog.siteblogheading": "blog", "addon.calendar.calendar": "calendar", "addon.calendar.calendarevents": "local_moodlemobileapp", + "addon.calendar.calendarreminders": "local_moodlemobileapp", "addon.calendar.defaultnotificationtime": "local_moodlemobileapp", "addon.calendar.errorloadevent": "local_moodlemobileapp", "addon.calendar.errorloadevents": "local_moodlemobileapp", @@ -1506,6 +1507,7 @@ "core.maxsizeandattachments": "moodle", "core.min": "moodle", "core.mins": "moodle", + "core.misc": "admin", "core.mod_assign": "assign/pluginname", "core.mod_assignment": "assignment/pluginname", "core.mod_book": "book/pluginname", diff --git a/src/addon/calendar/lang/en.json b/src/addon/calendar/lang/en.json index 1fc6d2e34..6ccb04caa 100644 --- a/src/addon/calendar/lang/en.json +++ b/src/addon/calendar/lang/en.json @@ -1,6 +1,7 @@ { "calendar": "Calendar", "calendarevents": "Calendar events", + "calendarreminders": "Calendar reminders", "defaultnotificationtime": "Default notification time", "errorloadevent": "Error loading event.", "errorloadevents": "Error loading events.", diff --git a/src/addon/pushnotifications/providers/pushnotifications.ts b/src/addon/pushnotifications/providers/pushnotifications.ts index 6cd40d65b..63944830c 100644 --- a/src/addon/pushnotifications/providers/pushnotifications.ts +++ b/src/addon/pushnotifications/providers/pushnotifications.ts @@ -13,9 +13,11 @@ // limitations under the License. import { Injectable, NgZone } from '@angular/core'; +import { Platform } from 'ionic-angular'; import { Badge } from '@ionic-native/badge'; import { Push, PushObject, PushOptions } from '@ionic-native/push'; import { Device } from '@ionic-native/device'; +import { TranslateService } from '@ngx-translate/core'; import { CoreAppProvider } from '@providers/app'; import { CoreInitDelegate } from '@providers/init'; import { CoreLoggerProvider } from '@providers/logger'; @@ -67,10 +69,21 @@ export class AddonPushNotificationsProvider { protected pushNotificationsDelegate: AddonPushNotificationsDelegate, protected sitesProvider: CoreSitesProvider, private badge: Badge, private localNotificationsProvider: CoreLocalNotificationsProvider, private utils: CoreUtilsProvider, private textUtils: CoreTextUtilsProvider, private push: Push, - private configProvider: CoreConfigProvider, private device: Device, private zone: NgZone) { + private configProvider: CoreConfigProvider, private device: Device, private zone: NgZone, + private translate: TranslateService, private platform: Platform) { this.logger = logger.getInstance('AddonPushNotificationsProvider'); this.appDB = appProvider.getDB(); this.appDB.createTablesFromSchema(this.tablesSchema); + + platform.ready().then(() => { + // Create the default channel. + this.createDefaultChannel(); + + translate.onLangChange.subscribe((event: any) => { + // Update the channel name. + this.createDefaultChannel(); + }); + }); } /** @@ -85,6 +98,25 @@ export class AddonPushNotificationsProvider { }); } + /** + * Create the default push channel. It is used to change the name. + * + * @return {Promise} Promise resolved when done. + */ + protected createDefaultChannel(): Promise { + if (!this.platform.is('android')) { + return Promise.resolve(); + } + + return this.push.createChannel({ + id: 'PushPluginChannel', + description: this.translate.instant('core.misc'), + importance: 4 + }).catch((error) => { + this.logger.error('Error changing push channel name', error); + }); + } + /** * Returns options for push notifications based on device. * @@ -155,13 +187,7 @@ export class AddonPushNotificationsProvider { if (this.localNotificationsProvider.isAvailable()) { const localNotif: ILocalNotification = { id: 1, - trigger: { - at: new Date() - }, - data: { - notif: data.notif, - site: data.site - }, + data: data, title: '', text: '' }, @@ -193,9 +219,6 @@ export class AddonPushNotificationsProvider { }); } else { // The notification was clicked. - // For compatibility with old push plugin implementation we'll merge all the notification data in a single object. - data.title = notification.title; - data.message = notification.message; this.notificationClicked(data); } }); diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 0731749b0..1ce4bc648 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -68,6 +68,7 @@ "addon.blog.siteblogheading": "Site blog", "addon.calendar.calendar": "Calendar", "addon.calendar.calendarevents": "Calendar events", + "addon.calendar.calendarreminders": "Calendar reminders", "addon.calendar.defaultnotificationtime": "Default notification time", "addon.calendar.errorloadevent": "Error loading event.", "addon.calendar.errorloadevents": "Error loading events.", @@ -1506,6 +1507,7 @@ "core.maxsizeandattachments": "Maximum size for new files: {{$a.size}}, maximum attachments: {{$a.attachments}}", "core.min": "min", "core.mins": "mins", + "core.misc": "Miscellaneous", "core.mod_assign": "Assignment", "core.mod_assignment": "Assignment 2.2 (Disabled)", "core.mod_book": "Book", diff --git a/src/lang/en.json b/src/lang/en.json index 65c423bd1..7b7086f67 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -126,6 +126,7 @@ "maxsizeandattachments": "Maximum size for new files: {{$a.size}}, maximum attachments: {{$a.attachments}}", "min": "min", "mins": "mins", + "misc": "Miscellaneous", "mod_assign": "Assignment", "mod_assignment": "Assignment 2.2 (Disabled)", "mod_book": "Book", diff --git a/src/providers/local-notifications.ts b/src/providers/local-notifications.ts index 40cfc3926..03b2995b7 100644 --- a/src/providers/local-notifications.ts +++ b/src/providers/local-notifications.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { Platform, Alert, AlertController } from 'ionic-angular'; import { LocalNotifications, ILocalNotification } from '@ionic-native/local-notifications'; +import { Push } from '@ionic-native/push'; import { TranslateService } from '@ngx-translate/core'; import { CoreAppProvider } from './app'; import { CoreConfigProvider } from './config'; @@ -104,7 +105,7 @@ export class CoreLocalNotificationsProvider { constructor(logger: CoreLoggerProvider, private localNotifications: LocalNotifications, private platform: Platform, private appProvider: CoreAppProvider, private utils: CoreUtilsProvider, private configProvider: CoreConfigProvider, private textUtils: CoreTextUtilsProvider, private translate: TranslateService, private alertCtrl: AlertController, - eventsProvider: CoreEventsProvider) { + eventsProvider: CoreEventsProvider, private push: Push) { this.logger = logger.getInstance('CoreLocalNotificationsProvider'); this.appDB = appProvider.getDB(); @@ -122,6 +123,14 @@ export class CoreLocalNotificationsProvider { this.notifyClick(notification.data); } }); + + // Create the default channel for local notifications. + this.createDefaultChannel(); + + translate.onLangChange.subscribe((event: any) => { + // Update the channel name. + this.createDefaultChannel(); + }); }); eventsProvider.on(CoreEventsProvider.SITE_DELETED, (site) => { @@ -176,6 +185,21 @@ export class CoreLocalNotificationsProvider { }); } + /** + * Create the default channel. It is used to change the name. + * + * @return {Promise} Promise resolved when done. + */ + protected createDefaultChannel(): Promise { + return this.push.createChannel({ + id: 'default-channel-id', + description: this.translate.instant('addon.calendar.calendarreminders'), + importance: 4 + }).catch((error) => { + this.logger.error('Error changing channel name', error); + }); + } + /** * Get a code to create unique notifications. If there's no code assigned, create a new one. *