Use the preference value to render the push notifications toggle

This commit is contained in:
Maxime NATUREL 2022-11-03 16:31:41 +01:00
parent 2941cfa329
commit 67d2a6faab
1 changed files with 16 additions and 22 deletions

View File

@ -120,31 +120,25 @@ class VectorSettingsNotificationPreferenceFragment :
(pref as SwitchPreference).isChecked = areNotifEnabledAtAccountLevel
}
findPreference<SwitchPreference>(VectorPreferences.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY)?.let {
pushersManager.getPusherForCurrentSession()?.let { pusher ->
it.isChecked = pusher.enabled
}
findPreference<SwitchPreference>(VectorPreferences.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY)
?.setTransactionalSwitchChangeListener(lifecycleScope) { isChecked ->
if (isChecked) {
enableNotificationsForCurrentSessionUseCase.execute(requireActivity())
it.setTransactionalSwitchChangeListener(lifecycleScope) { isChecked ->
if (isChecked) {
enableNotificationsForCurrentSessionUseCase.execute(requireActivity())
findPreference<VectorPreference>(VectorPreferences.SETTINGS_NOTIFICATION_METHOD_KEY)
?.summary = unifiedPushHelper.getCurrentDistributorName()
findPreference<VectorPreference>(VectorPreferences.SETTINGS_NOTIFICATION_METHOD_KEY)
?.summary = unifiedPushHelper.getCurrentDistributorName()
// TODO test with API 33
notificationPermissionManager.eventuallyRequestPermission(
requireActivity(),
postPermissionLauncher,
showRationale = false,
ignorePreference = true
)
} else {
disableNotificationsForCurrentSessionUseCase.execute()
notificationPermissionManager.eventuallyRevokePermission(requireActivity())
notificationPermissionManager.eventuallyRequestPermission(
requireActivity(),
postPermissionLauncher,
showRationale = false,
ignorePreference = true
)
} else {
disableNotificationsForCurrentSessionUseCase.execute()
notificationPermissionManager.eventuallyRevokePermission(requireActivity())
}
}
}
}
findPreference<VectorPreference>(VectorPreferences.SETTINGS_FDROID_BACKGROUND_SYNC_MODE)?.let {
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {