Skip to content

Commit

Permalink
Cleanup remaining code style issues for Kotlin sources
Browse files Browse the repository at this point in the history
  • Loading branch information
wmontwe committed Feb 17, 2023
1 parent d267394 commit 82cb622
Show file tree
Hide file tree
Showing 48 changed files with 445 additions and 239 deletions.
51 changes: 38 additions & 13 deletions app/core/src/main/java/com/fsck/k9/AccountPreferenceSerializer.kt
Expand Up @@ -37,18 +37,29 @@ class AccountPreferenceSerializer(
storage.getString("$accountUuid.$OUTGOING_SERVER_SETTINGS_KEY", ""),
)
oAuthState = storage.getString("$accountUuid.oAuthState", null)
localStorageProviderId = storage.getString("$accountUuid.localStorageProvider", storageManager.defaultProviderId)
localStorageProviderId = storage.getString(
"$accountUuid.localStorageProvider",
storageManager.defaultProviderId,
)
name = storage.getString("$accountUuid.description", null)
alwaysBcc = storage.getString("$accountUuid.alwaysBcc", alwaysBcc)
automaticCheckIntervalMinutes = storage.getInt("$accountUuid.automaticCheckIntervalMinutes", DEFAULT_SYNC_INTERVAL)
automaticCheckIntervalMinutes = storage.getInt(
"" +
"$accountUuid.automaticCheckIntervalMinutes",
DEFAULT_SYNC_INTERVAL,
)
idleRefreshMinutes = storage.getInt("$accountUuid.idleRefreshMinutes", 24)
displayCount = storage.getInt("$accountUuid.displayCount", K9.DEFAULT_VISIBLE_LIMIT)
if (displayCount < 0) {
displayCount = K9.DEFAULT_VISIBLE_LIMIT
}
isNotifyNewMail = storage.getBoolean("$accountUuid.notifyNewMail", false)

folderNotifyNewMailMode = getEnumStringPref<FolderMode>(storage, "$accountUuid.folderNotifyNewMailMode", FolderMode.ALL)
folderNotifyNewMailMode = getEnumStringPref<FolderMode>(
storage,
"$accountUuid.folderNotifyNewMailMode",
FolderMode.ALL,
)
isNotifySelfNewMail = storage.getBoolean("$accountUuid.notifySelfNewMail", true)
isNotifyContactsMailOnly = storage.getBoolean("$accountUuid.notifyContactsMailOnly", false)
isIgnoreChatMessages = storage.getBoolean("$accountUuid.ignoreChatMessages", false)
Expand Down Expand Up @@ -107,22 +118,25 @@ class AccountPreferenceSerializer(

autoExpandFolderId = storage.getString("$accountUuid.autoExpandFolderId", null)?.toLongOrNull()

expungePolicy = getEnumStringPref<Expunge>(storage, "$accountUuid.expungePolicy", Expunge.EXPUNGE_IMMEDIATELY)
expungePolicy = getEnumStringPref(storage, "$accountUuid.expungePolicy", Expunge.EXPUNGE_IMMEDIATELY)
isSyncRemoteDeletions = storage.getBoolean("$accountUuid.syncRemoteDeletions", true)

maxPushFolders = storage.getInt("$accountUuid.maxPushFolders", 10)
isSubscribedFoldersOnly = storage.getBoolean("$accountUuid.subscribedFoldersOnly", false)
maximumPolledMessageAge = storage.getInt("$accountUuid.maximumPolledMessageAge", -1)
maximumAutoDownloadMessageSize = storage.getInt("$accountUuid.maximumAutoDownloadMessageSize", 32768)
messageFormat = getEnumStringPref<MessageFormat>(storage, "$accountUuid.messageFormat", DEFAULT_MESSAGE_FORMAT)
messageFormat = getEnumStringPref(storage, "$accountUuid.messageFormat", DEFAULT_MESSAGE_FORMAT)
val messageFormatAuto = storage.getBoolean("$accountUuid.messageFormatAuto", DEFAULT_MESSAGE_FORMAT_AUTO)
if (messageFormatAuto && messageFormat == MessageFormat.TEXT) {
messageFormat = MessageFormat.AUTO
}
isMessageReadReceipt = storage.getBoolean("$accountUuid.messageReadReceipt", DEFAULT_MESSAGE_READ_RECEIPT)
quoteStyle = getEnumStringPref<QuoteStyle>(storage, "$accountUuid.quoteStyle", DEFAULT_QUOTE_STYLE)
quotePrefix = storage.getString("$accountUuid.quotePrefix", DEFAULT_QUOTE_PREFIX)
isDefaultQuotedTextShown = storage.getBoolean("$accountUuid.defaultQuotedTextShown", DEFAULT_QUOTED_TEXT_SHOWN)
isDefaultQuotedTextShown = storage.getBoolean(
"$accountUuid.defaultQuotedTextShown",
DEFAULT_QUOTED_TEXT_SHOWN,
)
isReplyAfterQuote = storage.getBoolean("$accountUuid.replyAfterQuote", DEFAULT_REPLY_AFTER_QUOTE)
isStripSignature = storage.getBoolean("$accountUuid.stripSignature", DEFAULT_STRIP_SIGNATURE)
useCompression = storage.getBoolean("$accountUuid.useCompression", true)
Expand Down Expand Up @@ -152,13 +166,16 @@ class AccountPreferenceSerializer(
)
}

