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

Unverified Commit 5e6de712 authored by Rafael Tonholo's avatar Rafael Tonholo
Browse files

feat(archive): add swipe action change swipe gesture when account is pop3

parent 2d4a3449
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ dependencies {
    api(projects.feature.notification)
    api(projects.mail.common)

    implementation(projects.core.common)
    implementation(projects.core.preference.api)

    implementation(projects.feature.mail.account.api)
+4 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package net.thunderbird.core.android.account

import com.fsck.k9.mail.ServerSettings
import net.thunderbird.core.android.account.AccountDefaultsProvider.Companion.NO_OPENPGP_KEY
import net.thunderbird.core.common.mail.Protocols
import net.thunderbird.feature.account.Account
import net.thunderbird.feature.account.AccountId
import net.thunderbird.feature.account.storage.profile.ProfileDto
@@ -144,4 +145,7 @@ data class LegacyAccountWrapper(
    fun hasOpenPgpKey(): Boolean {
        return openPgpKey != NO_OPENPGP_KEY
    }

    fun isIncomingServerPop3(): Boolean =
        incomingServerSettings.type == Protocols.POP3
}
+2 −0
Original line number Diff line number Diff line
@@ -1786,6 +1786,8 @@ class MessageListFragment :
                    setFlag(item, Flag.FLAGGED, !item.isStarred)
                }

                SwipeAction.Archive if item.accountWrapper.isIncomingServerPop3() -> Unit

                SwipeAction.Archive -> {
                    onArchive(item)
                }
+6 −5
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import android.view.View
import android.view.View.MeasureSpec
import android.widget.ImageView
import androidx.core.graphics.withTranslation
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import app.k9mail.ui.utils.itemtouchhelper.ItemTouchHelper
@@ -216,9 +217,9 @@ class MessageListSwipeCallback(
        swipeLayout.setBackgroundColor(backgroundColor)

        val icon = getIcon(swipeAction, item, swipeActionConfig)
        icon.setTint(foregroundColor)

        icon?.setTint(foregroundColor)
        swipeIcon.setImageDrawable(icon)
        swipeIcon.isVisible = icon != null

        val isSelected = adapter.isSelected(item)
        swipeText.text = getActionName(swipeAction, item, isSelected, swipeActionConfig)
@@ -255,7 +256,7 @@ class MessageListSwipeCallback(
        swipeAction: SwipeAction,
        item: MessageListItem,
        swipeActionConfig: SwipeActionConfig,
    ) = if (isToggled(swipeAction, item)) {
    ): Drawable? = if (isToggled(swipeAction, item)) {
        swipeActionConfig.iconToggled ?: error("action has no toggled icon")
    } else {
        swipeActionConfig.icon
@@ -336,7 +337,7 @@ class MessageListSwipeCallback(
            accounts.associate { account ->
                account.uuid to SwipeActionConfig(
                    colorRoles = resourceProvider.getActionColorRoles(swipeAction, account),
                    icon = resourceProvider.getActionIcon(swipeAction),
                    icon = resourceProvider.getActionIcon(swipeAction, account),
                    iconToggled = resourceProvider.getActionIconToggled(swipeAction),
                    actionName = resourceProvider.getActionName(swipeAction, account),
                    actionNameToggled = resourceProvider.getActionNameToggled(swipeAction),
@@ -373,7 +374,7 @@ interface MessageListSwipeListener {

private data class SwipeActionConfig(
    private val colorRoles: ColorRoles,
    val icon: Drawable,
    val icon: Drawable?,
    val iconToggled: Drawable? = null,
    val actionName: String,
    val actionNameToggled: String? = null,
+17 −15
Original line number Diff line number Diff line
@@ -16,19 +16,20 @@ import net.thunderbird.core.android.account.LegacyAccountWrapper

class SwipeResourceProvider(private val context: Context) {

    fun getActionIcon(action: SwipeAction): Drawable {
        return context.loadDrawable(
            when (action) {
    fun getActionIcon(action: SwipeAction, account: LegacyAccountWrapper): Drawable? {
        val drawableId = when (action) {
            SwipeAction.None -> error("action == SwipeAction.None")
            SwipeAction.ToggleSelection -> Icons.Outlined.CheckCircle
            SwipeAction.ToggleRead -> Icons.Outlined.MarkEmailRead
            SwipeAction.ToggleStar -> Icons.Filled.Star
            SwipeAction.Archive if account.isIncomingServerPop3() -> null
            SwipeAction.Archive -> Icons.Outlined.Archive
            SwipeAction.Delete -> Icons.Outlined.Delete
            SwipeAction.Spam -> Icons.Outlined.Report
            SwipeAction.Move -> Icons.Outlined.DriveFileMove
            },
        )
        }

        return drawableId?.let(context::loadDrawable)
    }

    fun getActionIconToggled(action: SwipeAction): Drawable? {
@@ -72,10 +73,11 @@ class SwipeResourceProvider(private val context: Context) {
                SwipeAction.ToggleSelection -> R.string.swipe_action_select
                SwipeAction.ToggleRead -> R.string.swipe_action_mark_as_read
                SwipeAction.ToggleStar -> R.string.swipe_action_add_star
                SwipeAction.Archive if account.hasArchiveFolder() ->
                SwipeAction.Archive if account.hasArchiveFolder() && !account.isIncomingServerPop3() ->
                    R.string.swipe_action_archive

                SwipeAction.Archive -> R.string.swipe_action_archive_folder_not_set
                SwipeAction.Archive if !account.isIncomingServerPop3() -> R.string.swipe_action_archive_folder_not_set
                SwipeAction.Archive -> R.string.swipe_action_change_swipe_gestures
                SwipeAction.Delete -> R.string.swipe_action_delete
                SwipeAction.Spam -> R.string.swipe_action_spam
                SwipeAction.Move -> R.string.swipe_action_move
Loading