Rename class NotificationSetting to NotificationSettings

This commit is contained in:
cketti 2022-02-08 19:12:06 +01:00
parent f923da4487
commit b91c902247
10 changed files with 56 additions and 56 deletions

View file

@ -373,7 +373,7 @@ class Account(override val uuid: String) : BaseAccount {
}
@get:Synchronized
val notificationSetting = NotificationSetting()
val notificationSettings = NotificationSettings()
val displayName: String
get() = name ?: email

View file

@ -137,16 +137,16 @@ class AccountPreferenceSerializer(
showPictures = getEnumStringPref<ShowPictures>(storage, "$accountUuid.showPicturesEnum", ShowPictures.NEVER)
notificationSetting.isVibrateEnabled = storage.getBoolean("$accountUuid.vibrate", false)
notificationSetting.vibratePattern = storage.getInt("$accountUuid.vibratePattern", 0)
notificationSetting.vibrateTimes = storage.getInt("$accountUuid.vibrateTimes", 5)
notificationSetting.isRingEnabled = storage.getBoolean("$accountUuid.ring", true)
notificationSetting.ringtone = storage.getString(
notificationSettings.isVibrateEnabled = storage.getBoolean("$accountUuid.vibrate", false)
notificationSettings.vibratePattern = storage.getInt("$accountUuid.vibratePattern", 0)
notificationSettings.vibrateTimes = storage.getInt("$accountUuid.vibrateTimes", 5)
notificationSettings.isRingEnabled = storage.getBoolean("$accountUuid.ring", true)
notificationSettings.ringtone = storage.getString(
"$accountUuid.ringtone",
"content://settings/system/notification_sound"
)
notificationSetting.setLed(storage.getBoolean("$accountUuid.led", true))
notificationSetting.ledColor = storage.getInt("$accountUuid.ledColor", chipColor)
notificationSettings.setLed(storage.getBoolean("$accountUuid.led", true))
notificationSettings.ledColor = storage.getInt("$accountUuid.ledColor", chipColor)
folderDisplayMode = getEnumStringPref<FolderMode>(storage, "$accountUuid.folderDisplayMode", FolderMode.NOT_SECOND_CLASS)
@ -322,13 +322,13 @@ class AccountPreferenceSerializer(
editor.putBoolean("$accountUuid.markMessageAsReadOnDelete", isMarkMessageAsReadOnDelete)
editor.putBoolean("$accountUuid.alwaysShowCcBcc", isAlwaysShowCcBcc)
editor.putBoolean("$accountUuid.vibrate", notificationSetting.isVibrateEnabled)
editor.putInt("$accountUuid.vibratePattern", notificationSetting.vibratePattern)
editor.putInt("$accountUuid.vibrateTimes", notificationSetting.vibrateTimes)
editor.putBoolean("$accountUuid.ring", notificationSetting.isRingEnabled)
editor.putString("$accountUuid.ringtone", notificationSetting.ringtone)
editor.putBoolean("$accountUuid.led", notificationSetting.isLedEnabled)
editor.putInt("$accountUuid.ledColor", notificationSetting.ledColor)
editor.putBoolean("$accountUuid.vibrate", notificationSettings.isVibrateEnabled)
editor.putInt("$accountUuid.vibratePattern", notificationSettings.vibratePattern)
editor.putInt("$accountUuid.vibrateTimes", notificationSettings.vibrateTimes)
editor.putBoolean("$accountUuid.ring", notificationSettings.isRingEnabled)
editor.putString("$accountUuid.ringtone", notificationSettings.ringtone)
editor.putBoolean("$accountUuid.led", notificationSettings.isLedEnabled)
editor.putInt("$accountUuid.ledColor", notificationSettings.ledColor)
editor.putLong("$accountUuid.lastSyncTime", lastSyncTime)
editor.putLong("$accountUuid.lastFolderListRefreshTime", lastFolderListRefreshTime)
editor.putBoolean("$accountUuid.isFinishedSetup", isFinishedSetup)
@ -604,7 +604,7 @@ class AccountPreferenceSerializer(
)
identities.add(identity)
with(notificationSetting) {
with(notificationSettings) {
isVibrateEnabled = false
vibratePattern = 0
vibrateTimes = 5

View file

@ -3,7 +3,7 @@ package com.fsck.k9;
/**
* Describes how a notification should behave.
*/
public class NotificationSetting {
public class NotificationSettings {
private boolean ringEnabled;
private String ringtoneUri;

View file

@ -40,7 +40,7 @@ internal class BaseNotificationDataCreator {
}
private fun createNotificationAppearance(account: Account): NotificationAppearance {
return with(account.notificationSetting) {
return with(account.notificationSettings) {
val vibrationPattern = if (isVibrateEnabled) vibration else null
NotificationAppearance(ringtone, vibrationPattern, ledColor)
}

View file

@ -6,7 +6,7 @@ import android.app.NotificationManager
import android.os.Build
import androidx.annotation.RequiresApi
import com.fsck.k9.Account
import com.fsck.k9.NotificationSetting
import com.fsck.k9.NotificationSettings
import com.fsck.k9.Preferences
import java.util.concurrent.Executor
import timber.log.Timber
@ -165,7 +165,7 @@ class NotificationChannelManager(
val oldChannelId = getChannelIdFor(account, ChannelType.MESSAGES)
val oldNotificationChannel = notificationManager.getNotificationChannel(oldChannelId)
if (oldNotificationChannel.matches(account.notificationSetting)) {
if (oldNotificationChannel.matches(account.notificationSettings)) {
Timber.v("Not recreating NotificationChannel. The current one already matches the app's settings.")
return
}
@ -183,7 +183,7 @@ class NotificationChannelManager(
group = account.uuid
copyPropertiesFrom(oldNotificationChannel)
copyPropertiesFrom(account.notificationSetting)
copyPropertiesFrom(account.notificationSettings)
}
Timber.v("Recreating NotificationChannel(%s => %s)", oldChannelId, newChannelId)
@ -191,10 +191,10 @@ class NotificationChannelManager(
}
@RequiresApi(Build.VERSION_CODES.O)
private fun NotificationChannel.matches(notificationSetting: NotificationSetting): Boolean {
return lightColor == notificationSetting.ledColor &&
shouldVibrate() == notificationSetting.isVibrateEnabled &&
vibrationPattern.contentEquals(notificationSetting.vibration)
private fun NotificationChannel.matches(notificationSettings: NotificationSettings): Boolean {
return lightColor == notificationSettings.ledColor &&
shouldVibrate() == notificationSettings.isVibrateEnabled &&
vibrationPattern.contentEquals(notificationSettings.vibration)
}
@RequiresApi(Build.VERSION_CODES.O)
@ -211,10 +211,10 @@ class NotificationChannelManager(
}
@RequiresApi(Build.VERSION_CODES.O)
private fun NotificationChannel.copyPropertiesFrom(notificationSetting: NotificationSetting) {
lightColor = notificationSetting.ledColor
vibrationPattern = notificationSetting.vibration
enableVibration(notificationSetting.isVibrateEnabled)
private fun NotificationChannel.copyPropertiesFrom(notificationSettings: NotificationSettings) {
lightColor = notificationSettings.ledColor
vibrationPattern = notificationSettings.vibration
enableVibration(notificationSettings.isVibrateEnabled)
}
private val Account.messagesNotificationChannelSuffix: String

View file

@ -41,7 +41,7 @@ internal class SyncNotificationController(
builder = notificationBuilder,
ringtone = null,
vibrationPattern = null,
ledColor = account.notificationSetting.ledColor,
ledColor = account.notificationSettings.ledColor,
ledSpeed = NotificationHelper.NOTIFICATION_LED_BLINK_FAST,
ringAndVibrate = true
)
@ -88,7 +88,7 @@ internal class SyncNotificationController(
builder = notificationBuilder,
ringtone = null,
vibrationPattern = null,
ledColor = account.notificationSetting.ledColor,
ledColor = account.notificationSettings.ledColor,
ledSpeed = NotificationHelper.NOTIFICATION_LED_BLINK_FAST,
ringAndVibrate = true
)
@ -118,7 +118,7 @@ internal class SyncNotificationController(
builder = notificationBuilder,
ringtone = null,
vibrationPattern = null,
ledColor = account.notificationSetting.ledColor,
ledColor = account.notificationSettings.ledColor,
ledSpeed = NotificationHelper.NOTIFICATION_LED_BLINK_FAST,
ringAndVibrate = true
)

View file

@ -4,7 +4,7 @@ import com.fsck.k9.Account
import com.fsck.k9.Identity
import com.fsck.k9.K9
import com.fsck.k9.K9.LockScreenNotificationVisibility
import com.fsck.k9.NotificationSetting
import com.fsck.k9.NotificationSettings
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.mockito.kotlin.mock
@ -138,7 +138,7 @@ class BaseNotificationDataCreatorTest {
@Test
fun ringtone() {
account.notificationSetting.ringtone = "content://ringtone/1"
account.notificationSettings.ringtone = "content://ringtone/1"
val notificationData = createNotificationData()
val result = notificationDataCreator.createBaseNotificationData(notificationData)
@ -148,19 +148,19 @@ class BaseNotificationDataCreatorTest {
@Test
fun `vibration pattern`() {
account.notificationSetting.isVibrateEnabled = true
account.notificationSetting.vibratePattern = 3
account.notificationSetting.vibrateTimes = 2
account.notificationSettings.isVibrateEnabled = true
account.notificationSettings.vibratePattern = 3
account.notificationSettings.vibrateTimes = 2
val notificationData = createNotificationData()
val result = notificationDataCreator.createBaseNotificationData(notificationData)
assertThat(result.appearance.vibrationPattern).isEqualTo(NotificationSetting.getVibration(3, 2))
assertThat(result.appearance.vibrationPattern).isEqualTo(NotificationSettings.getVibration(3, 2))
}
@Test
fun `led color`() {
account.notificationSetting.ledColor = 0x00FF00
account.notificationSettings.ledColor = 0x00FF00
val notificationData = createNotificationData()
val result = notificationDataCreator.createBaseNotificationData(notificationData)

View file

@ -30,7 +30,7 @@ class AccountSettingsDataStore(
"account_notify" -> account.isNotifyNewMail
"account_notify_self" -> account.isNotifySelfNewMail
"account_notify_contacts_mail_only" -> account.isNotifyContactsMailOnly
"account_led" -> account.notificationSetting.isLedEnabled
"account_led" -> account.notificationSettings.isLedEnabled
"account_notify_sync" -> account.isNotifySync
"openpgp_hide_sign_only" -> account.isOpenPgpHideSignOnly
"openpgp_encrypt_subject" -> account.isOpenPgpEncryptSubject
@ -55,7 +55,7 @@ class AccountSettingsDataStore(
"account_notify" -> account.isNotifyNewMail = value
"account_notify_self" -> account.isNotifySelfNewMail = value
"account_notify_contacts_mail_only" -> account.isNotifyContactsMailOnly = value
"account_led" -> account.notificationSetting.setLed(value)
"account_led" -> account.notificationSettings.setLed(value)
"account_notify_sync" -> account.isNotifySync = value
"openpgp_hide_sign_only" -> account.isOpenPgpHideSignOnly = value
"openpgp_encrypt_subject" -> account.isOpenPgpEncryptSubject = value
@ -72,7 +72,7 @@ class AccountSettingsDataStore(
override fun getInt(key: String?, defValue: Int): Int {
return when (key) {
"chip_color" -> account.chipColor
"led_color" -> account.notificationSetting.ledColor
"led_color" -> account.notificationSettings.ledColor
else -> defValue
}
}
@ -134,7 +134,7 @@ class AccountSettingsDataStore(
"folder_notify_new_mail_mode" -> account.folderNotifyNewMailMode.name
"account_combined_vibration" -> getCombinedVibrationValue()
"account_remote_search_num_results" -> account.remoteSearchNumResults.toString()
"account_ringtone" -> account.notificationSetting.ringtone
"account_ringtone" -> account.notificationSettings.ringtone
else -> defValue
}
}
@ -178,7 +178,7 @@ class AccountSettingsDataStore(
"folder_notify_new_mail_mode" -> account.folderNotifyNewMailMode = Account.FolderMode.valueOf(value)
"account_combined_vibration" -> setCombinedVibrationValue(value)
"account_remote_search_num_results" -> account.remoteSearchNumResults = value.toInt()
"account_ringtone" -> with(account.notificationSetting) {
"account_ringtone" -> with(account.notificationSettings) {
isRingEnabled = true
ringtone = value
}
@ -189,8 +189,8 @@ class AccountSettingsDataStore(
}
private fun setNotificationLightColor(value: Int) {
if (account.notificationSetting.ledColor != value) {
account.notificationSetting.ledColor = value
if (account.notificationSettings.ledColor != value) {
account.notificationSettings.ledColor = value
notificationSettingsChanged = true
}
}
@ -245,17 +245,17 @@ class AccountSettingsDataStore(
private fun getCombinedVibrationValue(): String {
return VibrationPreference.encode(
isVibrationEnabled = account.notificationSetting.isVibrateEnabled,
vibrationPattern = account.notificationSetting.vibratePattern,
vibrationTimes = account.notificationSetting.vibrateTimes
isVibrationEnabled = account.notificationSettings.isVibrateEnabled,
vibrationPattern = account.notificationSettings.vibratePattern,
vibrationTimes = account.notificationSettings.vibrateTimes
)
}
private fun setCombinedVibrationValue(value: String) {
val (isVibrationEnabled, vibrationPattern, vibrationTimes) = VibrationPreference.decode(value)
account.notificationSetting.isVibrateEnabled = isVibrationEnabled
account.notificationSetting.vibratePattern = vibrationPattern
account.notificationSetting.vibrateTimes = vibrationTimes
account.notificationSettings.isVibrateEnabled = isVibrationEnabled
account.notificationSettings.vibratePattern = vibrationPattern
account.notificationSettings.vibrateTimes = vibrationTimes
notificationSettingsChanged = true
}
}

View file

@ -16,7 +16,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SwitchCompat
import androidx.core.content.getSystemService
import androidx.preference.PreferenceDialogFragmentCompat
import com.fsck.k9.NotificationSetting
import com.fsck.k9.NotificationSettings
import com.fsck.k9.ui.R
class VibrationDialogFragment : PreferenceDialogFragmentCompat() {
@ -78,7 +78,7 @@ class VibrationDialogFragment : PreferenceDialogFragmentCompat() {
private fun playVibration() {
val vibrationPattern = adapter.vibrationPattern
val vibrationTimes = adapter.vibrationTimes
val combinedPattern = NotificationSetting.getVibration(vibrationPattern, vibrationTimes)
val combinedPattern = NotificationSettings.getVibration(vibrationPattern, vibrationTimes)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val vibrationEffect = VibrationEffect.createWaveform(combinedPattern, -1)

View file

@ -5,7 +5,7 @@ import android.content.Context
import android.util.AttributeSet
import androidx.core.content.res.TypedArrayUtils
import androidx.preference.ListPreference
import com.fsck.k9.NotificationSetting
import com.fsck.k9.NotificationSettings
import com.fsck.k9.ui.R
import com.takisoft.preferencex.PreferenceFragmentCompat
@ -71,7 +71,7 @@ constructor(
val vibrationPattern = entryValues.asSequence()
.map { entryValue -> entryValue.toString().toInt() }
.firstOrNull { vibrationPattern ->
val testPattern = NotificationSetting.getVibration(vibrationPattern, vibrationTimes)
val testPattern = NotificationSettings.getVibration(vibrationPattern, vibrationTimes)
testPattern.contentEquals(combinedPatternArray)
} ?: DEFAULT_VIBRATION_PATTERN