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

Unverified Commit 55fa9f80 authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé
Browse files

refactor(core-preference): move StorageEditor, StoragePersistor and StorageUpdater to api module

parent bccbd6fe
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@ dependencies {
    api(libs.junit)
    api(libs.robolectric)

    implementation(projects.core.preference.api)

    implementation(projects.legacy.core)

    api(libs.koin.core)
+3 −3
Original line number Diff line number Diff line
package net.thunderbird.core.android.preferences

import com.fsck.k9.preferences.DefaultStorage
import com.fsck.k9.preferences.StorageEditor
import com.fsck.k9.preferences.StoragePersister
import com.fsck.k9.preferences.StorageUpdater
import net.thunderbird.core.preference.storage.Storage
import net.thunderbird.core.preference.storage.StorageEditor
import net.thunderbird.core.preference.storage.StoragePersister
import net.thunderbird.core.preference.storage.StorageUpdater

class InMemoryStoragePersister : StoragePersister {
    private val values = mutableMapOf<String, Any?>()
+61 −0
Original line number Diff line number Diff line
package net.thunderbird.core.preference.storage

/**
 * Interface for editing the storage.
 *
 * This interface provides methods to put various types of values into the storage,
 * remove values, and commit the changes.
 */
interface StorageEditor {

    /**
     * Puts a boolean value into the storage.
     *
     * @param key The key for the value.
     * @param value The boolean value to put.
     * @return The StorageEditor instance for chaining.
     */
    fun putBoolean(key: String, value: Boolean): StorageEditor

    /**
     * Puts an integer value into the storage.
     *
     * @param key The key for the value.
     * @param value The integer value to put.
     * @return The StorageEditor instance for chaining.
     */
    fun putInt(key: String, value: Int): StorageEditor

    /**
     * Puts a long value into the storage.
     *
     * @param key The key for the value.
     * @param value The long value to put.
     * @return The StorageEditor instance for chaining.
     */
    fun putLong(key: String, value: Long): StorageEditor

    /**
     * Puts a string value into the storage.
     *
     * @param key The key for the value.
     * @param value The string value to put. If null, the key will be removed.
     * @return The StorageEditor instance for chaining.
     */
    fun putString(key: String, value: String?): StorageEditor

    /**
     * Removes a value from the storage.
     *
     * @param key The key for the value to remove.
     * @return The StorageEditor instance for chaining.
     */
    fun remove(key: String): StorageEditor

    /**
     * Commits the changes made to the storage.
     *
     * @return true if the commit was successful, false otherwise.
     */
    fun commit(): Boolean
}
+12 −0
Original line number Diff line number Diff line
package net.thunderbird.core.preference.storage

/**
 * Extension functions for the [StorageEditor] interface to simplify putting enum values.
 *
 * @param T The type of the enum.
 * @param key The key under which the enum value will be stored.
 * @param value The enum value to be stored.
 */
inline fun <reified T : Enum<T>> StorageEditor.putEnum(key: String, value: T) {
    putString(key, value.name)
}
+26 −0
Original line number Diff line number Diff line
package net.thunderbird.core.preference.storage

/**
 * Represents a mechanism for persisting storage data.
 *
 * This interface provides methods to:
 * - Load the current storage values.
 * - Create a storage editor for applying updates to the storage.
 */
interface StoragePersister {

    /**
     * Loads the storage values.
     *
     * @return The loaded storage.
     */
    fun loadValues(): Storage

    /**
     * Creates a storage editor for updating the storage.
     *
     * @param storageUpdater The updater to apply changes to the storage.
     * @return A new instance of [StorageEditor].
     */
    fun createStorageEditor(storageUpdater: StorageUpdater): StorageEditor
}
Loading