Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6da770f2 authored by cketti's avatar cketti
Browse files

Extract common code and typealiases to `SettingDescriptionsHelper.kt`

parent 9aea286d
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
package com.fsck.k9.preferences

import com.fsck.k9.preferences.Settings.IntegerRangeSetting
import com.fsck.k9.preferences.Settings.SettingsDescription
import com.fsck.k9.preferences.Settings.StringSetting
import com.fsck.k9.preferences.upgrader.ServerSettingsUpgraderTo92
import com.fsck.k9.preferences.upgrader.ServerSettingsUpgraderTo94
import com.fsck.k9.preferences.upgrader.ServerSettingsUpgraderTo95
import java.util.TreeMap

/**
 * Contains information to validate imported server settings with a given content version, and to upgrade those server
@@ -14,7 +12,7 @@ import java.util.TreeMap
 */
@Suppress("MagicNumber")
internal class ServerSettingsDescriptions {
    val settings: Map<String, TreeMap<Int, SettingsDescription<*>?>> by lazy {
    val settings: SettingsDescriptions by lazy {
        mapOf(
            HOST to versions(
                1 to StringSetting(null),
@@ -100,7 +98,3 @@ internal class ServerSettingsDescriptions {
        const val CLIENT_CERTIFICATE_ALIAS = "clientCertificateAlias"
    }
}

private fun versions(vararg versions: Pair<Int, SettingsDescription<*>?>): TreeMap<Int, SettingsDescription<*>?> {
    return TreeMap(versions.toMap())
}
+11 −0
Original line number Diff line number Diff line
package com.fsck.k9.preferences

import com.fsck.k9.preferences.Settings.SettingsDescription
import java.util.TreeMap

internal typealias SettingDescriptionVersions = TreeMap<Int, SettingsDescription<*>?>
internal typealias SettingsDescriptions = Map<String, SettingDescriptionVersions>

internal fun versions(vararg pairs: Pair<Int, SettingsDescription<*>?>): SettingDescriptionVersions {
    return pairs.toMap(TreeMap<Int, SettingsDescription<*>?>())
}
+3 −4
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@ package com.fsck.k9.preferences

import com.fsck.k9.K9
import com.fsck.k9.preferences.Settings.SettingsDescription
import java.util.TreeMap
import timber.log.Timber

internal object SettingsUpgradeHelper {
@@ -24,7 +23,7 @@ internal object SettingsUpgradeHelper {
    fun upgrade(
        version: Int,
        upgraders: Map<Int, SettingsUpgrader>,
        settingsDescriptions: Map<String, TreeMap<Int, SettingsDescription<*>?>>,
        settingsDescriptions: SettingsDescriptions,
        settings: Map<String, Any?>,
    ): Map<String, Any?> {
        return upgradeToVersion(Settings.VERSION, version, upgraders, settingsDescriptions, settings)
@@ -34,7 +33,7 @@ internal object SettingsUpgradeHelper {
        targetVersion: Int,
        version: Int,
        upgraders: Map<Int, SettingsUpgrader>,
        settingsDescriptions: Map<String, TreeMap<Int, SettingsDescription<*>?>>,
        settingsDescriptions: SettingsDescriptions,
        settings: Map<String, Any?>,
    ): Map<String, Any?> {
        val upgradedSettings = settings.toMutableMap()
@@ -49,7 +48,7 @@ internal object SettingsUpgradeHelper {
    }

    private fun upgradeSettingsGeneric(
        settingsDescriptions: Map<String, TreeMap<Int, SettingsDescription<*>?>>,
        settingsDescriptions: SettingsDescriptions,
        mutableSettings: MutableMap<String, Any?>,
        toVersion: Int,
    ) {
+0 −6
Original line number Diff line number Diff line
@@ -245,10 +245,4 @@ class SettingsUpgradeHelperTest {
            ),
        )
    }

    private fun versions(
        vararg pairs: Pair<Int, SettingsDescription<*>?>,
    ): TreeMap<Int, SettingsDescription<*>?> {
        return pairs.toMap(TreeMap<Int, SettingsDescription<*>?>())
    }
}