diff --git a/STCommon/build.gradle.kts b/STCommon/build.gradle.kts
index a85f8ea3..b7dc270e 100644
--- a/STCommon/build.gradle.kts
+++ b/STCommon/build.gradle.kts
@@ -2,6 +2,7 @@ plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
id("infomaniak.kotlinMultiplatform")
+ id("infomaniak.publishPlugin")
}
kotlin {
diff --git a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/appSettings/AppSettings.kt b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/appSettings/AppSettings.kt
new file mode 100644
index 00000000..9bd662b8
--- /dev/null
+++ b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/appSettings/AppSettings.kt
@@ -0,0 +1,31 @@
+/*
+ * Infomaniak SwissTransfer - Multiplatform
+ * Copyright (C) 2024 Infomaniak Network SA
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings
+
+import com.infomaniak.multiplatform_swisstransfer.common.models.DownloadLimit
+import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage
+import com.infomaniak.multiplatform_swisstransfer.common.models.Theme
+import com.infomaniak.multiplatform_swisstransfer.common.models.ValidityPeriod
+
+interface AppSettings {
+ var theme: Theme
+ var validityPeriod: ValidityPeriod
+ var downloadLimit: DownloadLimit
+ var emailLanguage: EmailLanguage
+}
diff --git a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/DownloadLimit.kt b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/DownloadLimit.kt
new file mode 100644
index 00000000..543c4a12
--- /dev/null
+++ b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/DownloadLimit.kt
@@ -0,0 +1,26 @@
+/*
+ * Infomaniak SwissTransfer - Multiplatform
+ * Copyright (C) 2024 Infomaniak Network SA
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.infomaniak.multiplatform_swisstransfer.common.models
+
+enum class DownloadLimit(val value: String) {
+ TWOHUNDREDFIFTY("250"),
+ ONEHUNDRED("100"),
+ TWENTY("20"),
+ ONE("1");
+}
diff --git a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/EmailLanguage.kt b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/EmailLanguage.kt
new file mode 100644
index 00000000..7fa74c9b
--- /dev/null
+++ b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/EmailLanguage.kt
@@ -0,0 +1,27 @@
+/*
+ * Infomaniak SwissTransfer - Multiplatform
+ * Copyright (C) 2024 Infomaniak Network SA
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.infomaniak.multiplatform_swisstransfer.common.models
+
+enum class EmailLanguage(val value: String) {
+ ENGLISH("english"),
+ FRENCH("french"),
+ GERMAN("german"),
+ ITALIAN("italian"),
+ SPANISH("spanish");
+}
diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/setting/AppSettings.kt b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/Theme.kt
similarity index 80%
rename from STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/setting/AppSettings.kt
rename to STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/Theme.kt
index 5d43f19b..92aff4aa 100644
--- a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/setting/AppSettings.kt
+++ b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/Theme.kt
@@ -16,10 +16,10 @@
* along with this program. If not, see .
*/
-package com.infomaniak.multiplatform_swisstransfer.database.models.setting
+package com.infomaniak.multiplatform_swisstransfer.common.models
-import io.realm.kotlin.types.RealmObject
-
-class AppSettings : RealmObject {
- //TODO: implement here
+enum class Theme(val value: String) {
+ SYSTEM("system"),
+ LIGHT("light"),
+ DARK("dark");
}
diff --git a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/ValidityPeriod.kt b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/ValidityPeriod.kt
new file mode 100644
index 00000000..8e2aea31
--- /dev/null
+++ b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/ValidityPeriod.kt
@@ -0,0 +1,26 @@
+/*
+ * Infomaniak SwissTransfer - Multiplatform
+ * Copyright (C) 2024 Infomaniak Network SA
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.infomaniak.multiplatform_swisstransfer.common.models
+
+enum class ValidityPeriod(val value: String) {
+ THIRTY("30"),
+ FIFTEEN("15"),
+ SEVEN("7"),
+ ONE("1");
+}
diff --git a/STCore/README.md b/STCore/README.md
index 85fec921..0928dadf 100644
--- a/STCore/README.md
+++ b/STCore/README.md
@@ -35,11 +35,26 @@ centralized access point to orchestrate transfer operations.
| Type | Name | Description |
|----------|--------------------|-------------------------------------------------------------------------------|
+| Property | appSettingsManager | A manager used to orchestrate AppSettings operations. |
| Property | transferManager | A manager used to orchestrate transfer operations. |
| Method | loadDefaultAccount | Loads the default user account and initializes Realm transfers for this user. |
### Details of Properties and Methods
+#### Property: `appSettingsManager`
+
+- **Type**: `AppSettingsManager`
+- **Description**:
+ - `appSettingsManager` is a lazily initialized property that provides a manager to orchestrate all AppSettings operations. It
+ uses `realmProvider` to configure and manage AppSettings efficiently.
+
+- **Usage Example**:
+ ```kotlin
+ val core = SwissTransferInjection()
+ val appSettingsManager = core.appSettingsManager
+ // Use the appSettingsManager to orchestrate AppSettings related operations
+ ```
+
#### Property: `transferManager`
- **Type**: `TransferManager`
diff --git a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/SwissTransferInjection.kt b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/SwissTransferInjection.kt
index f7e8363e..50f5e25d 100644
--- a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/SwissTransferInjection.kt
+++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/SwissTransferInjection.kt
@@ -19,6 +19,8 @@
package com.infomaniak.multiplatform_swisstransfer
import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider
+import com.infomaniak.multiplatform_swisstransfer.database.cache.setting.AppSettingsController
+import com.infomaniak.multiplatform_swisstransfer.managers.AppSettingsManager
import com.infomaniak.multiplatform_swisstransfer.managers.TransferManager
import com.infomaniak.multiplatform_swisstransfer.network.ApiClientProvider
import com.infomaniak.multiplatform_swisstransfer.network.repositories.TransferRepository
@@ -33,6 +35,7 @@ import com.infomaniak.multiplatform_swisstransfer.utils.Constants
*
* This class serves as the main access point.
*
+ * @property appSettingsManager A manager used to orchestrate AppSettings operations.
* @property transferManager A manager used to orchestrate transfer operations.
*/
class SwissTransferInjection {
@@ -42,14 +45,20 @@ class SwissTransferInjection {
private val transferRepository by lazy { TransferRepository(apiClientProvider) }
private val uploadRepository by lazy { UploadRepository(apiClientProvider) }
+ private val appSettingsController by lazy { AppSettingsController(realmProvider) }
+
/**
* Loads the default user account and initializes Realm transfers for the default user ID defined in the constants.
*/
@Throws(IllegalArgumentException::class, IllegalStateException::class)
- fun loadDefaultAccount() {
+ suspend fun loadDefaultAccount() {
+ appSettingsController.initAppSettings()
realmProvider.loadRealmTransfers(Constants.DEFAULT_USER_ID)
}
/** A manager used to orchestrate transfer operations. */
val transferManager by lazy { TransferManager(realmProvider, apiClientProvider) }
+
+ /** A manager used to orchestrate AppSettings operations. */
+ val appSettingsManager by lazy { AppSettingsManager(appSettingsController) }
}
diff --git a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/AppSettingsManager.kt b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/AppSettingsManager.kt
new file mode 100644
index 00000000..1c6d155a
--- /dev/null
+++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/AppSettingsManager.kt
@@ -0,0 +1,101 @@
+/*
+ * Infomaniak SwissTransfer - Multiplatform
+ * Copyright (C) 2024 Infomaniak Network SA
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.infomaniak.multiplatform_swisstransfer.managers
+
+import com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings.AppSettings
+import com.infomaniak.multiplatform_swisstransfer.common.models.DownloadLimit
+import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage
+import com.infomaniak.multiplatform_swisstransfer.common.models.Theme
+import com.infomaniak.multiplatform_swisstransfer.common.models.ValidityPeriod
+import com.infomaniak.multiplatform_swisstransfer.database.cache.setting.AppSettingsController
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.IO
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.flowOn
+import kotlinx.coroutines.withContext
+import kotlin.coroutines.cancellation.CancellationException
+
+/**
+ * Provides a convenient interface for managing application settings, abstracting the underlying
+ * [AppSettingsController]. It handles asynchronous operations and ensures settings updates are
+ * performed on a background thread.
+ **/
+class AppSettingsManager internal constructor(
+ private val appSettingsController: AppSettingsController,
+) {
+
+ /**
+ * A [Flow] that emits the current [AppSettings] object whenever it changes. This flow operates
+ * on the [Dispatchers.IO] context to avoid blocking the main thread.
+ */
+ val appSettings: Flow
+ get() = appSettingsController.getAppSettingsFlow().flowOn(Dispatchers.IO)
+
+ /**
+ * Asynchronously sets the application theme.
+ *
+ * @param theme The new theme to apply.
+ *
+ * @throws IllegalArgumentException If the provided theme is invalid.
+ * @throws CancellationException If the operation is cancelled.
+ */
+ @Throws(IllegalArgumentException::class, CancellationException::class)
+ suspend fun setTheme(theme: Theme) = withContext(Dispatchers.IO) {
+ appSettingsController.setTheme(theme)
+ }
+
+ /**
+ * Asynchronously sets the validity period for certain application features.
+ *
+ * @param validityPeriod The new validity period.
+ *
+ * @throws IllegalArgumentException If the provided validity period is invalid.
+ * @throws CancellationException If the operation is cancelled.
+ */
+ @Throws(IllegalArgumentException::class, CancellationException::class)
+ suspend fun setValidityPeriod(validityPeriod: ValidityPeriod) = withContext(Dispatchers.IO) {
+ appSettingsController.setValidityPeriod(validityPeriod)
+ }
+
+ /**
+ * Asynchronously sets the download limit for files.
+ *
+ * @param downloadLimit The new download limit.
+ *
+ * @throws IllegalArgumentException If the provided download limit is invalid.
+ * @throws CancellationException If the operation is cancelled.
+ */
+ @Throws(IllegalArgumentException::class, CancellationException::class)
+ suspend fun setDownloadLimit(downloadLimit: DownloadLimit) = withContext(Dispatchers.IO) {
+ appSettingsController.setDownloadLimit(downloadLimit)
+ }
+
+ /**
+ * Asynchronously sets the language for email communications.
+ *
+ * @param emailLanguage The new email language.
+ *
+ * @throws IllegalArgumentException If the provided email language is invalid.
+ * @throws CancellationException If the operation is cancelled.
+ */
+ @Throws(IllegalArgumentException::class, CancellationException::class)
+ suspend fun setEmailLanguage(emailLanguage: EmailLanguage) = withContext(Dispatchers.IO) {
+ appSettingsController.setEmailLanguage(emailLanguage)
+ }
+}
diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/RealmProvider.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/RealmProvider.kt
index 283dce54..935f219d 100644
--- a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/RealmProvider.kt
+++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/RealmProvider.kt
@@ -21,7 +21,7 @@ package com.infomaniak.multiplatform_swisstransfer.database
import com.infomaniak.multiplatform_swisstransfer.database.models.ContainerDB
import com.infomaniak.multiplatform_swisstransfer.database.models.FileDB
import com.infomaniak.multiplatform_swisstransfer.database.models.TransferDB
-import com.infomaniak.multiplatform_swisstransfer.database.models.setting.AppSettings
+import com.infomaniak.multiplatform_swisstransfer.database.models.setting.AppSettingsDB
import com.infomaniak.multiplatform_swisstransfer.database.models.upload.UploadTasks
import io.realm.kotlin.Realm
import io.realm.kotlin.RealmConfiguration
@@ -62,7 +62,7 @@ class RealmProvider {
}
private val realmAppSettingsConfiguration = RealmConfiguration
- .Builder(schema = setOf(AppSettings::class))
+ .Builder(schema = setOf(AppSettingsDB::class))
.name("AppSettings")
.build()
diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/AppSettingsController.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/AppSettingsController.kt
new file mode 100644
index 00000000..ab0f98c9
--- /dev/null
+++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/AppSettingsController.kt
@@ -0,0 +1,100 @@
+/*
+ * Infomaniak SwissTransfer - Multiplatform
+ * Copyright (C) 2024 Infomaniak Network SA
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.infomaniak.multiplatform_swisstransfer.database.cache.setting
+
+import com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings.AppSettings
+import com.infomaniak.multiplatform_swisstransfer.common.models.DownloadLimit
+import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage
+import com.infomaniak.multiplatform_swisstransfer.common.models.Theme
+import com.infomaniak.multiplatform_swisstransfer.common.models.ValidityPeriod
+import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider
+import com.infomaniak.multiplatform_swisstransfer.database.models.setting.AppSettingsDB
+import io.realm.kotlin.UpdatePolicy
+import io.realm.kotlin.ext.query
+import kotlin.coroutines.cancellation.CancellationException
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.mapLatest
+
+@OptIn(ExperimentalCoroutinesApi::class)
+class AppSettingsController(private val realmProvider: RealmProvider) {
+
+ private val realm by lazy { realmProvider.realmAppSettings }
+
+ private val appSettingsQuery get() = realm.query().first()
+
+ suspend fun initAppSettings() {
+ if (appSettingsQuery.find() == null) {
+ realm.write {
+ copyToRealm(AppSettingsDB(), UpdatePolicy.ALL)
+ }
+ }
+ }
+
+ //region Get data
+
+ fun getAppSettingsFlow(): Flow {
+ return appSettingsQuery.asFlow().mapLatest { it.obj }
+ }
+
+ //endregion
+
+ //region Update data
+
+ @Throws(IllegalArgumentException::class, CancellationException::class)
+ private suspend fun updateAppSettings(onUpdate: (AppSettings) -> Unit) {
+ val appSettings = appSettingsQuery.find() ?: return
+
+ realm.write {
+ findLatest(appSettings)?.let { mutableAppSettings ->
+ onUpdate(mutableAppSettings)
+ }
+ }
+ }
+
+ @Throws(IllegalArgumentException::class, CancellationException::class)
+ suspend fun setTheme(theme: Theme) {
+ updateAppSettings { mutableAppSettings ->
+ mutableAppSettings.theme = theme
+ }
+ }
+
+ @Throws(IllegalArgumentException::class, CancellationException::class)
+ suspend fun setValidityPeriod(validityPeriod: ValidityPeriod) {
+ updateAppSettings { mutableAppSettings ->
+ mutableAppSettings.validityPeriod = validityPeriod
+ }
+ }
+
+ @Throws(IllegalArgumentException::class, CancellationException::class)
+ suspend fun setDownloadLimit(downloadLimit: DownloadLimit) {
+ updateAppSettings { mutableAppSettings ->
+ mutableAppSettings.downloadLimit = downloadLimit
+ }
+ }
+
+ @Throws(IllegalArgumentException::class, CancellationException::class)
+ suspend fun setEmailLanguage(emailLanguage: EmailLanguage) {
+ updateAppSettings { mutableAppSettings ->
+ mutableAppSettings.emailLanguage = emailLanguage
+ }
+ }
+
+ //endregion
+}
diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/TransferDB.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/TransferDB.kt
index ab5da68e..24618a2d 100644
--- a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/TransferDB.kt
+++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/TransferDB.kt
@@ -22,7 +22,7 @@ import com.infomaniak.multiplatform_swisstransfer.common.interfaces.Transfer
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.PrimaryKey
-class TransferDB : Transfer, RealmObject {
+class TransferDB : Transfer, RealmObject {
@PrimaryKey
override var linkUUID: String = ""
override var containerUUID: String = ""
@@ -32,5 +32,5 @@ class TransferDB : Transfer, RealmObject {
override var isDownloadOnetime: Long = 0 // TODO: Boolean ?
override var isMailSent: Boolean = false
override var downloadHost: String = ""
- override var container: ContainerDB = ContainerDB()
+ override var container: ContainerDB? = null
}
diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/setting/AppSettingsDB.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/setting/AppSettingsDB.kt
new file mode 100644
index 00000000..7ad2a89d
--- /dev/null
+++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/setting/AppSettingsDB.kt
@@ -0,0 +1,63 @@
+/*
+ * Infomaniak SwissTransfer - Multiplatform
+ * Copyright (C) 2024 Infomaniak Network SA
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.infomaniak.multiplatform_swisstransfer.database.models.setting
+
+import com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings.AppSettings
+import com.infomaniak.multiplatform_swisstransfer.common.models.DownloadLimit
+import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage
+import com.infomaniak.multiplatform_swisstransfer.common.models.Theme
+import com.infomaniak.multiplatform_swisstransfer.common.models.ValidityPeriod
+import io.realm.kotlin.types.RealmObject
+
+class AppSettingsDB : RealmObject, AppSettings {
+ private var _theme: String = Theme.SYSTEM.value
+ override var theme: Theme
+ get() = Theme.entries.find { it.value == _theme } ?: DEFAULT_THEME
+ set(value) {
+ _theme = value.value
+ }
+
+ private var _validityPeriod: String = ValidityPeriod.THIRTY.value
+ override var validityPeriod: ValidityPeriod
+ get() = ValidityPeriod.entries.find { it.value == _validityPeriod } ?: DEFAULT_VALIDITY_PERIOD
+ set(value) {
+ _validityPeriod = value.value
+ }
+
+ private var _downloadLimit: String = DownloadLimit.TWOHUNDREDFIFTY.value
+ override var downloadLimit: DownloadLimit
+ get() = DownloadLimit.entries.find { it.value == _downloadLimit } ?: DEFAULT_DOWNLOAD_LIMIT
+ set(value) {
+ _downloadLimit = value.value
+ }
+
+ private var _emailLanguage: String = DEFAULT_EMAIL_LANGUAGE.value
+ override var emailLanguage: EmailLanguage
+ get() = EmailLanguage.entries.find { it.value == _emailLanguage } ?: DEFAULT_EMAIL_LANGUAGE
+ set(value) {
+ _emailLanguage = value.value
+ }
+
+ companion object {
+ private val DEFAULT_THEME = Theme.SYSTEM
+ private val DEFAULT_VALIDITY_PERIOD = ValidityPeriod.THIRTY
+ private val DEFAULT_DOWNLOAD_LIMIT = DownloadLimit.TWOHUNDREDFIFTY
+ private val DEFAULT_EMAIL_LANGUAGE = EmailLanguage.ENGLISH
+ }
+}