From 1a39aad59a9e062f88c38db3571c93194a2cc0f6 Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Thu, 17 Oct 2024 10:53:11 +0200 Subject: [PATCH 1/2] feat: Add a list utils extension --- .../common/utils/ListExt.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/utils/ListExt.kt diff --git a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/utils/ListExt.kt b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/utils/ListExt.kt new file mode 100644 index 00000000..faa3c961 --- /dev/null +++ b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/utils/ListExt.kt @@ -0,0 +1,22 @@ +/* + * 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.utils + +inline fun Iterable.mapToList(transform: (T) -> R): List { + return mapTo(mutableListOf(), transform) +} From 979ddec7c883a677203cc5be1d0752c281ef3662 Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Thu, 17 Oct 2024 10:55:32 +0200 Subject: [PATCH 2/2] feat: Update with list extensions --- .../common/interfaces/ui/TransferUi.kt | 3 ++- .../multiplatform_swisstransfer/managers/TransferManager.kt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/ui/TransferUi.kt b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/ui/TransferUi.kt index 07468e28..27a176b6 100644 --- a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/ui/TransferUi.kt +++ b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/ui/TransferUi.kt @@ -19,6 +19,7 @@ package com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui import com.infomaniak.multiplatform_swisstransfer.common.interfaces.transfers.Transfer import com.infomaniak.multiplatform_swisstransfer.common.utils.DateUtils +import com.infomaniak.multiplatform_swisstransfer.common.utils.mapToList data class TransferUi( val uuid: String, @@ -40,6 +41,6 @@ data class TransferUi( downloadLimit = transfer.container?.downloadLimit ?: 0, downloadLeft = transfer.downloadCounterCredit, message = transfer.container?.message, - files = transfer.container?.files?.mapTo(mutableListOf()) { FileUi(it) } ?: emptyList() + files = transfer.container?.files?.mapToList { FileUi(it) } ?: emptyList() ) } 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 a5da446b..746b5a45 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 @@ -22,6 +22,7 @@ import com.infomaniak.multiplatform_swisstransfer.common.exceptions.UnknownExcep import com.infomaniak.multiplatform_swisstransfer.common.interfaces.transfers.Transfer import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection +import com.infomaniak.multiplatform_swisstransfer.common.utils.mapToList import com.infomaniak.multiplatform_swisstransfer.database.controllers.TransferController import com.infomaniak.multiplatform_swisstransfer.network.ApiClientProvider import com.infomaniak.multiplatform_swisstransfer.network.exceptions.ApiException @@ -67,7 +68,7 @@ class TransferManager internal constructor( @Throws(RealmException::class) fun getTransfers(transferDirection: TransferDirection): Flow> { return transferController.getTransfersFlow(transferDirection) - .map { it.mapTo(mutableListOf()) { transfer -> TransferUi(transfer) } } + .map { it.mapToList { transfer -> TransferUi(transfer) } } .flowOn(Dispatchers.IO) }