forked from GitHub-Mirror/riotX-android
Stop notification using preference when disabled
This commit is contained in:
parent
74099be316
commit
c01af6ac78
@ -38,6 +38,7 @@ import im.vector.riotredesign.features.notifications.NotifiableEventResolver
|
||||
import im.vector.riotredesign.features.notifications.NotifiableMessageEvent
|
||||
import im.vector.riotredesign.features.notifications.NotificationDrawerManager
|
||||
import im.vector.riotredesign.features.notifications.SimpleNotifiableEvent
|
||||
import im.vector.riotredesign.features.settings.PreferencesManager
|
||||
import org.koin.android.ext.android.inject
|
||||
import timber.log.Timber
|
||||
|
||||
@ -61,6 +62,11 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
|
||||
* @param message the message
|
||||
*/
|
||||
override fun onMessageReceived(message: RemoteMessage?) {
|
||||
if (!PreferencesManager.areNotificationEnabledForDevice(applicationContext)) {
|
||||
Timber.i("Notification are disabled for this device")
|
||||
return
|
||||
}
|
||||
|
||||
if (message == null || message.data == null) {
|
||||
Timber.e("## onMessageReceived() : received a null message or message with no data")
|
||||
return
|
||||
@ -91,7 +97,9 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
|
||||
if (refreshedToken == null) {
|
||||
Timber.w("onNewToken:received null token")
|
||||
} else {
|
||||
pusherManager.registerPusherWithFcmKey(refreshedToken)
|
||||
if (PreferencesManager.areNotificationEnabledForDevice(applicationContext)) {
|
||||
pusherManager.registerPusherWithFcmKey(refreshedToken)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,7 @@ import im.vector.riotredesign.features.notifications.PushRuleTriggerListener
|
||||
import im.vector.riotredesign.features.rageshake.VectorFileLogger
|
||||
import im.vector.riotredesign.features.rageshake.VectorUncaughtExceptionHandler
|
||||
import im.vector.riotredesign.features.roomdirectory.RoomDirectoryModule
|
||||
import im.vector.riotredesign.features.settings.PreferencesManager
|
||||
import im.vector.riotredesign.features.version.getVersion
|
||||
import im.vector.riotredesign.push.fcm.FcmHelper
|
||||
import org.koin.android.ext.android.get
|
||||
@ -137,11 +138,12 @@ class VectorApplication : Application() {
|
||||
} else {
|
||||
//TODO check if notifications are enabled for this device
|
||||
//We need to use alarm in this mode
|
||||
if (Matrix.getInstance().currentSession != null) {
|
||||
AlarmSyncBroadcastReceiver.scheduleAlarm(applicationContext, 4_000L)
|
||||
Timber.i("Alarm scheduled to restart service")
|
||||
if (PreferencesManager.areNotificationEnabledForDevice(applicationContext)) {
|
||||
if (Matrix.getInstance().currentSession != null) {
|
||||
AlarmSyncBroadcastReceiver.scheduleAlarm(applicationContext, 4_000L)
|
||||
Timber.i("Alarm scheduled to restart service")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ import im.vector.matrix.android.api.session.content.ContentUrlResolver
|
||||
import im.vector.riotredesign.BuildConfig
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.utils.SecretStoringUtils
|
||||
import im.vector.riotredesign.features.settings.PreferencesManager
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
@ -65,6 +66,10 @@ class NotificationDrawerManager(val context: Context,
|
||||
Events might be grouped and there might not be one notification per event!
|
||||
*/
|
||||
fun onNotifiableEventReceived(notifiableEvent: NotifiableEvent) {
|
||||
if (!PreferencesManager.areNotificationEnabledForDevice(context)) {
|
||||
Timber.i("Notification are disabled for this device")
|
||||
return
|
||||
}
|
||||
//If we support multi session, event list should be per userId
|
||||
//Currently only manage single session
|
||||
if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) {
|
||||
|
@ -35,7 +35,9 @@ class VectorSettingsNotificationPreferenceFragment : VectorPreferenceFragment()
|
||||
val switchPref = preference as SwitchPreference
|
||||
if (switchPref.isChecked) {
|
||||
FcmHelper.getFcmToken(requireContext())?.let {
|
||||
pushManager.registerPusherWithFcmKey(it)
|
||||
if (PreferencesManager.areNotificationEnabledForDevice(requireContext())) {
|
||||
pushManager.registerPusherWithFcmKey(it)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
FcmHelper.getFcmToken(requireContext())?.let {
|
||||
|
Loading…
Reference in New Issue
Block a user