folderDisplayMode = getEnumStringPref<FolderMode>(storage, "$accountUuid.folderDisplayMode", FolderMode.NOT_SECOND_CLASS)
folderDisplayMode =
getEnumStringPref<FolderMode>(storage, "$accountUuid.folderDisplayMode", FolderMode.NOT_SECOND_CLASS)

folderSyncMode = getEnumStringPref<FolderMode>(storage, "$accountUuid.folderSyncMode", FolderMode.FIRST_CLASS)
folderSyncMode =
getEnumStringPref<FolderMode>(storage, "$accountUuid.folderSyncMode", FolderMode.FIRST_CLASS)

folderPushMode = getEnumStringPref<FolderMode>(storage, "$accountUuid.folderPushMode", FolderMode.NONE)

folderTargetMode = getEnumStringPref<FolderMode>(storage, "$accountUuid.folderTargetMode", FolderMode.NOT_SECOND_CLASS)
folderTargetMode =
getEnumStringPref<FolderMode>(storage, "$accountUuid.folderTargetMode", FolderMode.NOT_SECOND_CLASS)

searchableFolders = getEnumStringPref<Searchable>(storage, "$accountUuid.searchableFolders", Searchable.ALL)

Expand All @@ -172,7 +189,8 @@ class AccountPreferenceSerializer(
isOpenPgpEncryptAllDrafts = storage.getBoolean("$accountUuid.openPgpEncryptAllDrafts", true)
autocryptPreferEncryptMutual = storage.getBoolean("$accountUuid.autocryptMutualMode", false)
isRemoteSearchFullText = storage.getBoolean("$accountUuid.remoteSearchFullText", false)
remoteSearchNumResults = storage.getInt("$accountUuid.remoteSearchNumResults", DEFAULT_REMOTE_SEARCH_NUM_RESULTS)
remoteSearchNumResults =
storage.getInt("$accountUuid.remoteSearchNumResults", DEFAULT_REMOTE_SEARCH_NUM_RESULTS)
isUploadSentMessages = storage.getBoolean("$accountUuid.uploadSentMessages", true)

isMarkMessageAsReadOnView = storage.getBoolean("$accountUuid.markMessageAsReadOnView", true)
Expand Down Expand Up @@ -247,8 +265,14 @@ class AccountPreferenceSerializer(
}

with(account) {
editor.putString("$accountUuid.$INCOMING_SERVER_SETTINGS_KEY", serverSettingsSerializer.serialize(incomingServerSettings))
editor.putString("$accountUuid.$OUTGOING_SERVER_SETTINGS_KEY", serverSettingsSerializer.serialize(outgoingServerSettings))
editor.putString(
"$accountUuid.$INCOMING_SERVER_SETTINGS_KEY",
serverSettingsSerializer.serialize(incomingServerSettings),
)
editor.putString(
"$accountUuid.$OUTGOING_SERVER_SETTINGS_KEY",
serverSettingsSerializer.serialize(outgoingServerSettings),
)
editor.putString("$accountUuid.oAuthState", oAuthState)
editor.putString("$accountUuid.localStorageProvider", localStorageProviderId)
editor.putString("$accountUuid.description", name)
Expand Down Expand Up @@ -351,7 +375,8 @@ class AccountPreferenceSerializer(
val accountUuid = account.uuid

// Get the list of account UUIDs
val uuids = storage.getString("accountUuids", "").split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
val uuids =
storage.getString("accountUuids", "").split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()

// Create a list of all account UUIDs excluding this account
val newUuids = ArrayList<String>(uuids.size)
Expand Down
3 changes: 2 additions & 1 deletion app/core/src/main/java/com/fsck/k9/DI.kt
Expand Up @@ -14,7 +14,8 @@ import org.koin.java.KoinJavaComponent.get as koinGet
object DI {
private const val DEBUG = false

@JvmStatic fun start(application: Application, modules: List<Module>) {
@JvmStatic
fun start(application: Application, modules: List<Module>) {
startKoin {
if (BuildConfig.DEBUG && DEBUG) {
androidLogger()
Expand Down
10 changes: 6 additions & 4 deletions app/core/src/main/java/com/fsck/k9/K9.kt
Expand Up @@ -287,11 +287,13 @@ object K9 : EarlyInit {
}

fun init(context: Context) {
K9MailLib.setDebugStatus(object : K9MailLib.DebugStatus {
override fun enabled(): Boolean = isDebugLoggingEnabled
K9MailLib.setDebugStatus(
object : K9MailLib.DebugStatus {
override fun enabled(): Boolean = isDebugLoggingEnabled

override fun debugSensitive(): Boolean = isSensitiveDebugLoggingEnabled
})
override fun debugSensitive(): Boolean = isSensitiveDebugLoggingEnabled
},
)
com.fsck.k9.logging.Timber.logger = TimberLogger()

checkCachedDatabaseVersion(context)
Expand Down
1 change: 0 additions & 1 deletion app/core/src/main/java/com/fsck/k9/Preferences.kt
Expand Up @@ -8,7 +8,6 @@ import com.fsck.k9.preferences.AccountManager
import com.fsck.k9.preferences.Storage
import com.fsck.k9.preferences.StorageEditor
import com.fsck.k9.preferences.StoragePersister
import java.util.HashMap
import java.util.LinkedList
import java.util.UUID
import java.util.concurrent.CopyOnWriteArraySet
Expand Down
Expand Up @@ -23,7 +23,10 @@ class AutocryptTransferMessageCreator(private val stringProvider: AutocryptStrin
val textBodyPart = MimeBodyPart.create(TextBody(messageText))
val dataBodyPart = MimeBodyPart.create(BinaryMemoryBody(data, "7bit"))
dataBodyPart.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "application/autocrypt-setup")
dataBodyPart.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment; filename=\"autocrypt-setup-message\"")
dataBodyPart.setHeader(
MimeHeader.HEADER_CONTENT_DISPOSITION,
"attachment; filename=\"autocrypt-setup-message\"",
)

val messageBody = MimeMultipart.newInstance()
messageBody.addBodyPart(textBodyPart)
Expand Down
Expand Up @@ -12,7 +12,6 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import timber.log.Timber

Expand Down
Expand Up @@ -7,7 +7,6 @@ import android.content.Intent
import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED
import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED
import android.content.pm.PackageManager.DONT_KILL_APP
import java.lang.Exception
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import timber.log.Timber
Expand Down
Expand Up @@ -214,6 +214,7 @@ class PushController internal constructor(
account.folderPushMode != FolderMode.NONE && backendManager.getBackend(account).isPushCapable
}
}

private fun setPushNotificationState(notificationState: PushNotificationState) {
pushNotificationManager.notificationState = notificationState
}
Expand Down
Expand Up @@ -5,5 +5,5 @@ import java.util.concurrent.ThreadFactory
class NamedThreadFactory(private val threadNamePrefix: String) : ThreadFactory {
var counter: Int = 0

override fun newThread(runnable: Runnable) = Thread(runnable, "$threadNamePrefix-${ counter++ }")
override fun newThread(runnable: Runnable) = Thread(runnable, "$threadNamePrefix-${counter++}")
}
Expand Up @@ -20,7 +20,11 @@ class K9BackendStorageFactory(
account,
)
val specialFolderListener = SpecialFolderBackendFoldersRefreshListener(specialFolderUpdater)
val autoExpandFolderListener = AutoExpandFolderBackendFoldersRefreshListener(preferences, account, folderRepository)
val autoExpandFolderListener = AutoExpandFolderBackendFoldersRefreshListener(
preferences,
account,
folderRepository,
)
val listeners = listOf(specialFolderListener, autoExpandFolderListener)
return K9BackendStorage(messageStore, folderSettingsProvider, saveMessageDataCreator, listeners)
}
Expand Down
Expand Up @@ -4,7 +4,10 @@ import com.fsck.k9.Account
import com.fsck.k9.preferences.AccountManager
import java.util.concurrent.ConcurrentHashMap

class MessageStoreManager(private val accountManager: AccountManager, private val messageStoreFactory: MessageStoreFactory) {
class MessageStoreManager(
private val accountManager: AccountManager,
private val messageStoreFactory: MessageStoreFactory,
) {
private val messageStores = ConcurrentHashMap<String, ListenableMessageStore>()

init {
Expand Down
Expand Up @@ -17,7 +17,7 @@ object UriMatcher {
private const val SCHEME_SEPARATORS = "\\s(\\n<"
private const val ALLOWED_SEPARATORS_PATTERN = "(?:^|[$SCHEME_SEPARATORS])"
private val URI_SCHEME = Regex(
"$ALLOWED_SEPARATORS_PATTERN(${ SUPPORTED_URIS.keys.joinToString("|") })",
"$ALLOWED_SEPARATORS_PATTERN(${SUPPORTED_URIS.keys.joinToString("|")})",
RegexOption.IGNORE_CASE,
)

Expand Down
Expand Up @@ -19,7 +19,12 @@ val coreNotificationModule = module {
}
single { NotificationManagerCompat.from(get()) }
single {
NotificationHelper(context = get(), notificationManager = get(), notificationChannelManager = get(), resourceProvider = get())
NotificationHelper(
context = get(),
notificationManager = get(),
notificationChannelManager = get(),
resourceProvider = get(),
)
}
single {
NotificationChannelManager(
Expand Down
Expand Up @@ -18,7 +18,8 @@ class AutocryptDraftStateHeaderParserTest : RobolectricTest() {

@Test
fun testSignOnly() {
val parsedHeader = autocryptHeaderParser.parseAutocryptDraftStateHeader("encrypt=no; _by-choice=yes; _sign-only=yes")
val parsedHeader =
autocryptHeaderParser.parseAutocryptDraftStateHeader("encrypt=no; _by-choice=yes; _sign-only=yes")

with(parsedHeader!!) {
assertThat(isEncrypt).isFalse()
Expand All @@ -38,7 +39,8 @@ class AutocryptDraftStateHeaderParserTest : RobolectricTest() {

@Test
fun missingEncrypt() {
val parsedHeader = autocryptHeaderParser.parseAutocryptDraftStateHeader("encrpt-with-typo=no; _non_critical=value")
val parsedHeader =
autocryptHeaderParser.parseAutocryptDraftStateHeader("encrpt-with-typo=no; _non_critical=value")

assertThat(parsedHeader).isNull()
}
Expand Down
Expand Up @@ -383,25 +383,27 @@ class MessageListRepositoryTest {

private fun runMessageMapper(messages: Array<out MessageData>, mapper: MessageMapper<Any?>): List<Any> {
return messages.mapNotNull { message ->
mapper.map(object : MessageDetailsAccessor {
override val id = message.messageId
override val messageServerId = "irrelevant"
override val folderId = message.folderId
override val fromAddresses = emptyList<Address>()
override val toAddresses = emptyList<Address>()
override val ccAddresses = emptyList<Address>()
override val messageDate = 0L
override val internalDate = 0L
override val subject = "irrelevant"
override val preview = PreviewResult.error()
override val isRead = message.isRead
override val isStarred = message.isStarred
override val isAnswered = message.isAnswered
override val isForwarded = message.isForwarded
override val hasAttachments = false
override val threadRoot = message.threadRoot
override val threadCount = 0
})
mapper.map(
object : MessageDetailsAccessor {
override val id = message.messageId
override val messageServerId = "irrelevant"
override val folderId = message.folderId
override val fromAddresses = emptyList<Address>()
override val toAddresses = emptyList<Address>()
override val ccAddresses = emptyList<Address>()
override val messageDate = 0L
override val internalDate = 0L
override val subject = "irrelevant"
override val preview = PreviewResult.error()
override val isRead = message.isRead
override val isStarred = message.isStarred
override val isAnswered = message.isAnswered
override val isForwarded = message.isForwarded
override val hasAttachments = false
override val threadRoot = message.threadRoot
override val threadCount = 0
},
)
}
}

Expand Down
Expand Up @@ -35,7 +35,11 @@ fun createOAuthConfigurationProvider(): OAuthConfigurationProvider {
),
listOf("outlook.office365.com", "smtp.office365.com") to OAuthConfiguration(
clientId = BuildConfig.OAUTH_MICROSOFT_CLIENT_ID,
scopes = listOf("https://outlook.office.com/IMAP.AccessAsUser.All", "https://outlook.office.com/SMTP.Send", "offline_access"),
scopes = listOf(
"https://outlook.office.com/IMAP.AccessAsUser.All",
"https://outlook.office.com/SMTP.Send",
"offline_access",
),
authorizationEndpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
tokenEndpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/token",
redirectUri = BuildConfig.OAUTH_MICROSOFT_REDIRECT_URI,
Expand Down
Expand Up @@ -104,9 +104,10 @@ internal class K9NotificationActionCreator(
messageReferences: List<MessageReference>,
): PendingIntent {
val accountUuid = account.uuid
val intent = NotificationActionService.createMarkAllAsReadIntent(context, accountUuid, messageReferences).apply {
data = Uri.parse("data:,markAllAsRead/$accountUuid/${System.currentTimeMillis()}")
}
val intent =
NotificationActionService.createMarkAllAsReadIntent(context, accountUuid, messageReferences).apply {
data = Uri.parse("data:,markAllAsRead/$accountUuid/${System.currentTimeMillis()}")
}
return PendingIntent.getService(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
}

Expand Down Expand Up @@ -165,9 +166,10 @@ internal class K9NotificationActionCreator(
messageReferences: List<MessageReference>,
): PendingIntent {
val accountUuid = account.uuid
val intent = NotificationActionService.createDeleteAllMessagesIntent(context, accountUuid, messageReferences).apply {
data = Uri.parse("data:,deleteAll/$accountUuid/${System.currentTimeMillis()}")
}
val intent =
NotificationActionService.createDeleteAllMessagesIntent(context, accountUuid, messageReferences).apply {
data = Uri.parse("data:,deleteAll/$accountUuid/${System.currentTimeMillis()}")
}
return PendingIntent.getService(context, 0, intent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
}

Expand Down
Expand Up @@ -18,7 +18,8 @@ internal class MoveMessageOperations(
Timber.d("Moving message [ID: $messageId] to folder [ID: $destinationFolderId]")

return database.execute(true) { database ->
val threadInfo = threadMessageOperations.createOrUpdateParentThreadEntries(database, messageId, destinationFolderId)
val threadInfo =
threadMessageOperations.createOrUpdateParentThreadEntries(database, messageId, destinationFolderId)
val destinationMessageId = createMessageEntry(database, messageId, destinationFolderId, threadInfo)
threadMessageOperations.createThreadEntryIfNecessary(database, destinationMessageId, threadInfo)

Expand Down

0 comments on commit 82cb622

Please sign in to comment.