Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Aug 29, 2024
1 parent 35620af commit 7b989d5
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ enum class Theme(val value: String) {
SYSTEM("system"),
LIGHT("light"),
DARK("dark");

fun indexOf() = entries.indexOf(this)
}
26 changes: 13 additions & 13 deletions STCore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class AppSettingsController(private val realmProvider: RealmProvider) {

private val realm by lazy { realmProvider.realmAppSettings }

private val appSettingsQuery
get() = realm.query<AppSettingsDB>().first()
private val appSettingsQuery get() = realm.query<AppSettingsDB>().first()

suspend fun initAppSettings() {
if (appSettingsQuery.find() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 7b989d5

Please sign in to comment.