Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add ListExt in common to simplify the use of lists #40

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
)
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.multiplatform_swisstransfer.common.utils

inline fun <T, R> Iterable<T>.mapToList(transform: (T) -> R): List<R> {
return mapTo(mutableListOf(), transform)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,7 +68,7 @@ class TransferManager internal constructor(
@Throws(RealmException::class)
fun getTransfers(transferDirection: TransferDirection): Flow<List<TransferUi>> {
return transferController.getTransfersFlow(transferDirection)
.map { it.mapTo(mutableListOf()) { transfer -> TransferUi(transfer) } }
.map { it.mapToList { transfer -> TransferUi(transfer) } }
.flowOn(Dispatchers.IO)
}

Expand Down
Loading