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

Unverified Commit 3eb6ec42 authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé
Browse files

feat(core-preference): add LegacyProfileDtoStorageHandler to legacy module

parent f01b6e29
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -25,9 +25,15 @@ val featureAccountStorageLegacyModule = module {

    factory { ServerSettingsDtoSerializer() }

    single {
    factory<ProfileDtoStorageHandler> {
        LegacyProfileDtoStorageHandler(
        )
    }

    single<StorageHandler<LegacyAccount>> {
        LegacyAccountStorageHandler(
            serverSettingsDtoSerializer = get(),
            profileDtoStorageHandler = get(),
            logger = get(),
        )
    }
+1 −9
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import net.thunderbird.feature.notification.VibratePattern

class LegacyAccountStorageHandler(
    private val serverSettingsDtoSerializer: ServerSettingsDtoSerializer,
    private val profileDtoStorageHandler: LegacyProfileDtoStorageHandler,
    private val logger: Logger,
) : StorageHandler<LegacyAccount> {

@@ -42,7 +43,6 @@ class LegacyAccountStorageHandler(
                storage.getStringOrDefault(keyGen.create(OUTGOING_SERVER_SETTINGS_KEY), ""),
            )
            oAuthState = storage.getStringOrNull(keyGen.create("oAuthState"))
            name = storage.getStringOrNull(keyGen.create("description"))
            alwaysBcc = storage.getStringOrNull(keyGen.create("alwaysBcc")) ?: alwaysBcc
            automaticCheckIntervalMinutes = storage.getInt(
                keyGen.create("automaticCheckIntervalMinutes"),
@@ -182,8 +182,6 @@ class LegacyAccountStorageHandler(
                AccountDefaultsProvider.Companion.UNASSIGNED_ACCOUNT_NUMBER,
            )

            chipColor = storage.getInt(keyGen.create("chipColor"), FALLBACK_ACCOUNT_COLOR)

            sortType = getEnumStringPref<SortType>(storage, keyGen.create("sortTypeEnum"), SortType.SORT_DATE)

            setSortAscending(sortType, storage.getBoolean(keyGen.create("sortAscending"), false))
@@ -325,7 +323,6 @@ class LegacyAccountStorageHandler(
                serverSettingsDtoSerializer.serialize(outgoingServerSettings),
            )
            editor.putString(keyGen.create("oAuthState"), oAuthState)
            editor.putString(keyGen.create("description"), name)
            editor.putString(keyGen.create("alwaysBcc"), alwaysBcc)
            editor.putInt(keyGen.create("automaticCheckIntervalMinutes"), automaticCheckIntervalMinutes)
            editor.putInt(keyGen.create("idleRefreshMinutes"), idleRefreshMinutes)
@@ -369,7 +366,6 @@ class LegacyAccountStorageHandler(
            editor.putString(keyGen.create("expungePolicy"), expungePolicy.name)
            editor.putBoolean(keyGen.create("syncRemoteDeletions"), isSyncRemoteDeletions)
            editor.putInt(keyGen.create("maxPushFolders"), maxPushFolders)
            editor.putInt(keyGen.create("chipColor"), chipColor)
            editor.putBoolean(keyGen.create("subscribedFoldersOnly"), isSubscribedFoldersOnly)
            editor.putInt(keyGen.create("maximumPolledMessageAge"), maximumPolledMessageAge)
            editor.putInt(keyGen.create("maximumAutoDownloadMessageSize"), maximumAutoDownloadMessageSize)
@@ -450,7 +446,6 @@ class LegacyAccountStorageHandler(
        editor.remove(keyGen.create(INCOMING_SERVER_SETTINGS_KEY))
        editor.remove(keyGen.create(OUTGOING_SERVER_SETTINGS_KEY))
        editor.remove(keyGen.create("description"))
        editor.remove(keyGen.create("name"))
        editor.remove(keyGen.create("email"))
        editor.remove(keyGen.create("alwaysBcc"))
        editor.remove(keyGen.create("automaticCheckIntervalMinutes"))
@@ -485,7 +480,6 @@ class LegacyAccountStorageHandler(
        editor.remove(keyGen.create("expungePolicy"))
        editor.remove(keyGen.create("syncRemoteDeletions"))
        editor.remove(keyGen.create("maxPushFolders"))
        editor.remove(keyGen.create("chipColor"))
        editor.remove(keyGen.create("notificationLight"))
        editor.remove(keyGen.create("subscribedFoldersOnly"))
        editor.remove(keyGen.create("maximumPolledMessageAge"))
@@ -617,7 +611,5 @@ class LegacyAccountStorageHandler(
        const val IDENTITY_NAME_KEY = "name"
        const val IDENTITY_EMAIL_KEY = "email"
        const val IDENTITY_DESCRIPTION_KEY = "description"

        const val FALLBACK_ACCOUNT_COLOR = 0x0099CC
    }
}
+53 −0
Original line number Diff line number Diff line
package net.thunderbird.feature.account.storage.legacy

import net.thunderbird.core.android.account.LegacyAccount
import net.thunderbird.core.preference.storage.Storage
import net.thunderbird.core.preference.storage.StorageEditor

class LegacyProfileDtoStorageHandler(
) : ProfileDtoStorageHandler {

    override fun load(
        data: LegacyAccount,
        storage: Storage,
    ) {
        val keyGen = AccountKeyGenerator(data.id)

        with(data) {
            name = storage.getStringOrNull(keyGen.create(KEY_NAME))
            chipColor = storage.getInt(keyGen.create(KEY_COLOR), FALLBACK_ACCOUNT_COLOR)
        }
    }

    override fun save(
        data: LegacyAccount,
        storage: Storage,
        editor: StorageEditor,
    ) {
        val keyGen = AccountKeyGenerator(data.id)

        with(data) {
            editor.putString(keyGen.create(KEY_NAME), name)
            editor.putInt(keyGen.create(KEY_COLOR), chipColor)
        }
    }

    override fun delete(
        data: LegacyAccount,
        storage: Storage,
        editor: StorageEditor,
    ) {
        val keyGen = AccountKeyGenerator(data.id)

        editor.remove(keyGen.create(KEY_NAME))
        editor.remove(keyGen.create(KEY_COLOR))
    }

    private companion object Companion {
        const val KEY_COLOR = "chipColor"
        const val KEY_NAME = "description"

        // TODO why?
        const val FALLBACK_ACCOUNT_COLOR = 0x0099CC
    }
}
+3 −0
Original line number Diff line number Diff line
package net.thunderbird.feature.account.storage.legacy

import androidx.annotation.Discouraged
import net.thunderbird.core.android.account.LegacyAccount
import net.thunderbird.core.preference.storage.Storage
import net.thunderbird.core.preference.storage.StorageEditor

@@ -41,3 +42,5 @@ interface StorageHandler<T> {
    fun delete(data: T, storage: Storage, editor: StorageEditor)
}

interface ProfileDtoStorageHandler : StorageHandler<LegacyAccount>