Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7b90b58 authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

Merge branch 'main' into 5445-Enable_openPGP_support_by_default

parents cf5ef30c 06e39f66
Loading
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -30,15 +30,7 @@ internal open class AuthenticationErrorNotificationController(
            .setStyle(NotificationCompat.BigTextStyle().bigText(text))
            .setPublicVersion(createLockScreenNotification(account))
            .setCategory(NotificationCompat.CATEGORY_ERROR)

        notificationHelper.configureNotification(
            builder = notificationBuilder,
            ringtone = null,
            vibrationPattern = null,
            ledColor = NotificationHelper.NOTIFICATION_LED_FAILURE_COLOR,
            ledSpeed = NotificationHelper.NOTIFICATION_LED_BLINK_FAST,
            ringAndVibrate = true
        )
            .setErrorAppearance()

        notificationManager.notify(notificationId, notificationBuilder.build())
    }
+1 −9
Original line number Diff line number Diff line
@@ -30,15 +30,7 @@ internal open class CertificateErrorNotificationController(
            .setStyle(NotificationCompat.BigTextStyle().bigText(text))
            .setPublicVersion(createLockScreenNotification(account))
            .setCategory(NotificationCompat.CATEGORY_ERROR)

        notificationHelper.configureNotification(
            builder = notificationBuilder,
            ringtone = null,
            vibrationPattern = null,
            ledColor = NotificationHelper.NOTIFICATION_LED_FAILURE_COLOR,
            ledSpeed = NotificationHelper.NOTIFICATION_LED_BLINK_FAST,
            ringAndVibrate = true
        )
            .setErrorAppearance()

        notificationManager.notify(notificationId, notificationBuilder.build())
    }
+17 −48
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ package com.fsck.k9.notification

import android.content.Context
import android.net.Uri
import android.text.TextUtils
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.fsck.k9.Account
@@ -13,47 +13,6 @@ class NotificationHelper(
    private val notificationManager: NotificationManagerCompat,
    private val channelUtils: NotificationChannelManager
) {
    fun configureNotification(
        builder: NotificationCompat.Builder,
        ringtone: String?,
        vibrationPattern: LongArray?,
        ledColor: Int?,
        ledSpeed: Int,
        ringAndVibrate: Boolean
    ) {

        if (K9.isQuietTime) {
            builder.setNotificationSilent()
            return
        }

        if (ringAndVibrate) {
            if (ringtone != null && !TextUtils.isEmpty(ringtone)) {
                builder.setSound(Uri.parse(ringtone))
            }

            if (vibrationPattern != null) {
                builder.setVibrate(vibrationPattern)
            }
        } else {
            builder.setNotificationSilent()
        }

        if (ledColor != null) {
            val ledOnMS: Int
            val ledOffMS: Int
            if (ledSpeed == NOTIFICATION_LED_BLINK_SLOW) {
                ledOnMS = NOTIFICATION_LED_ON_TIME
                ledOffMS = NOTIFICATION_LED_OFF_TIME
            } else {
                ledOnMS = NOTIFICATION_LED_FAST_ON_TIME
                ledOffMS = NOTIFICATION_LED_FAST_OFF_TIME
            }

            builder.setLights(ledColor, ledOnMS, ledOffMS)
        }
    }

    fun getContext(): Context {
        return context
    }
@@ -75,12 +34,22 @@ class NotificationHelper(
    companion object {
        internal const val NOTIFICATION_LED_ON_TIME = 500
        internal const val NOTIFICATION_LED_OFF_TIME = 2000
        private const val NOTIFICATION_LED_FAST_ON_TIME = 100
        private const val NOTIFICATION_LED_FAST_OFF_TIME = 100
        internal const val NOTIFICATION_LED_FAST_ON_TIME = 100
        internal const val NOTIFICATION_LED_FAST_OFF_TIME = 100

        internal const val NOTIFICATION_LED_FAILURE_COLOR = 0xFFFF0000L.toInt()
    }
}

internal fun NotificationCompat.Builder.setErrorAppearance(): NotificationCompat.Builder = apply {
    setSilent(true)

        internal const val NOTIFICATION_LED_BLINK_SLOW = 0
        internal const val NOTIFICATION_LED_BLINK_FAST = 1
        internal const val NOTIFICATION_LED_FAILURE_COLOR = -0x10000
    if (!K9.isQuietTime) {
        setLights(
            NotificationHelper.NOTIFICATION_LED_FAILURE_COLOR,
            NotificationHelper.NOTIFICATION_LED_FAST_ON_TIME,
            NotificationHelper.NOTIFICATION_LED_FAST_OFF_TIME
        )
    }
}

@@ -90,7 +59,7 @@ internal fun NotificationCompat.Builder.setAppearance(
): NotificationCompat.Builder = apply {
    if (silent) {
        setSilent(true)
    } else {
    } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        if (!appearance.ringtone.isNullOrEmpty()) {
            setSound(Uri.parse(appearance.ringtone))
        }
+5 −3
Original line number Diff line number Diff line
@@ -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)
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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()
Loading