forked from CIT/Vmeda.Online
		
	MOBILE-3039 core: Don't allow disable sound in iOS and Android 8+
This commit is contained in:
		
							parent
							
								
									3a56fa0e80
								
							
						
					
					
						commit
						ed35e57e1c
					
				| @ -55,7 +55,8 @@ export class AddonNotificationsSettingsPage implements OnDestroy { | |||||||
|             @Optional() private svComponent: CoreSplitViewComponent) { |             @Optional() private svComponent: CoreSplitViewComponent) { | ||||||
| 
 | 
 | ||||||
|         this.notifPrefsEnabled = notificationsProvider.isNotificationPreferencesEnabled(); |         this.notifPrefsEnabled = notificationsProvider.isNotificationPreferencesEnabled(); | ||||||
|         this.canChangeSound = localNotificationsProvider.isAvailable() && !appProvider.isDesktop(); |         this.canChangeSound = localNotificationsProvider.canDisableSound(); | ||||||
|  | 
 | ||||||
|         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; | ||||||
|  | |||||||
| @ -246,7 +246,15 @@ export class CorePushNotificationsProvider { | |||||||
|      * @return {Promise<PushOptions>} Promise with the push options resolved when done. |      * @return {Promise<PushOptions>} Promise with the push options resolved when done. | ||||||
|      */ |      */ | ||||||
|     protected getOptions(): Promise<PushOptions> { |     protected getOptions(): Promise<PushOptions> { | ||||||
|         return this.configProvider.get(CoreConstants.SETTINGS_NOTIFICATION_SOUND, true).then((soundEnabled) => { |         let promise; | ||||||
|  | 
 | ||||||
|  |         if (this.localNotificationsProvider.canDisableSound()) { | ||||||
|  |             promise = this.configProvider.get(CoreConstants.SETTINGS_NOTIFICATION_SOUND, true); | ||||||
|  |         } else { | ||||||
|  |             promise = Promise.resolve(true); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return promise.then((soundEnabled) => { | ||||||
|             return { |             return { | ||||||
|                 android: { |                 android: { | ||||||
|                     sound: !!soundEnabled, |                     sound: !!soundEnabled, | ||||||
|  | |||||||
| @ -205,6 +205,17 @@ export class CoreLocalNotificationsProvider { | |||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Check whether sound can be disabled for notifications. | ||||||
|  |      * | ||||||
|  |      * @return {boolean} Whether sound can be disabled for notifications. | ||||||
|  |      */ | ||||||
|  |     canDisableSound(): boolean { | ||||||
|  |         // Only allow disabling sound in Android 7 or lower. In iOS and Android 8+ it can easily be done with system settings.
 | ||||||
|  |         return this.isAvailable() && !this.appProvider.isDesktop() && this.platform.is('android') && | ||||||
|  |                 this.platform.version().major < 8; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * Create the default channel. It is used to change the name. |      * Create the default channel. It is used to change the name. | ||||||
|      * |      * | ||||||
| @ -577,7 +588,15 @@ export class CoreLocalNotificationsProvider { | |||||||
|             return this.localNotifications.cancel(notification.id).finally(() => { |             return this.localNotifications.cancel(notification.id).finally(() => { | ||||||
|                 if (!triggered) { |                 if (!triggered) { | ||||||
|                     // Check if sound is enabled for notifications.
 |                     // Check if sound is enabled for notifications.
 | ||||||
|                     return this.configProvider.get(CoreConstants.SETTINGS_NOTIFICATION_SOUND, true).then((soundEnabled) => { |                     let promise; | ||||||
|  | 
 | ||||||
|  |                     if (this.canDisableSound()) { | ||||||
|  |                         promise = this.configProvider.get(CoreConstants.SETTINGS_NOTIFICATION_SOUND, true); | ||||||
|  |                     } else { | ||||||
|  |                         promise = Promise.resolve(true); | ||||||
|  |                     } | ||||||
|  | 
 | ||||||
|  |                     return promise.then((soundEnabled) => { | ||||||
|                         if (!soundEnabled) { |                         if (!soundEnabled) { | ||||||
|                             notification.sound = null; |                             notification.sound = null; | ||||||
|                         } else { |                         } else { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user