Skip to content

Commit

Permalink
Merge pull request #7489 from thunderbird/change-options-screen-into-…
Browse files Browse the repository at this point in the history
…two-screens

Change options screen into two screens
  • Loading branch information
wmontwe authored Jan 11, 2024
2 parents b9a7d17 + 34d0da0 commit 0ff9f1e
Show file tree
Hide file tree
Showing 90 changed files with 1,062 additions and 494 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,12 +42,12 @@ class InMemoryAccountStore(
accountMap[account.uuid] = if (isIncoming) {
account.copy(
incomingServerSettings = serverSettings,
authorizationState = authorizationState?.state,
authorizationState = authorizationState?.value,
)
} else {
account.copy(
outgoingServerSettings = serverSettings,
authorizationState = authorizationState?.state,
authorizationState = authorizationState?.value,
)
}

Expand All @@ -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,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AccountServerSettingsUpdater(
account.outgoingServerSettings = serverSettings
}

account.oAuthState = authorizationState?.state
account.oAuthState = authorizationState?.value

accountManager.saveAccount(account)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AccountServerSettingsUpdaterTest {
assertThat(k9Account).isNotNull().all {
prop(K9Account::incomingServerSettings).isEqualTo(updatedIncomingServerSettings)
prop(K9Account::outgoingServerSettings).isEqualTo(OUTGOING_SERVER_SETTINGS)
prop(K9Account::oAuthState).isEqualTo(updatedAuthorizationState.state)
prop(K9Account::oAuthState).isEqualTo(updatedAuthorizationState.value)
}
}

Expand All @@ -77,7 +77,7 @@ class AccountServerSettingsUpdaterTest {
assertThat(k9Account).isNotNull().all {
prop(K9Account::incomingServerSettings).isEqualTo(INCOMING_SERVER_SETTINGS)
prop(K9Account::outgoingServerSettings).isEqualTo(updatedOutgoingServerSettings)
prop(K9Account::oAuthState).isEqualTo(updatedAuthorizationState.state)
prop(K9Account::oAuthState).isEqualTo(updatedAuthorizationState.value)
}
}

Expand Down Expand Up @@ -136,7 +136,7 @@ class AccountServerSettingsUpdaterTest {
).apply {
incomingServerSettings = INCOMING_SERVER_SETTINGS
outgoingServerSettings = OUTGOING_SERVER_SETTINGS
oAuthState = AUTHORIZATION_STATE.state
oAuthState = AUTHORIZATION_STATE.value
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package app.k9mail.feature.account.common.data

import app.k9mail.feature.account.common.domain.AccountDomainContract
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.SpecialFolderSettings
import com.fsck.k9.mail.ServerSettings
Expand Down Expand Up @@ -41,16 +42,20 @@ 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)
}

override fun setSyncOptions(syncOptions: AccountSyncOptions) {
state = state.copy(syncOptions = syncOptions)
}

override fun clear() {
state = AccountState()
}

override fun getAuthorizationState(): String? {
return state.authorizationState?.state
return state.authorizationState?.value
}

override fun updateAuthorizationState(authorizationState: String?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package app.k9mail.feature.account.common.domain

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.SpecialFolderSettings
import com.fsck.k9.mail.ServerSettings

interface AccountDomainContract {

@Suppress("TooManyFunctions")
interface AccountStateRepository {
fun getState(): AccountState

Expand All @@ -23,7 +25,9 @@ interface AccountDomainContract {

fun setSpecialFolderSettings(specialFolderSettings: SpecialFolderSettings)

fun setOptions(options: AccountOptions)
fun setDisplayOptions(displayOptions: AccountDisplayOptions)

fun setSyncOptions(syncOptions: AccountSyncOptions)

fun clear()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package app.k9mail.feature.account.common.domain.entity

data class AccountDisplayOptions(
val accountName: String,
val displayName: String,
val emailSignature: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +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,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package app.k9mail.feature.account.common.domain.entity

data class AccountSyncOptions(
val checkFrequencyInMinutes: Int,
val messageDisplayCount: Int,
val showNotification: Boolean,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package app.k9mail.feature.account.common.domain.entity

data class AuthorizationState(
val state: String? = null,
val value: String? = null,
)
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package app.k9mail.feature.account.common.ui.preview

import app.k9mail.feature.account.common.domain.AccountDomainContract
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.common.domain.entity.SpecialFolderSettings
import com.fsck.k9.mail.AuthType
import com.fsck.k9.mail.ServerSettings

@Suppress("TooManyFunctions")
class PreviewAccountStateRepository : AccountDomainContract.AccountStateRepository {

override fun getState(): AccountState = AccountState(
Expand Down Expand Up @@ -47,7 +49,9 @@ 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

override fun clear() = Unit
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,7 +26,8 @@ class InMemoryAccountStateRepositoryTest {
incomingServerSettings = null,
outgoingServerSettings = null,
authorizationState = null,
options = null,
displayOptions = null,
syncOptions = null,
),
)
}
Expand All @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
),
)

Expand All @@ -135,7 +149,8 @@ class InMemoryAccountStateRepositoryTest {
incomingServerSettings = null,
outgoingServerSettings = null,
authorizationState = null,
options = null,
displayOptions = null,
syncOptions = null,
),
)
}
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class AuthorizationStateTest {
fun `should default to null state`() {
val authorizationState = AuthorizationState()

assertThat(authorizationState.state).isNull()
assertThat(authorizationState.value).isNull()
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
)
}
}
Loading

0 comments on commit 0ff9f1e

Please sign in to comment.