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

Commit 8e71e902 authored by Michael Enoma's avatar Michael Enoma 👽
Browse files

Koin and String Fix

parent bc767079
Loading
Loading
Loading
Loading
Loading
+0 −158
Original line number Diff line number Diff line
package com.fsck.k9.notification

import android.app.Notification
import androidx.core.app.NotificationCompat
import com.fsck.k9.Account
import com.fsck.k9.K9

internal open class SingleMessageNotifications(
    notificationHelper: NotificationHelper,
    actionCreator: NotificationActionCreator,
    resourceProvider: NotificationResourceProvider
) : BaseNotifications(notificationHelper, actionCreator, resourceProvider) {

    fun buildSingleMessageNotification(account: Account, holder: NotificationHolder): Notification {
        val notificationId = holder.notificationId
        return createSingleMessageNotificationBuilder(account, holder, notificationId)
            .setNotificationSilent()
            .build()
    }

    fun createSingleMessageNotificationBuilder(
        account: Account,
        holder: NotificationHolder,
        notificationId: Int
    ): NotificationCompat.Builder {
        val content = holder.content
        val builder = createBigTextStyleNotification(account, holder, notificationId)

        val deletePendingIntent = actionCreator.createDismissMessagePendingIntent(
            context, content.messageReference, holder.notificationId
        )
        builder.setDeleteIntent(deletePendingIntent)
        addActions(builder, account, holder)
        return builder
    }

    private fun addActions(builder: NotificationCompat.Builder, account: Account, holder: NotificationHolder) {
        addDeviceActions(builder, holder)
        addWearActions(builder, account, holder)
    }

    private fun addDeviceActions(builder: NotificationCompat.Builder, holder: NotificationHolder) {
        addDeviceReplyAction(builder, holder)
        addDeviceMarkAsReadAction(builder, holder)
        addDeviceDeleteAction(builder, holder)
    }

    private fun addDeviceReplyAction(builder: NotificationCompat.Builder, holder: NotificationHolder) {
        val icon = resourceProvider.iconReply
        val title = resourceProvider.actionReply()
        val content = holder.content
        val messageReference = content.messageReference
        val replyToMessagePendingIntent =
            actionCreator.createReplyPendingIntent(messageReference, holder.notificationId)
        builder.addAction(icon, title, replyToMessagePendingIntent)
    }

    private fun addDeviceMarkAsReadAction(builder: NotificationCompat.Builder, holder: NotificationHolder) {
        val icon = resourceProvider.iconMarkAsRead
        val title = resourceProvider.actionMarkAsRead()
        val content = holder.content
        val notificationId = holder.notificationId
        val messageReference = content.messageReference
        val action = actionCreator.createMarkMessageAsReadPendingIntent(messageReference, notificationId)
        builder.addAction(icon, title, action)
    }

    private fun addDeviceDeleteAction(builder: NotificationCompat.Builder, holder: NotificationHolder) {
        if (!isDeleteActionEnabled()) {
            return
        }
        val icon = resourceProvider.iconDelete
        val title = resourceProvider.actionDelete()
        val content = holder.content
        val notificationId = holder.notificationId
        val messageReference = content.messageReference
        val action = actionCreator.createDeleteMessagePendingIntent(messageReference, notificationId)
        builder.addAction(icon, title, action)
    }

    private fun addWearActions(builder: NotificationCompat.Builder, account: Account, holder: NotificationHolder) {
        val wearableExtender = NotificationCompat.WearableExtender()
        addReplyAction(wearableExtender, holder)
        addMarkAsReadAction(wearableExtender, holder)
        if (isDeleteActionAvailableForWear()) {
            addDeleteAction(wearableExtender, holder)
        }
        if (isArchiveActionAvailableForWear(account)) {
            addArchiveAction(wearableExtender, holder)
        }
        if (isSpamActionAvailableForWear(account)) {
            addMarkAsSpamAction(wearableExtender, holder)
        }
        builder.extend(wearableExtender)
    }

    private fun addReplyAction(wearableExtender: NotificationCompat.WearableExtender, holder: NotificationHolder) {
        val icon = resourceProvider.wearIconReplyAll
        val title = resourceProvider.actionReply()
        val messageReference = holder.content.messageReference
        val notificationId = holder.notificationId
        val action = actionCreator.createReplyPendingIntent(messageReference, notificationId)
        val replyAction = NotificationCompat.Action.Builder(icon, title, action).build()
        wearableExtender.addAction(replyAction)
    }

    private fun addMarkAsReadAction(wearableExtender: NotificationCompat.WearableExtender, holder: NotificationHolder) {
        val icon = resourceProvider.wearIconMarkAsRead
        val title = resourceProvider.actionMarkAsRead()
        val messageReference = holder.content.messageReference
        val notificationId = holder.notificationId
        val action = actionCreator.createMarkMessageAsReadPendingIntent(messageReference, notificationId)
        val markAsReadAction = NotificationCompat.Action.Builder(icon, title, action).build()
        wearableExtender.addAction(markAsReadAction)
    }

    private fun addDeleteAction(wearableExtender: NotificationCompat.WearableExtender, holder: NotificationHolder) {
        val icon = resourceProvider.wearIconDelete
        val title = resourceProvider.actionDelete()
        val messageReference = holder.content.messageReference
        val notificationId = holder.notificationId
        val action = actionCreator.createDeleteMessagePendingIntent(messageReference, notificationId)
        val deleteAction = NotificationCompat.Action.Builder(icon, title, action).build()
        wearableExtender.addAction(deleteAction)
    }

    private fun addArchiveAction(wearableExtender: NotificationCompat.WearableExtender, holder: NotificationHolder) {
        val icon = resourceProvider.wearIconArchive
        val title = resourceProvider.actionArchive()
        val messageReference = holder.content.messageReference
        val notificationId = holder.notificationId
        val action = actionCreator.createArchiveMessagePendingIntent(messageReference, notificationId)
        val archiveAction = NotificationCompat.Action.Builder(icon, title, action).build()
        wearableExtender.addAction(archiveAction)
    }

    private fun addMarkAsSpamAction(wearableExtender: NotificationCompat.WearableExtender, holder: NotificationHolder) {
        val icon = resourceProvider.wearIconMarkAsSpam
        val title = resourceProvider.actionMarkAsSpam()
        val messageReference = holder.content.messageReference
        val notificationId = holder.notificationId
        val action = actionCreator.createMarkMessageAsSpamPendingIntent(messageReference, notificationId)
        val spamAction = NotificationCompat.Action.Builder(icon, title, action).build()
        wearableExtender.addAction(spamAction)
    }

    private fun isDeleteActionAvailableForWear(): Boolean {
        return isDeleteActionEnabled() && !K9.isConfirmDeleteFromNotification
    }

    private fun isArchiveActionAvailableForWear(account: Account): Boolean {
        return account.archiveFolderId != null
    }

    private fun isSpamActionAvailableForWear(account: Account): Boolean {
        return account.spamFolderId != null && !K9.isConfirmSpam
    }
}
+0 −232
Original line number Diff line number Diff line
package com.fsck.k9.notification

import android.app.Notification
import androidx.core.app.NotificationCompat
import com.fsck.k9.Account
import com.fsck.k9.K9
import com.fsck.k9.controller.MessagingController
import com.fsck.k9.notification.NotificationIds.getNewMailSummaryNotificationId

internal open class WearNotifications(
    notificationHelper: NotificationHelper,
    actionCreator: NotificationActionCreator,
    resourceProvider: NotificationResourceProvider
) : BaseNotifications(notificationHelper, actionCreator, resourceProvider) {
    fun buildStackedNotification(account: Account, holder: NotificationHolder): Notification {
        val notificationId = holder.notificationId
        val content = holder.content
        val builder = createBigTextStyleNotification(account, holder, notificationId)
        builder.setNotificationSilent()

        val deletePendingIntent = actionCreator.createDismissMessagePendingIntent(
            context, content.messageReference, holder.notificationId
        )
        builder.setDeleteIntent(deletePendingIntent)

        addActions(builder, account, holder)

        return builder.build()
    }

    fun addSummaryActions(builder: NotificationCompat.Builder, notificationData: NotificationData) {
        val wearableExtender = NotificationCompat.WearableExtender()

        addMarkAllAsReadAction(wearableExtender, notificationData)
        if (isDeleteActionAvailableForWear()) {
            addDeleteAllAction(wearableExtender, notificationData)
        }
        if (isArchiveActionAvailableForWear(notificationData.account)) {
            addArchiveAllAction(wearableExtender, notificationData)
        }
        builder.extend(wearableExtender)
    }

    private fun addMarkAllAsReadAction(
        wearableExtender: NotificationCompat.WearableExtender,
        notificationData: NotificationData
    ) {
        val icon = resourceProvider.wearIconMarkAsRead
        val title = resourceProvider.actionMarkAllAsRead()
        val account = notificationData.account
        val messageReferences = notificationData.getAllMessageReferences()
        val notificationId = getNewMailSummaryNotificationId(account)
        val action = actionCreator.createMarkAllAsReadPendingIntent(account, messageReferences, notificationId)
        val markAsReadAction = NotificationCompat.Action.Builder(icon, title, action).build()
        wearableExtender.addAction(markAsReadAction)
    }

    private fun addDeleteAllAction(
        wearableExtender: NotificationCompat.WearableExtender,
        notificationData: NotificationData
    ) {
        val icon = resourceProvider.wearIconDelete
        val title = resourceProvider.actionDeleteAll()
        val account = notificationData.account
        val messageReferences = notificationData.getAllMessageReferences()
        val notificationId = getNewMailSummaryNotificationId(account)
        val action = actionCreator.createDeleteAllPendingIntent(account, messageReferences, notificationId)
        val deleteAction = NotificationCompat.Action.Builder(icon, title, action).build()

        wearableExtender.addAction(deleteAction);
        wearableExtender.addAction(deleteAction)
    }

    private fun addArchiveAllAction(
        wearableExtender: NotificationCompat.WearableExtender,
        notificationData: NotificationData
    ) {
        val icon = resourceProvider.wearIconArchive
        val title = resourceProvider.actionArchiveAll()
        val account = notificationData.account
        val messageReferences = notificationData.getAllMessageReferences()
        val notificationId = getNewMailSummaryNotificationId(account)
        val action = actionCreator.createArchiveAllPendingIntent(account, messageReferences, notificationId)
        val archiveAction = NotificationCompat.Action.Builder(icon, title, action).build()

        wearableExtender.addAction(archiveAction)
    }

    private fun addActions(builder: NotificationCompat.Builder, account: Account, holder: NotificationHolder) {
        addDeviceActions(builder, holder)
        addWearActions(builder, account, holder)
    }

    private fun addDeviceActions(builder: NotificationCompat.Builder, holder: NotificationHolder) {
        addDeviceReplyAction(builder, holder)
        addDeviceMarkAsReadAction(builder, holder)
        addDeviceDeleteAction(builder, holder)
    }

    private fun addDeviceReplyAction(builder: NotificationCompat.Builder, holder: NotificationHolder) {
        val icon = resourceProvider.iconReply
        val title = resourceProvider.actionReply()
        val content = holder.content
        val messageReference = content.messageReference
        val replyToMessagePendingIntent =
            actionCreator.createReplyPendingIntent(messageReference, holder.notificationId)

        builder.addAction(icon, title, replyToMessagePendingIntent)
    }

    private fun addDeviceMarkAsReadAction(builder: NotificationCompat.Builder, holder: NotificationHolder) {
        val icon = resourceProvider.iconMarkAsRead
        val title = resourceProvider.actionMarkAsRead()
        val content = holder.content
        val notificationId = holder.notificationId
        val messageReference = content.messageReference
        val action = actionCreator.createMarkMessageAsReadPendingIntent(messageReference, notificationId)
        builder.addAction(icon, title, action)
    }

    private fun addDeviceDeleteAction(builder: NotificationCompat.Builder, holder: NotificationHolder) {
        if (!isDeleteActionEnabled()) {
            return
        }

        val icon = resourceProvider.iconDelete
        val title = resourceProvider.actionDelete()
        val content = holder.content
        val notificationId = holder.notificationId
        val messageReference = content.messageReference
        val action = actionCreator.createDeleteMessagePendingIntent(messageReference, notificationId)
        builder.addAction(icon, title, action)
    }

    private fun addWearActions(builder: NotificationCompat.Builder, account: Account, holder: NotificationHolder) {
        val wearableExtender = NotificationCompat.WearableExtender()

        addReplyAction(wearableExtender, holder)
        addMarkAsReadAction(wearableExtender, holder)
        if (isDeleteActionAvailableForWear()) {
            addDeleteAction(wearableExtender, holder)
        }

        if (isArchiveActionAvailableForWear(account)) {
            addArchiveAction(wearableExtender, holder)
        }

        if (isSpamActionAvailableForWear(account)) {
            addMarkAsSpamAction(wearableExtender, holder)
        }

        builder.extend(wearableExtender)
    }

    private fun addReplyAction(wearableExtender: NotificationCompat.WearableExtender, holder: NotificationHolder) {
        val icon = resourceProvider.wearIconReplyAll
        val title = resourceProvider.actionReply()
        val messageReference = holder.content.messageReference
        val notificationId = holder.notificationId
        val action = actionCreator.createReplyPendingIntent(messageReference, notificationId)
        val replyAction = NotificationCompat.Action.Builder(icon, title, action).build()
        wearableExtender.addAction(replyAction)
    }

    private fun addMarkAsReadAction(wearableExtender: NotificationCompat.WearableExtender, holder: NotificationHolder) {
        val icon = resourceProvider.wearIconMarkAsRead
        val title = resourceProvider.actionMarkAsRead()
        val messageReference = holder.content.messageReference
        val notificationId = holder.notificationId
        val action = actionCreator.createMarkMessageAsReadPendingIntent(messageReference, notificationId)
        val markAsReadAction = NotificationCompat.Action.Builder(icon, title, action).build()

        wearableExtender.addAction(markAsReadAction)
    }

    private fun addDeleteAction(wearableExtender: NotificationCompat.WearableExtender, holder: NotificationHolder) {
        val icon = resourceProvider.wearIconDelete
        val title = resourceProvider.actionDelete()
        val messageReference = holder.content.messageReference
        val notificationId = holder.notificationId
        val action = actionCreator.createDeleteMessagePendingIntent(messageReference, notificationId)
        val deleteAction = NotificationCompat.Action.Builder(icon, title, action).build()

        wearableExtender.addAction(deleteAction)
    }

    private fun addArchiveAction(wearableExtender: NotificationCompat.WearableExtender, holder: NotificationHolder) {
        val icon = resourceProvider.wearIconArchive
        val title = resourceProvider.actionArchive()
        val messageReference = holder.content.messageReference
        val notificationId = holder.notificationId
        val action = actionCreator.createArchiveMessagePendingIntent(messageReference, notificationId)
        val archiveAction = NotificationCompat.Action.Builder(icon, title, action).build()

        wearableExtender.addAction(archiveAction)
    }

    private fun addMarkAsSpamAction(wearableExtender: NotificationCompat.WearableExtender, holder: NotificationHolder) {
        val icon = resourceProvider.wearIconMarkAsSpam
        val title = resourceProvider.actionMarkAsSpam()
        val messageReference = holder.content.messageReference
        val notificationId = holder.notificationId
        val action = actionCreator.createMarkMessageAsSpamPendingIntent(messageReference, notificationId)
        val spamAction = NotificationCompat.Action.Builder(icon, title, action).build()

        wearableExtender.addAction(spamAction)
    }

    private fun isDeleteActionAvailableForWear(): Boolean {
        return isDeleteActionEnabled() && !K9.isConfirmDeleteFromNotification
    }

    private fun isArchiveActionAvailableForWear(account: Account): Boolean {
        return isMovePossible(account, account.archiveFolderId)
    }

    private fun isSpamActionAvailableForWear(account: Account): Boolean {
        return !K9.isConfirmSpam && isMovePossible(account, account.spamFolderId)
    }

    private fun isMovePossible(account: Account, destinationFolderId: Long?): Boolean {
        if (destinationFolderId == null) {
            return false
        }
        val controller = createMessagingController()
        return controller.isMoveCapable(account)
    }

    protected open fun createMessagingController(): MessagingController {
        return MessagingController.getInstance(context)
    }
}
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -710,6 +710,7 @@
    <string name="edit_identity_email_label">Email address</string>
    <string name="edit_identity_email_hint">(Required)</string>
    <string name="edit_identity_reply_to_hint">(Optional)</string>
    <string name="edit_identity_reply_to_label">Reply-to address</string>
    <string name="edit_identity_signature_label">Signature</string>
    <string name="edit_identity_signature_hint">(Optional)</string>

+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ dependencies {
    implementation "commons-io:commons-io:${versions.commonsIo}"
    implementation "androidx.annotation:annotation:${versions.androidxAnnotation}"
    implementation "com.jakewharton.timber:timber:${versions.timber}"
    implementation "org.koin:koin-android:${versions.koin}"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.kotlinCoroutines}"

    implementation "com.squareup.retrofit2:retrofit:${versions.retrofit}"