Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update notification preferences when fragment is created #7469

Merged
merged 1 commit into from
Jan 3, 2024

Conversation

cketti
Copy link
Member

@cketti cketti commented Jan 2, 2024

Update notification preferences right away instead of waiting for it to happen in onResume().

The notification preferences were initially disabled and only enabled after the current state has been read from the NotificationChannel.

private fun updateNotificationPreferences(account: Account) {
notificationSettingsUpdater.updateNotificationSettings(account)
val notificationSettings = account.notificationSettings
notificationSoundPreference?.let { preference ->
preference.setNotificationSound(notificationSettings.ringtone?.toUri())
preference.isEnabled = true
}
notificationLightPreference?.let { preference ->
preference.value = notificationSettings.light.name
preference.isEnabled = true
}
notificationVibrationPreference?.let { preference ->
val notificationVibration = notificationSettings.vibration
preference.setVibration(
isVibrationEnabled = notificationVibration.isEnabled,
vibratePattern = notificationVibration.pattern,
vibrationTimes = notificationVibration.repeatCount,
)
preference.isEnabled = true
}
}

However, calling updateNotificationPreferences() is skipped when the user returns from setting the notification sound.

// Don't update the notification preferences when resuming after the user has selected a new notification sound
// via NotificationSoundPreference. Otherwise we race the background thread and might read data from the old
// NotificationChannel, overwriting the notification sound with the previous value.
notificationSoundPreference?.let { notificationSoundPreference ->
if (notificationSoundPreference.receivedActivityResultJustNow) {
notificationSoundPreference.receivedActivityResultJustNow = false
} else {
maybeUpdateNotificationPreferences(account)
}
}

This could lead to the notification preferences never being enabled when the activity was recreated while returning from the system screen to set a notification sound (see #7468).

Fixes #7468

@rezazarchi
Copy link
Contributor

I checked this pull request and tested it on my Galaxy phone and verified that the issue has been resolved. Thank you.

@cketti cketti requested a review from wmontwe January 2, 2024 20:13
Copy link
Member

@wmontwe wmontwe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cketti cketti merged commit c11ed93 into main Jan 3, 2024
2 checks passed
@cketti cketti deleted the fix_notification_preferences branch January 3, 2024 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ringtone settings gets disabled after rotating the device
3 participants