Change AccountState
to use display and sync options
This commit is contained in:
parent
c50314ffbe
commit
38a1be4f07
24 changed files with 153 additions and 143 deletions
|
@ -2,7 +2,10 @@ package app.k9mail.feature.preview.account
|
|||
|
||||
import app.k9mail.feature.account.common.AccountCommonExternalContract.AccountStateLoader
|
||||
import app.k9mail.feature.account.common.domain.entity.Account
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountState
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountSyncOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
|
||||
import app.k9mail.feature.account.edit.AccountEditExternalContract.AccountServerSettingsUpdater
|
||||
import app.k9mail.feature.account.edit.AccountEditExternalContract.AccountUpdaterFailure
|
||||
|
@ -59,7 +62,24 @@ class InMemoryAccountStore(
|
|||
incomingServerSettings = account.incomingServerSettings,
|
||||
outgoingServerSettings = account.outgoingServerSettings,
|
||||
authorizationState = account.authorizationState?.let { AuthorizationState(it) },
|
||||
options = account.options,
|
||||
displayOptions = mapToDisplayOptions(account.options),
|
||||
syncOptions = mapToSyncOptions(account.options),
|
||||
)
|
||||
}
|
||||
|
||||
private fun mapToDisplayOptions(options: AccountOptions): AccountDisplayOptions {
|
||||
return AccountDisplayOptions(
|
||||
accountName = options.accountName,
|
||||
displayName = options.displayName,
|
||||
emailSignature = options.emailSignature,
|
||||
)
|
||||
}
|
||||
|
||||
private fun mapToSyncOptions(options: AccountOptions): AccountSyncOptions {
|
||||
return AccountSyncOptions(
|
||||
checkFrequencyInMinutes = options.checkFrequencyInMinutes,
|
||||
messageDisplayCount = options.messageDisplayCount,
|
||||
showNotification = options.showNotification,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package app.k9mail.feature.account.common.data
|
|||
|
||||
import app.k9mail.feature.account.common.domain.AccountDomainContract
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountState
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountSyncOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
|
||||
|
@ -43,10 +42,6 @@ class InMemoryAccountStateRepository(
|
|||
state = state.copy(specialFolderSettings = specialFolderSettings)
|
||||
}
|
||||
|
||||
override fun setOptions(options: AccountOptions) {
|
||||
state = state.copy(options = options)
|
||||
}
|
||||
|
||||
override fun setDisplayOptions(displayOptions: AccountDisplayOptions) {
|
||||
state = state.copy(displayOptions = displayOptions)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package app.k9mail.feature.account.common.domain
|
||||
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountState
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountSyncOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
|
||||
|
@ -26,8 +25,6 @@ interface AccountDomainContract {
|
|||
|
||||
fun setSpecialFolderSettings(specialFolderSettings: SpecialFolderSettings)
|
||||
|
||||
fun setOptions(options: AccountOptions)
|
||||
|
||||
fun setDisplayOptions(displayOptions: AccountDisplayOptions)
|
||||
|
||||
fun setSyncOptions(syncOptions: AccountSyncOptions)
|
||||
|
|
|
@ -9,7 +9,6 @@ data class AccountState(
|
|||
val outgoingServerSettings: ServerSettings? = null,
|
||||
val authorizationState: AuthorizationState? = null,
|
||||
val specialFolderSettings: SpecialFolderSettings? = null,
|
||||
val options: AccountOptions? = null,
|
||||
val displayOptions: AccountDisplayOptions? = null,
|
||||
val syncOptions: AccountSyncOptions? = null,
|
||||
)
|
||||
|
|
|
@ -2,7 +2,6 @@ package app.k9mail.feature.account.common.ui.preview
|
|||
|
||||
import app.k9mail.feature.account.common.domain.AccountDomainContract
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountState
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountSyncOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
|
||||
|
@ -50,8 +49,6 @@ class PreviewAccountStateRepository : AccountDomainContract.AccountStateReposito
|
|||
|
||||
override fun setSpecialFolderSettings(specialFolderSettings: SpecialFolderSettings) = Unit
|
||||
|
||||
override fun setOptions(options: AccountOptions) = Unit
|
||||
|
||||
override fun setDisplayOptions(displayOptions: AccountDisplayOptions) = Unit
|
||||
|
||||
override fun setSyncOptions(syncOptions: AccountSyncOptions) = Unit
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package app.k9mail.feature.account.common.data
|
||||
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountState
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountSyncOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
|
@ -25,7 +26,8 @@ class InMemoryAccountStateRepositoryTest {
|
|||
incomingServerSettings = null,
|
||||
outgoingServerSettings = null,
|
||||
authorizationState = null,
|
||||
options = null,
|
||||
displayOptions = null,
|
||||
syncOptions = null,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
@ -39,7 +41,8 @@ class InMemoryAccountStateRepositoryTest {
|
|||
incomingServerSettings = INCOMING_SERVER_SETTINGS,
|
||||
outgoingServerSettings = OUTGOING_SERVER_SETTINGS,
|
||||
authorizationState = AuthorizationState("authorizationState"),
|
||||
options = OPTIONS,
|
||||
displayOptions = DISPLAY_OPTIONS,
|
||||
syncOptions = SYNC_OPTIONS,
|
||||
),
|
||||
)
|
||||
val newState = AccountState(
|
||||
|
@ -48,10 +51,12 @@ class InMemoryAccountStateRepositoryTest {
|
|||
incomingServerSettings = INCOMING_SERVER_SETTINGS.copy(host = "imap2.example.org"),
|
||||
outgoingServerSettings = OUTGOING_SERVER_SETTINGS.copy(host = "smtp2.example.org"),
|
||||
authorizationState = AuthorizationState("authorizationState2"),
|
||||
options = OPTIONS.copy(
|
||||
displayOptions = DISPLAY_OPTIONS.copy(
|
||||
accountName = "accountName2",
|
||||
displayName = "displayName2",
|
||||
emailSignature = "emailSignature2",
|
||||
),
|
||||
syncOptions = SYNC_OPTIONS.copy(
|
||||
checkFrequencyInMinutes = 50,
|
||||
messageDisplayCount = 60,
|
||||
showNotification = false,
|
||||
|
@ -104,13 +109,21 @@ class InMemoryAccountStateRepositoryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `should set options`() {
|
||||
fun `should set display options`() {
|
||||
val testSubject = InMemoryAccountStateRepository()
|
||||
|
||||
testSubject.setOptions(OPTIONS)
|
||||
testSubject.setDisplayOptions(DISPLAY_OPTIONS)
|
||||
|
||||
assertThat(testSubject.getState().options)
|
||||
.isEqualTo(OPTIONS)
|
||||
assertThat(testSubject.getState().displayOptions).isEqualTo(DISPLAY_OPTIONS)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should set sync options`() {
|
||||
val testSubject = InMemoryAccountStateRepository()
|
||||
|
||||
testSubject.setSyncOptions(SYNC_OPTIONS)
|
||||
|
||||
assertThat(testSubject.getState().syncOptions).isEqualTo(SYNC_OPTIONS)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -122,7 +135,8 @@ class InMemoryAccountStateRepositoryTest {
|
|||
incomingServerSettings = INCOMING_SERVER_SETTINGS,
|
||||
outgoingServerSettings = OUTGOING_SERVER_SETTINGS,
|
||||
authorizationState = AuthorizationState("authorizationState"),
|
||||
options = OPTIONS,
|
||||
displayOptions = DISPLAY_OPTIONS,
|
||||
syncOptions = SYNC_OPTIONS,
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -135,7 +149,8 @@ class InMemoryAccountStateRepositoryTest {
|
|||
incomingServerSettings = null,
|
||||
outgoingServerSettings = null,
|
||||
authorizationState = null,
|
||||
options = null,
|
||||
displayOptions = null,
|
||||
syncOptions = null,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
@ -163,10 +178,13 @@ class InMemoryAccountStateRepositoryTest {
|
|||
null,
|
||||
)
|
||||
|
||||
val OPTIONS = AccountOptions(
|
||||
val DISPLAY_OPTIONS = AccountDisplayOptions(
|
||||
accountName = "accountName",
|
||||
displayName = "displayName",
|
||||
emailSignature = "emailSignature",
|
||||
)
|
||||
|
||||
val SYNC_OPTIONS = AccountSyncOptions(
|
||||
checkFrequencyInMinutes = 10,
|
||||
messageDisplayCount = 20,
|
||||
showNotification = true,
|
||||
|
|
|
@ -17,7 +17,9 @@ class AccountStateTest {
|
|||
prop(AccountState::incomingServerSettings).isNull()
|
||||
prop(AccountState::outgoingServerSettings).isNull()
|
||||
prop(AccountState::authorizationState).isNull()
|
||||
prop(AccountState::options).isNull()
|
||||
prop(AccountState::specialFolderSettings).isNull()
|
||||
prop(AccountState::displayOptions).isNull()
|
||||
prop(AccountState::syncOptions).isNull()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package app.k9mail.feature.account.edit.domain.usecase
|
||||
|
||||
import app.k9mail.feature.account.common.data.InMemoryAccountStateRepository
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountState
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountSyncOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
|
||||
import app.k9mail.feature.account.common.domain.entity.MailConnectionSecurity
|
||||
import assertk.assertFailure
|
||||
|
@ -77,13 +79,26 @@ class GetAccountStateTest {
|
|||
showNotification = true,
|
||||
)
|
||||
|
||||
val DISPLAY_OPTIONS = AccountDisplayOptions(
|
||||
accountName = "accountName",
|
||||
displayName = "displayName",
|
||||
emailSignature = null,
|
||||
)
|
||||
|
||||
val SYNC_OPTIONS = AccountSyncOptions(
|
||||
checkFrequencyInMinutes = 15,
|
||||
messageDisplayCount = 25,
|
||||
showNotification = true,
|
||||
)
|
||||
|
||||
val ACCOUNT_STATE = AccountState(
|
||||
uuid = ACCOUNT_UUID,
|
||||
emailAddress = EMAIL_ADDRESS,
|
||||
incomingServerSettings = INCOMING_SERVER_SETTINGS,
|
||||
outgoingServerSettings = OUTGOING_SERVER_SETTINGS,
|
||||
authorizationState = AUTHORIZATION_STATE,
|
||||
options = OPTIONS,
|
||||
displayOptions = DISPLAY_OPTIONS,
|
||||
syncOptions = SYNC_OPTIONS,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package app.k9mail.feature.account.edit.domain.usecase
|
||||
|
||||
import app.k9mail.feature.account.common.data.InMemoryAccountStateRepository
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountState
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountSyncOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
|
||||
import app.k9mail.feature.account.common.domain.entity.MailConnectionSecurity
|
||||
import assertk.assertFailure
|
||||
|
@ -72,10 +73,13 @@ class LoadAccountStateTest {
|
|||
|
||||
val AUTHORIZATION_STATE = AuthorizationState("authorization state")
|
||||
|
||||
val OPTIONS = AccountOptions(
|
||||
val DISPLAY_OPTIONS = AccountDisplayOptions(
|
||||
accountName = "accountName",
|
||||
displayName = "displayName",
|
||||
emailSignature = null,
|
||||
)
|
||||
|
||||
val SYNC_OPTIONS = AccountSyncOptions(
|
||||
checkFrequencyInMinutes = 15,
|
||||
messageDisplayCount = 25,
|
||||
showNotification = true,
|
||||
|
@ -87,7 +91,8 @@ class LoadAccountStateTest {
|
|||
incomingServerSettings = INCOMING_SERVER_SETTINGS,
|
||||
outgoingServerSettings = OUTGOING_SERVER_SETTINGS,
|
||||
authorizationState = AUTHORIZATION_STATE,
|
||||
options = OPTIONS,
|
||||
displayOptions = DISPLAY_OPTIONS,
|
||||
syncOptions = SYNC_OPTIONS,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package app.k9mail.feature.account.edit.domain.usecase
|
||||
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountState
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountSyncOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
|
||||
import app.k9mail.feature.account.common.domain.entity.MailConnectionSecurity
|
||||
import app.k9mail.feature.account.edit.AccountEditExternalContract.AccountUpdaterFailure
|
||||
|
@ -143,10 +144,13 @@ class SaveServerSettingsTest {
|
|||
|
||||
val AUTHORIZATION_STATE = AuthorizationState("authorization state")
|
||||
|
||||
val OPTIONS = AccountOptions(
|
||||
val DISPLAY_OPTIONS = AccountDisplayOptions(
|
||||
accountName = "accountName",
|
||||
displayName = "displayName",
|
||||
emailSignature = null,
|
||||
)
|
||||
|
||||
val SYNC_OPTIONS = AccountSyncOptions(
|
||||
checkFrequencyInMinutes = 15,
|
||||
messageDisplayCount = 25,
|
||||
showNotification = true,
|
||||
|
@ -158,7 +162,8 @@ class SaveServerSettingsTest {
|
|||
incomingServerSettings = INCOMING_SERVER_SETTINGS,
|
||||
outgoingServerSettings = OUTGOING_SERVER_SETTINGS,
|
||||
authorizationState = AUTHORIZATION_STATE,
|
||||
options = OPTIONS,
|
||||
displayOptions = DISPLAY_OPTIONS,
|
||||
syncOptions = SYNC_OPTIONS,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,9 @@ package app.k9mail.feature.account.setup.domain
|
|||
import app.k9mail.autodiscovery.api.AutoDiscoveryResult
|
||||
import app.k9mail.core.common.domain.usecase.validation.ValidationError
|
||||
import app.k9mail.core.common.domain.usecase.validation.ValidationResult
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountState
|
||||
import app.k9mail.feature.account.common.domain.entity.SpecialFolderOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.SpecialFolderSettings
|
||||
import app.k9mail.feature.account.setup.AccountSetupExternalContract.AccountCreator.AccountCreatorResult
|
||||
import com.fsck.k9.mail.ServerSettings
|
||||
|
||||
interface DomainContract {
|
||||
|
||||
|
@ -18,15 +15,7 @@ interface DomainContract {
|
|||
}
|
||||
|
||||
fun interface CreateAccount {
|
||||
suspend fun execute(
|
||||
emailAddress: String,
|
||||
incomingServerSettings: ServerSettings,
|
||||
outgoingServerSettings: ServerSettings,
|
||||
authorizationState: String?,
|
||||
specialFolderSettings: SpecialFolderSettings?,
|
||||
options: AccountOptions,
|
||||
displayOptions: AccountDisplayOptions,
|
||||
): AccountCreatorResult
|
||||
suspend fun execute(accountState: AccountState): AccountCreatorResult
|
||||
}
|
||||
|
||||
fun interface ValidateEmailAddress {
|
||||
|
|
|
@ -3,47 +3,42 @@ package app.k9mail.feature.account.setup.domain.usecase
|
|||
import app.k9mail.feature.account.common.domain.entity.Account
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.SpecialFolderSettings
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountState
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountSyncOptions
|
||||
import app.k9mail.feature.account.setup.AccountSetupExternalContract.AccountCreator
|
||||
import app.k9mail.feature.account.setup.AccountSetupExternalContract.AccountCreator.AccountCreatorResult
|
||||
import app.k9mail.feature.account.setup.domain.DomainContract.UseCase
|
||||
import com.fsck.k9.mail.ServerSettings
|
||||
import java.util.UUID
|
||||
|
||||
class CreateAccount(
|
||||
private val accountCreator: AccountCreator,
|
||||
private val uuidGenerator: () -> String = { UUID.randomUUID().toString() },
|
||||
) : UseCase.CreateAccount {
|
||||
override suspend fun execute(
|
||||
emailAddress: String,
|
||||
incomingServerSettings: ServerSettings,
|
||||
outgoingServerSettings: ServerSettings,
|
||||
authorizationState: String?,
|
||||
specialFolderSettings: SpecialFolderSettings?,
|
||||
options: AccountOptions,
|
||||
displayOptions: AccountDisplayOptions,
|
||||
): AccountCreatorResult {
|
||||
override suspend fun execute(accountState: AccountState): AccountCreatorResult {
|
||||
val account = Account(
|
||||
uuid = uuidGenerator(),
|
||||
emailAddress = emailAddress,
|
||||
incomingServerSettings = incomingServerSettings,
|
||||
outgoingServerSettings = outgoingServerSettings,
|
||||
authorizationState = authorizationState,
|
||||
specialFolderSettings = specialFolderSettings,
|
||||
options = mapOptions(options, displayOptions),
|
||||
emailAddress = accountState.emailAddress!!,
|
||||
incomingServerSettings = accountState.incomingServerSettings!!.copy(),
|
||||
outgoingServerSettings = accountState.outgoingServerSettings!!.copy(),
|
||||
authorizationState = accountState.authorizationState?.value,
|
||||
specialFolderSettings = accountState.specialFolderSettings,
|
||||
options = mapOptions(accountState.displayOptions!!, accountState.syncOptions!!),
|
||||
)
|
||||
|
||||
return accountCreator.createAccount(account)
|
||||
}
|
||||
|
||||
private fun mapOptions(
|
||||
options: AccountOptions,
|
||||
displayOptions: AccountDisplayOptions,
|
||||
syncOptions: AccountSyncOptions,
|
||||
): AccountOptions {
|
||||
return options.copy(
|
||||
return AccountOptions(
|
||||
accountName = displayOptions.accountName,
|
||||
displayName = displayOptions.displayName,
|
||||
emailSignature = displayOptions.emailSignature,
|
||||
checkFrequencyInMinutes = syncOptions.checkFrequencyInMinutes,
|
||||
messageDisplayCount = syncOptions.messageDisplayCount,
|
||||
showNotification = syncOptions.showNotification,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@ internal fun AccountAutoDiscoveryContract.State.toAccountState(): AccountState {
|
|||
incomingServerSettings = autoDiscoverySettings?.incomingServerSettings?.toServerSettings(password.value),
|
||||
outgoingServerSettings = autoDiscoverySettings?.outgoingServerSettings?.toServerSettings(password.value),
|
||||
authorizationState = authorizationState,
|
||||
options = null,
|
||||
displayOptions = null,
|
||||
syncOptions = null,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ internal fun AccountOptionsScreenK9Preview() {
|
|||
onNext = {},
|
||||
onBack = {},
|
||||
viewModel = CreateAccountViewModel(
|
||||
createAccount = { _, _, _, _, _, _, _ -> AccountCreatorResult.Success("irrelevant") },
|
||||
createAccount = { AccountCreatorResult.Success("irrelevant") },
|
||||
accountStateRepository = InMemoryAccountStateRepository(),
|
||||
),
|
||||
)
|
||||
|
|
|
@ -33,17 +33,7 @@ class CreateAccountViewModel(
|
|||
val accountState = accountStateRepository.getState()
|
||||
|
||||
viewModelScope.launch {
|
||||
val result = createAccount.execute(
|
||||
emailAddress = accountState.emailAddress ?: "",
|
||||
incomingServerSettings = accountState.incomingServerSettings!!,
|
||||
outgoingServerSettings = accountState.outgoingServerSettings!!,
|
||||
authorizationState = accountState.authorizationState?.state,
|
||||
specialFolderSettings = accountState.specialFolderSettings,
|
||||
options = accountState.options!!,
|
||||
displayOptions = accountState.displayOptions!!,
|
||||
)
|
||||
|
||||
when (result) {
|
||||
when (val result = createAccount.execute(accountState)) {
|
||||
is AccountCreatorResult.Success -> showSuccess(AccountUuid(result.accountUuid))
|
||||
is AccountCreatorResult.Error -> showError(result)
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ import app.k9mail.feature.account.common.domain.entity.AccountState
|
|||
import app.k9mail.feature.account.common.domain.input.StringInputField
|
||||
import app.k9mail.feature.account.setup.ui.options.display.DisplayOptionsContract.State
|
||||
|
||||
internal fun AccountState.toAccountOptionsState(): State {
|
||||
val options = options
|
||||
internal fun AccountState.toDisplayOptionsState(): State {
|
||||
val options = displayOptions
|
||||
return if (options == null) {
|
||||
State(
|
||||
accountName = StringInputField(emailAddress ?: ""),
|
||||
|
|
|
@ -14,7 +14,7 @@ internal class DisplayOptionsViewModel(
|
|||
private val accountStateRepository: AccountDomainContract.AccountStateRepository,
|
||||
initialState: State? = null,
|
||||
) : BaseViewModel<State, Event, Effect>(
|
||||
initialState = initialState ?: accountStateRepository.getState().toAccountOptionsState(),
|
||||
initialState = initialState ?: accountStateRepository.getState().toDisplayOptionsState(),
|
||||
),
|
||||
ViewModel {
|
||||
|
||||
|
@ -47,7 +47,7 @@ internal class DisplayOptionsViewModel(
|
|||
|
||||
private fun loadAccountState() {
|
||||
updateState {
|
||||
accountStateRepository.getState().toAccountOptionsState()
|
||||
accountStateRepository.getState().toDisplayOptionsState()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@ import app.k9mail.feature.account.setup.domain.entity.EmailCheckFrequency
|
|||
import app.k9mail.feature.account.setup.domain.entity.EmailDisplayCount
|
||||
import app.k9mail.feature.account.setup.ui.options.sync.SyncOptionsContract.State
|
||||
|
||||
internal fun AccountState.toAccountOptionsState(): State {
|
||||
val options = options
|
||||
internal fun AccountState.toSyncOptionsState(): State {
|
||||
val options = syncOptions
|
||||
return if (options == null) {
|
||||
State()
|
||||
} else {
|
||||
|
|
|
@ -11,7 +11,7 @@ internal class SyncOptionsViewModel(
|
|||
private val accountStateRepository: AccountDomainContract.AccountStateRepository,
|
||||
initialState: State? = null,
|
||||
) : BaseViewModel<State, Event, Effect>(
|
||||
initialState = initialState ?: accountStateRepository.getState().toAccountOptionsState(),
|
||||
initialState = initialState ?: accountStateRepository.getState().toSyncOptionsState(),
|
||||
),
|
||||
ViewModel {
|
||||
|
||||
|
@ -44,7 +44,7 @@ internal class SyncOptionsViewModel(
|
|||
|
||||
private fun loadAccountState() {
|
||||
updateState {
|
||||
accountStateRepository.getState().toAccountOptionsState()
|
||||
accountStateRepository.getState().toSyncOptionsState()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ package app.k9mail.feature.account.setup.domain.usecase
|
|||
import app.k9mail.feature.account.common.domain.entity.Account
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountState
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountSyncOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
|
||||
import app.k9mail.feature.account.common.domain.entity.MailConnectionSecurity
|
||||
import app.k9mail.feature.account.common.domain.entity.SpecialFolderOption
|
||||
import app.k9mail.feature.account.common.domain.entity.SpecialFolderSettings
|
||||
|
@ -31,13 +34,15 @@ class CreateAccountTest {
|
|||
)
|
||||
|
||||
val result = createAccount.execute(
|
||||
emailAddress = EMAIL_ADDRESS,
|
||||
incomingServerSettings = INCOMING_SETTINGS,
|
||||
outgoingServerSettings = OUTGOING_SETTINGS,
|
||||
authorizationState = AUTHORIZATION_STATE,
|
||||
specialFolderSettings = SPECIAL_FOLDER_SETTINGS,
|
||||
options = OPTIONS,
|
||||
displayOptions = DISPLAY_OPTIONS,
|
||||
AccountState(
|
||||
emailAddress = EMAIL_ADDRESS,
|
||||
incomingServerSettings = INCOMING_SETTINGS,
|
||||
outgoingServerSettings = OUTGOING_SETTINGS,
|
||||
authorizationState = AUTHORIZATION_STATE,
|
||||
specialFolderSettings = SPECIAL_FOLDER_SETTINGS,
|
||||
displayOptions = DISPLAY_OPTIONS,
|
||||
syncOptions = SYNC_OPTIONS,
|
||||
),
|
||||
)
|
||||
|
||||
assertThat(result).isEqualTo(AccountCreatorResult.Success("uuid"))
|
||||
|
@ -47,7 +52,7 @@ class CreateAccountTest {
|
|||
emailAddress = EMAIL_ADDRESS,
|
||||
incomingServerSettings = INCOMING_SETTINGS,
|
||||
outgoingServerSettings = OUTGOING_SETTINGS,
|
||||
authorizationState = AUTHORIZATION_STATE,
|
||||
authorizationState = AUTHORIZATION_STATE.value,
|
||||
specialFolderSettings = SPECIAL_FOLDER_SETTINGS,
|
||||
options = OPTIONS,
|
||||
),
|
||||
|
@ -79,7 +84,7 @@ class CreateAccountTest {
|
|||
clientCertificateAlias = null,
|
||||
)
|
||||
|
||||
const val AUTHORIZATION_STATE = "authorization state"
|
||||
val AUTHORIZATION_STATE = AuthorizationState("authorization state")
|
||||
|
||||
val SPECIAL_FOLDER_SETTINGS = SpecialFolderSettings(
|
||||
archiveSpecialFolderOption = SpecialFolderOption.Special(
|
||||
|
@ -113,5 +118,11 @@ class CreateAccountTest {
|
|||
displayName = "displayName",
|
||||
emailSignature = null,
|
||||
)
|
||||
|
||||
val SYNC_OPTIONS = AccountSyncOptions(
|
||||
checkFrequencyInMinutes = 15,
|
||||
messageDisplayCount = 25,
|
||||
showNotification = true,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ class AccountAutoDiscoveryStateMapperKtTest {
|
|||
incomingServerSettings = null,
|
||||
outgoingServerSettings = null,
|
||||
authorizationState = null,
|
||||
options = null,
|
||||
displayOptions = null,
|
||||
syncOptions = null,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -297,7 +297,8 @@ class AccountAutoDiscoveryViewModelTest {
|
|||
incomingServerSettings = null,
|
||||
outgoingServerSettings = null,
|
||||
authorizationState = null,
|
||||
options = null,
|
||||
displayOptions = null,
|
||||
syncOptions = null,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ import app.k9mail.core.ui.compose.testing.MainDispatcherRule
|
|||
import app.k9mail.core.ui.compose.testing.mvi.eventStateTest
|
||||
import app.k9mail.feature.account.common.data.InMemoryAccountStateRepository
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountState
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountSyncOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AuthorizationState
|
||||
import app.k9mail.feature.account.common.domain.entity.SpecialFolderOption
|
||||
import app.k9mail.feature.account.common.domain.entity.SpecialFolderSettings
|
||||
|
@ -61,14 +61,14 @@ class CreateAccountViewModelTest {
|
|||
)
|
||||
|
||||
assertThat(fakeCreateAccount.recordedInvocations).containsExactly(
|
||||
CreateAccountArguments(
|
||||
AccountState(
|
||||
emailAddress = EMAIL_ADDRESS,
|
||||
incomingServerSettings = INCOMING_SERVER_SETTINGS,
|
||||
outgoingServerSettings = OUTGOING_SERVER_SETTINGS,
|
||||
authorizationState = AUTHORIZATION_STATE.state,
|
||||
authorizationState = AUTHORIZATION_STATE,
|
||||
specialFolderSettings = SPECIAL_FOLDER_SETTINGS,
|
||||
options = ACCOUNT_OPTIONS,
|
||||
displayOptions = ACCOUNT_DISPLAY_OPTIONS,
|
||||
syncOptions = ACCOUNT_SYNC_OPTIONS,
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -186,28 +186,26 @@ class CreateAccountViewModelTest {
|
|||
),
|
||||
)
|
||||
|
||||
val ACCOUNT_OPTIONS = AccountOptions(
|
||||
accountName = "account name",
|
||||
displayName = "display name",
|
||||
emailSignature = null,
|
||||
checkFrequencyInMinutes = 0,
|
||||
messageDisplayCount = 50,
|
||||
showNotification = false,
|
||||
)
|
||||
|
||||
val ACCOUNT_DISPLAY_OPTIONS = AccountDisplayOptions(
|
||||
accountName = "account name",
|
||||
displayName = "display name",
|
||||
emailSignature = null,
|
||||
)
|
||||
|
||||
val ACCOUNT_SYNC_OPTIONS = AccountSyncOptions(
|
||||
checkFrequencyInMinutes = 0,
|
||||
messageDisplayCount = 50,
|
||||
showNotification = false,
|
||||
)
|
||||
|
||||
val ACCOUNT_STATE = AccountState(
|
||||
emailAddress = EMAIL_ADDRESS,
|
||||
incomingServerSettings = INCOMING_SERVER_SETTINGS,
|
||||
outgoingServerSettings = OUTGOING_SERVER_SETTINGS,
|
||||
authorizationState = AUTHORIZATION_STATE,
|
||||
specialFolderSettings = SPECIAL_FOLDER_SETTINGS,
|
||||
options = ACCOUNT_OPTIONS,
|
||||
displayOptions = ACCOUNT_DISPLAY_OPTIONS,
|
||||
syncOptions = ACCOUNT_SYNC_OPTIONS,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,48 +1,19 @@
|
|||
package app.k9mail.feature.account.setup.ui.createaccount
|
||||
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountDisplayOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountOptions
|
||||
import app.k9mail.feature.account.common.domain.entity.SpecialFolderSettings
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountState
|
||||
import app.k9mail.feature.account.setup.AccountSetupExternalContract.AccountCreator.AccountCreatorResult
|
||||
import app.k9mail.feature.account.setup.domain.DomainContract.UseCase.CreateAccount
|
||||
import com.fsck.k9.mail.ServerSettings
|
||||
|
||||
class FakeCreateAccount : CreateAccount {
|
||||
val recordedInvocations = mutableListOf<CreateAccountArguments>()
|
||||
val recordedInvocations = mutableListOf<AccountState>()
|
||||
|
||||
var result: AccountCreatorResult = AccountCreatorResult.Success("default result")
|
||||
|
||||
override suspend fun execute(
|
||||
emailAddress: String,
|
||||
incomingServerSettings: ServerSettings,
|
||||
outgoingServerSettings: ServerSettings,
|
||||
authorizationState: String?,
|
||||
specialFolderSettings: SpecialFolderSettings?,
|
||||
options: AccountOptions,
|
||||
displayOptions: AccountDisplayOptions,
|
||||
accountState: AccountState,
|
||||
): AccountCreatorResult {
|
||||
recordedInvocations.add(
|
||||
CreateAccountArguments(
|
||||
emailAddress,
|
||||
incomingServerSettings,
|
||||
outgoingServerSettings,
|
||||
authorizationState,
|
||||
specialFolderSettings,
|
||||
options,
|
||||
displayOptions,
|
||||
),
|
||||
)
|
||||
recordedInvocations.add(accountState)
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
data class CreateAccountArguments(
|
||||
val emailAddress: String,
|
||||
val incomingServerSettings: ServerSettings,
|
||||
val outgoingServerSettings: ServerSettings,
|
||||
val authorizationState: String?,
|
||||
val specialFolderSettings: SpecialFolderSettings?,
|
||||
val options: AccountOptions,
|
||||
val displayOptions: AccountDisplayOptions,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue