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

Commit 05cff337 authored by cketti's avatar cketti
Browse files

Refactor `DeletePolicyHelper` into interface and implementation

parent 58c566ac
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ class AccountCreator(
    private val preferences: Preferences,
    private val context: Context,
    private val messagingController: MessagingController,
    private val deletePolicyProvider: DeletePolicyProvider,
    private val coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO,
) : AccountSetupExternalContract.AccountCreator {

@@ -67,7 +68,7 @@ class AccountCreator(
        newAccount.automaticCheckIntervalMinutes = account.options.checkFrequencyInMinutes
        newAccount.displayCount = account.options.messageDisplayCount

        newAccount.deletePolicy = DeletePolicyHelper.getDefaultDeletePolicy(newAccount.incomingServerSettings.type)
        newAccount.deletePolicy = deletePolicyProvider.getDeletePolicy(newAccount.incomingServerSettings.type)
        newAccount.chipColor = accountColorPicker.pickColor()

        localFoldersCreator.createSpecialLocalFolders(newAccount)
+3 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ val newAccountModule = module {
            localFoldersCreator = get(),
            preferences = get(),
            context = androidApplication(),
            deletePolicyProvider = get(),
            messagingController = get(),
        )
    }
@@ -50,4 +51,6 @@ val newAccountModule = module {
            messagingController = get(),
        )
    }

    factory<DeletePolicyProvider> { DefaultDeletePolicyProvider() }
}
+15 −0
Original line number Diff line number Diff line
package com.fsck.k9.account

import app.k9mail.core.common.mail.Protocols
import app.k9mail.legacy.account.Account.DeletePolicy

class DefaultDeletePolicyProvider : DeletePolicyProvider {
    override fun getDeletePolicy(accountType: String): DeletePolicy {
        return when (accountType) {
            Protocols.IMAP -> DeletePolicy.ON_DELETE
            Protocols.POP3 -> DeletePolicy.NEVER
            "demo" -> DeletePolicy.ON_DELETE
            else -> throw AssertionError("Unhandled case: $accountType")
        }
    }
}
+0 −15
Original line number Diff line number Diff line
package com.fsck.k9.account

import app.k9mail.core.common.mail.Protocols
import app.k9mail.legacy.account.Account

object DeletePolicyHelper {
    fun getDefaultDeletePolicy(type: String): Account.DeletePolicy {
        return when (type) {
            Protocols.IMAP -> Account.DeletePolicy.ON_DELETE
            Protocols.POP3 -> Account.DeletePolicy.NEVER
            "demo" -> Account.DeletePolicy.ON_DELETE
            else -> throw AssertionError("Unhandled case: $type")
        }
    }
}
+16 −0
Original line number Diff line number Diff line
package com.fsck.k9.account

import app.k9mail.core.common.mail.Protocols
import app.k9mail.legacy.account.Account.DeletePolicy

/**
 * Decides which [DeletePolicy] an account uses by default.
 */
interface DeletePolicyProvider {
    /**
     * Returns the [DeletePolicy] an account of type [accountType] should use by default.
     *
     * @param accountType The protocol identifier of the incoming server of an account. See [Protocols].
     */
    fun getDeletePolicy(accountType: String): DeletePolicy
}
Loading