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 152349c7..a68c282c 100644 --- a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/SwissTransferInjection.kt +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/SwissTransferInjection.kt @@ -19,12 +19,10 @@ package com.infomaniak.multiplatform_swisstransfer import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider import com.infomaniak.multiplatform_swisstransfer.database.controllers.AppSettingsController +import com.infomaniak.multiplatform_swisstransfer.database.controllers.FileController import com.infomaniak.multiplatform_swisstransfer.database.controllers.TransferController import com.infomaniak.multiplatform_swisstransfer.database.controllers.UploadController -import com.infomaniak.multiplatform_swisstransfer.managers.AccountManager -import com.infomaniak.multiplatform_swisstransfer.managers.AppSettingsManager -import com.infomaniak.multiplatform_swisstransfer.managers.TransferManager -import com.infomaniak.multiplatform_swisstransfer.managers.UploadManager +import com.infomaniak.multiplatform_swisstransfer.managers.* import com.infomaniak.multiplatform_swisstransfer.network.ApiClientProvider import com.infomaniak.multiplatform_swisstransfer.network.repositories.TransferRepository import com.infomaniak.multiplatform_swisstransfer.network.repositories.UploadRepository @@ -58,12 +56,16 @@ class SwissTransferInjection( private val appSettingsController by lazy { AppSettingsController(realmProvider) } private val uploadController by lazy { UploadController(realmProvider) } private val transferController by lazy { TransferController(realmProvider) } + private val fileController by lazy { FileController(realmProvider) } private val emailLanguageUtils by lazy { EmailLanguageUtils() } /** A manager used to orchestrate Transfers operations. */ val transferManager by lazy { TransferManager(apiClientProvider, transferController, transferRepository) } + /** A manager used to orchestrate Files operations. */ + val fileManager by lazy { FileManager(fileController) } + /** 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/FileManager.kt b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/FileManager.kt new file mode 100644 index 00000000..b4c8b985 --- /dev/null +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/FileManager.kt @@ -0,0 +1,37 @@ +/* + * 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.ui.FileUi +import com.infomaniak.multiplatform_swisstransfer.common.utils.mapToList +import com.infomaniak.multiplatform_swisstransfer.database.controllers.FileController +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map + +class FileManager(private val fileController: FileController) { + + /** + * Retrieves a flow of files contained in a folder with the specified folderUuid. + * + * @param folderUuid The UUID of the folder within the transfer. + * @return A flow of lists of [FileUi] objects representing the files in the transfer. + */ + fun getFilesFromTransfer(folderUuid: String): Flow?> { + return fileController.getFilesFromTransfer(folderUuid).map { files -> files.mapToList { FileUi(it) } } + } +} diff --git a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/TransferManager.kt b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/TransferManager.kt index e25fdf3c..f5d160e7 100644 --- a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/TransferManager.kt +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/TransferManager.kt @@ -20,7 +20,6 @@ package com.infomaniak.multiplatform_swisstransfer.managers import com.infomaniak.multiplatform_swisstransfer.common.exceptions.RealmException import com.infomaniak.multiplatform_swisstransfer.common.exceptions.UnknownException import com.infomaniak.multiplatform_swisstransfer.common.interfaces.transfers.Transfer -import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadSession import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection @@ -127,16 +126,6 @@ class TransferManager internal constructor( return transferController.getTransfer(transferUUID)?.let(::TransferUi) } - /** - * Retrieves a flow of files contained in a folder with the specified folderUuid. - * - * @param folderUuid The UUID of the folder within the transfer. - * @return A flow of lists of [FileUi] objects representing the files in the transfer. - */ - fun getFilesFromTransfer(folderUuid: String): Flow?> { - return transferController.getFilesFromTransfer(folderUuid).map { files -> files.mapToList { FileUi(it) } } - } - /** * Retrieves a transfer using the provided link UUID and saves it to the database. * diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/appSettings/AppSettingsDB.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/appSettings/AppSettingsDB.kt index bf1072d8..9e362d2f 100644 --- a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/appSettings/AppSettingsDB.kt +++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/appSettings/AppSettingsDB.kt @@ -22,12 +22,12 @@ import com.infomaniak.multiplatform_swisstransfer.common.models.* import io.realm.kotlin.types.RealmObject import io.realm.kotlin.types.annotations.Ignore -class AppSettingsDB(): RealmObject, AppSettings { +class AppSettingsDB() : RealmObject, AppSettings { @Ignore private var defaultEmailLanguage = EmailLanguage.ENGLISH - constructor(defaultEmailLanguage: EmailLanguage): this() { + constructor(defaultEmailLanguage: EmailLanguage) : this() { this.defaultEmailLanguage = defaultEmailLanguage }