Convert 'Account' to Kotlin

This commit is contained in:
cketti 2022-02-08 18:58:08 +01:00
parent 2dbdca0fc4
commit f923da4487
6 changed files with 692 additions and 1100 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,19 +1,19 @@
package com.fsck.k9
import com.fsck.k9.Account.DEFAULT_SORT_ASCENDING
import com.fsck.k9.Account.DEFAULT_SORT_TYPE
import com.fsck.k9.Account.DEFAULT_SYNC_INTERVAL
import com.fsck.k9.Account.Companion.DEFAULT_SORT_ASCENDING
import com.fsck.k9.Account.Companion.DEFAULT_SORT_TYPE
import com.fsck.k9.Account.Companion.DEFAULT_SYNC_INTERVAL
import com.fsck.k9.Account.Companion.NO_OPENPGP_KEY
import com.fsck.k9.Account.Companion.UNASSIGNED_ACCOUNT_NUMBER
import com.fsck.k9.Account.DeletePolicy
import com.fsck.k9.Account.Expunge
import com.fsck.k9.Account.FolderMode
import com.fsck.k9.Account.MessageFormat
import com.fsck.k9.Account.NO_OPENPGP_KEY
import com.fsck.k9.Account.QuoteStyle
import com.fsck.k9.Account.Searchable
import com.fsck.k9.Account.ShowPictures
import com.fsck.k9.Account.SortType
import com.fsck.k9.Account.SpecialFolderSelection
import com.fsck.k9.Account.UNASSIGNED_ACCOUNT_NUMBER
import com.fsck.k9.helper.Utility
import com.fsck.k9.mail.NetworkType
import com.fsck.k9.mailstore.StorageManager
@ -38,7 +38,7 @@ class AccountPreferenceSerializer(
storage.getString("$accountUuid.$OUTGOING_SERVER_SETTINGS_KEY", "")
)
localStorageProviderId = storage.getString("$accountUuid.localStorageProvider", storageManager.defaultProviderId)
setName(storage.getString("$accountUuid.description", null))
name = storage.getString("$accountUuid.description", null)
alwaysBcc = storage.getString("$accountUuid.alwaysBcc", alwaysBcc)
automaticCheckIntervalMinutes = storage.getInt("$accountUuid.automaticCheckIntervalMinutes", DEFAULT_SYNC_INTERVAL)
idleRefreshMinutes = storage.getInt("$accountUuid.idleRefreshMinutes", 24)
@ -159,7 +159,7 @@ class AccountPreferenceSerializer(
searchableFolders = getEnumStringPref<Searchable>(storage, "$accountUuid.searchableFolders", Searchable.ALL)
isSignatureBeforeQuotedText = storage.getBoolean("$accountUuid.signatureBeforeQuotedText", false)
identities = loadIdentities(accountUuid, storage)
replaceIdentities(loadIdentities(accountUuid, storage))
openPgpProvider = storage.getString("$accountUuid.openPgpProvider", "")
openPgpKey = storage.getLong("$accountUuid.cryptoKey", NO_OPENPGP_KEY)
@ -333,6 +333,7 @@ class AccountPreferenceSerializer(
editor.putLong("$accountUuid.lastFolderListRefreshTime", lastFolderListRefreshTime)
editor.putBoolean("$accountUuid.isFinishedSetup", isFinishedSetup)
val compressionMap = getCompressionMap()
for (type in NetworkType.values()) {
val useCompression = compressionMap[type]
if (useCompression != null) {

View file

@ -115,13 +115,15 @@ class IdentityHelperTest : RobolectricTest() {
}
private fun createDummyAccount() = Account(UUID.randomUUID().toString()).apply {
identities = listOf(
newIdentity("Default", DEFAULT_ADDRESS),
newIdentity("Identity 1", IDENTITY_1_ADDRESS),
newIdentity("Identity 2", IDENTITY_2_ADDRESS),
newIdentity("Identity 3", IDENTITY_3_ADDRESS),
newIdentity("Identity 4", IDENTITY_4_ADDRESS),
newIdentity("Identity 5", IDENTITY_5_ADDRESS)
replaceIdentities(
listOf(
newIdentity("Default", DEFAULT_ADDRESS),
newIdentity("Identity 1", IDENTITY_1_ADDRESS),
newIdentity("Identity 2", IDENTITY_2_ADDRESS),
newIdentity("Identity 3", IDENTITY_3_ADDRESS),
newIdentity("Identity 4", IDENTITY_4_ADDRESS),
newIdentity("Identity 5", IDENTITY_5_ADDRESS)
)
)
}

View file

@ -24,8 +24,8 @@ class BaseNotificationDataCreatorTest {
@Test
fun `account name from name property`() {
account.setName("name")
account.setEmail("irrelevant@k9mail.example")
account.name = "name"
account.email = "irrelevant@k9mail.example"
val notificationData = createNotificationData()
val result = notificationDataCreator.createBaseNotificationData(notificationData)
@ -35,8 +35,8 @@ class BaseNotificationDataCreatorTest {
@Test
fun `account name is blank`() {
account.setName("")
account.setEmail("test@k9mail.example")
account.name = ""
account.email = "test@k9mail.example"
val notificationData = createNotificationData()
val result = notificationDataCreator.createBaseNotificationData(notificationData)
@ -46,8 +46,8 @@ class BaseNotificationDataCreatorTest {
@Test
fun `account name is null`() {
account.setName(null)
account.setEmail("test@k9mail.example")
account.name = null
account.email = "test@k9mail.example"
val notificationData = createNotificationData()
val result = notificationDataCreator.createBaseNotificationData(notificationData)
@ -191,8 +191,8 @@ class BaseNotificationDataCreatorTest {
private fun createAccount(): Account {
return Account("00000000-0000-4000-0000-000000000000").apply {
setName("account name")
identities = listOf(Identity())
name = "account name"
replaceIdentities(listOf(Identity()))
}
}
}

View file

@ -347,7 +347,7 @@ class NewMailNotificationManagerTest {
private fun createAccount(): Account {
return Account(ACCOUNT_UUID).apply {
setName(ACCOUNT_NAME)
name = ACCOUNT_NAME
chipColor = ACCOUNT_COLOR
}
}

View file

@ -143,18 +143,18 @@ class AccountSettingsDataStore(
if (value == null) return
when (key) {
"account_description" -> account.setName(value)
"account_description" -> account.name = value
"show_pictures_enum" -> account.showPictures = Account.ShowPictures.valueOf(value)
"account_display_count" -> account.displayCount = value.toInt()
"account_message_age" -> account.maximumPolledMessageAge = value.toInt()
"account_autodownload_size" -> account.maximumAutoDownloadMessageSize = value.toInt()
"account_check_frequency" -> {
if (account.setAutomaticCheckIntervalMinutes(value.toInt())) {
if (account.updateAutomaticCheckIntervalMinutes(value.toInt())) {
reschedulePoll()
}
}
"folder_sync_mode" -> {
if (account.setFolderSyncMode(Account.FolderMode.valueOf(value))) {
if (account.updateFolderSyncMode(Account.FolderMode.valueOf(value))) {
reschedulePoll()
}
}