Merge pull request #6000 from k9mail/fix_update_notification_preferences

Fix reading notification settings from `NotificationChannel`
This commit is contained in:
cketti 2022-04-06 15:59:45 +02:00 committed by GitHub
commit d6f218b3ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 20 deletions

View file

@ -18,17 +18,19 @@ class NotificationSettingsUpdater(
accountUuids
.mapNotNull { accountUuid -> preferences.getAccount(accountUuid) }
.forEach { account -> updateNotificationSettings(account) }
.forEach { account ->
updateNotificationSettings(account)
preferences.saveAccount(account)
}
}
@RequiresApi(Build.VERSION_CODES.O)
private fun updateNotificationSettings(account: Account) {
fun updateNotificationSettings(account: Account) {
val notificationConfiguration = notificationChannelManager.getNotificationConfiguration(account)
val notificationSettings = notificationConfigurationConverter.convert(account, notificationConfiguration)
if (notificationSettings != account.notificationSettings) {
account.updateNotificationSettings { notificationSettings }
preferences.saveAccount(account)
}
}
}

View file

@ -9,7 +9,7 @@ import com.fsck.k9.VibratePattern
class NotificationVibrationDecoder {
fun decode(isVibrationEnabled: Boolean, systemPattern: List<Long>?): NotificationVibration {
if (systemPattern == null || systemPattern.size < 2 || systemPattern.size % 2 != 0) {
return NotificationVibration.DEFAULT
return NotificationVibration(isVibrationEnabled, VibratePattern.Default, repeatCount = 1)
}
val systemPatternArray = systemPattern.toLongArray()

View file

@ -10,6 +10,7 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.widget.Toast
import androidx.core.content.getSystemService
import androidx.core.net.toUri
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
@ -28,8 +29,7 @@ import com.fsck.k9.mailstore.FolderType
import com.fsck.k9.mailstore.RemoteFolder
import com.fsck.k9.notification.NotificationChannelManager
import com.fsck.k9.notification.NotificationChannelManager.ChannelType
import com.fsck.k9.notification.NotificationLightDecoder
import com.fsck.k9.notification.NotificationVibrationDecoder
import com.fsck.k9.notification.NotificationSettingsUpdater
import com.fsck.k9.ui.R
import com.fsck.k9.ui.endtoend.AutocryptKeyTransferActivity
import com.fsck.k9.ui.settings.onClick
@ -52,8 +52,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), ConfirmationDialogFr
private val messagingController: MessagingController by inject()
private val accountRemover: BackgroundAccountRemover by inject()
private val notificationChannelManager: NotificationChannelManager by inject()
private val notificationLightDecoder: NotificationLightDecoder by inject()
private val notificationVibrationDecoder: NotificationVibrationDecoder by inject()
private val notificationSettingsUpdater: NotificationSettingsUpdater by inject()
private val vibrator by lazy { requireContext().getSystemService<Vibrator>() }
private lateinit var dataStore: AccountSettingsDataStore
@ -251,28 +250,21 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), ConfirmationDialogFr
@SuppressLint("NewApi")
private fun updateNotificationPreferences(account: Account) {
val notificationConfiguration = notificationChannelManager.getNotificationConfiguration(account)
notificationSettingsUpdater.updateNotificationSettings(account)
val notificationSettings = account.notificationSettings
notificationSoundPreference?.let { preference ->
preference.setNotificationSound(notificationConfiguration.sound)
preference.setNotificationSound(notificationSettings.ringtone?.toUri())
preference.isEnabled = true
}
notificationLightPreference?.let { preference ->
val notificationLightSetting = notificationLightDecoder.decode(
isBlinkLightsEnabled = notificationConfiguration.isBlinkLightsEnabled,
lightColor = notificationConfiguration.lightColor,
accountColor = account.chipColor
)
preference.value = notificationLightSetting.name
preference.value = notificationSettings.light.name
preference.isEnabled = true
}
notificationVibrationPreference?.let { preference ->
val notificationVibration = notificationVibrationDecoder.decode(
isVibrationEnabled = notificationConfiguration.isVibrationEnabled,
systemPattern = notificationConfiguration.vibrationPattern
)
val notificationVibration = notificationSettings.vibration
preference.setVibration(
isVibrationEnabled = notificationVibration.isEnabled,
vibratePattern = notificationVibration.pattern,