Add create account use case
This commit is contained in:
parent
1c142876d0
commit
32a8f23dc7
5 changed files with 53 additions and 0 deletions
|
@ -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()
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue