diff --git a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/Theme.kt b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/Theme.kt index 7048aabc..92aff4aa 100644 --- a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/Theme.kt +++ b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/models/Theme.kt @@ -22,6 +22,4 @@ enum class Theme(val value: String) { SYSTEM("system"), LIGHT("light"), DARK("dark"); - - fun indexOf() = entries.indexOf(this) } diff --git a/STCore/README.md b/STCore/README.md index ed9553b4..0928dadf 100644 --- a/STCore/README.md +++ b/STCore/README.md @@ -35,38 +35,38 @@ centralized access point to orchestrate transfer operations. | Type | Name | Description | |----------|--------------------|-------------------------------------------------------------------------------| -| Property | transferManager | A manager used to orchestrate transfer operations. | | 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: `transferManager` +#### Property: `appSettingsManager` -- **Type**: `TransferManager` +- **Type**: `AppSettingsManager` - **Description**: - - `transferManager` is a lazily initialized property that provides a manager to orchestrate all transfer operations. It - uses `realmProvider` and `apiClientProvider` to configure and manage transfers efficiently. + - `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 transferManager = core.transferManager - // Use the transferManager to orchestrate transfers + val appSettingsManager = core.appSettingsManager + // Use the appSettingsManager to orchestrate AppSettings related operations ``` -#### Property: `appSettingsManager` +#### Property: `transferManager` -- **Type**: `AppSettingsManager` +- **Type**: `TransferManager` - **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. + - `transferManager` is a lazily initialized property that provides a manager to orchestrate all transfer operations. It + uses `realmProvider` and `apiClientProvider` to configure and manage transfers efficiently. - **Usage Example**: ```kotlin val core = SwissTransferInjection() - val appSettingsManager = core.appSettingsManager - // Use the appSettingsManager to orchestrate AppSettings related operations + val transferManager = core.transferManager + // Use the transferManager to orchestrate transfers ``` #### Method: `loadDefaultAccount` 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 b7c82c1a..50f5e25d 100644 --- a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/SwissTransferInjection.kt +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/SwissTransferInjection.kt @@ -35,8 +35,8 @@ import com.infomaniak.multiplatform_swisstransfer.utils.Constants * * This class serves as the main access point. * - * @property transferManager A manager used to orchestrate transfer operations. * @property appSettingsManager A manager used to orchestrate AppSettings operations. + * @property transferManager A manager used to orchestrate transfer operations. */ class SwissTransferInjection { private val realmProvider by lazy { RealmProvider() } 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 index 9b22d5e8..cc739c8e 100644 --- a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/AppSettingsManager.kt +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/AppSettingsManager.kt @@ -29,6 +29,7 @@ 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 @@ -50,6 +51,9 @@ class AppSettingsManager internal constructor( * 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. */ suspend fun setTheme(theme: Theme) = withContext(Dispatchers.IO) { appSettingsController.setTheme(theme) @@ -59,6 +63,9 @@ class AppSettingsManager internal constructor( * 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. */ suspend fun setValidityPeriod(validityPeriod: ValidityPeriod) = withContext(Dispatchers.IO) { appSettingsController.setValidityPeriod(validityPeriod) @@ -68,6 +75,9 @@ class AppSettingsManager internal constructor( * 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. */ suspend fun setDownloadLimit(downloadLimit: DownloadLimit) = withContext(Dispatchers.IO) { appSettingsController.setDownloadLimit(downloadLimit) @@ -77,6 +87,9 @@ class AppSettingsManager internal constructor( * 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. */ suspend fun setEmailLanguage(emailLanguage: EmailLanguage) = withContext(Dispatchers.IO) { appSettingsController.setEmailLanguage(emailLanguage) 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 index 8f60f71f..ab0f98c9 100644 --- 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 @@ -37,8 +37,7 @@ class AppSettingsController(private val realmProvider: RealmProvider) { private val realm by lazy { realmProvider.realmAppSettings } - private val appSettingsQuery - get() = realm.query().first() + private val appSettingsQuery get() = realm.query().first() suspend fun initAppSettings() { if (appSettingsQuery.find() == 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 index 081e9fd5..7ad2a89d 100644 --- 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 @@ -55,9 +55,9 @@ class AppSettingsDB : RealmObject, AppSettings { } companion object { - private val DEFAULT_THEME = Theme.SYSTEM //TODO do we want the default theme of the phone ? + 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.FRENCH //TODO do we want the default language of the phone ? + private val DEFAULT_EMAIL_LANGUAGE = EmailLanguage.ENGLISH } }