Add create account use case

This commit is contained in:
Wolf-Martell Montwé 2023-06-27 18:59:35 +02:00
parent 1c142876d0
commit 32a8f23dc7
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
5 changed files with 53 additions and 0 deletions

View file

@ -3,6 +3,7 @@ package com.fsck.k9.account
import android.content.Context
import app.k9mail.feature.account.setup.domain.ExternalContract
import app.k9mail.feature.account.setup.domain.entity.Account
import com.fsck.k9.Account.FolderMode
import com.fsck.k9.Core
import com.fsck.k9.Preferences
import com.fsck.k9.mailstore.SpecialLocalFoldersCreator
@ -22,10 +23,23 @@ class AccountCreator(
newAccount.incomingServerSettings = account.incomingServerSettings
newAccount.outgoingServerSettings = account.outgoingServerSettings
newAccount.name = account.options.displayName
newAccount.senderName = account.options.accountName
if (account.options.emailSignature != null) {
newAccount.signature = account.options.emailSignature
}
newAccount.isNotifyNewMail = account.options.showNotification
newAccount.automaticCheckIntervalMinutes = account.options.checkFrequencyInMinutes
newAccount.displayCount = account.options.messageDisplayCount
newAccount.folderPushMode = FolderMode.ALL // TODO is this always ALL?
newAccount.deletePolicy = accountCreatorHelper.getDefaultDeletePolicy(newAccount.incomingServerSettings.type)
newAccount.chipColor = accountCreatorHelper.pickColor()
// TODO check this:
// DI.get(LocalKeyStoreManager.class)
// .deleteCertificate(mAccount, newHost, newPort, MailServerDirection.OUTGOING)
localFoldersCreator.createSpecialLocalFolders(newAccount)
newAccount.markSetupFinished()

View file

@ -21,6 +21,7 @@ import com.fsck.k9.activity.MessageList;
import com.fsck.k9.ui.R;
import com.fsck.k9.helper.Utility;
@Deprecated(since = "New account setup flow")
public class AccountSetupNames extends K9Activity implements OnClickListener {
private static final String EXTRA_ACCOUNT = "account";

View file

@ -18,6 +18,7 @@ import com.fsck.k9.ui.R;
import com.fsck.k9.ui.base.K9Activity;
@Deprecated(since = "New account setup flow")
public class AccountSetupOptions extends K9Activity implements OnClickListener {
private static final String EXTRA_ACCOUNT = "account";

View file

@ -2,6 +2,7 @@ package app.k9mail.feature.account.setup.domain
import app.k9mail.autodiscovery.api.AutoDiscoveryResult
import app.k9mail.core.common.domain.usecase.validation.ValidationResult
import app.k9mail.feature.account.setup.domain.entity.AccountOptions
import app.k9mail.feature.account.setup.domain.entity.IncomingProtocolType
import com.fsck.k9.mail.ServerSettings
import com.fsck.k9.mail.server.ServerSettingsValidationResult
@ -24,6 +25,15 @@ internal interface DomainContract {
suspend fun execute(settings: ServerSettings): ServerSettingsValidationResult
}
fun interface CreateAccount {
suspend fun execute(
emailAddress: String,
incomingServerSettings: ServerSettings,
outgoingServerSettings: ServerSettings,
options: AccountOptions,
): String
}
fun interface ValidateEmailAddress {
fun execute(emailAddress: String): ValidationResult
}

View file

@ -0,0 +1,27 @@
package app.k9mail.feature.account.setup.domain.usecase
import app.k9mail.feature.account.setup.domain.DomainContract.UseCase
import app.k9mail.feature.account.setup.domain.ExternalContract
import app.k9mail.feature.account.setup.domain.entity.Account
import app.k9mail.feature.account.setup.domain.entity.AccountOptions
import com.fsck.k9.mail.ServerSettings
class CreateAccount(
private val accountCreator: ExternalContract.AccountCreator,
) : UseCase.CreateAccount {
override suspend fun execute(
emailAddress: String,
incomingServerSettings: ServerSettings,
outgoingServerSettings: ServerSettings,
options: AccountOptions,
): String {
val account = Account(
emailAddress = emailAddress,
incomingServerSettings = incomingServerSettings,
outgoingServerSettings = outgoingServerSettings,
options = options,
)
return accountCreator.createAccount(account)
}
}