Skip to content

Commit

Permalink
Merge pull request #40 from Infomaniak/list-utils
Browse files Browse the repository at this point in the history
chore: Add ListExt in common to simplify the use of lists
  • Loading branch information
tevincent authored Oct 17, 2024
2 parents 45b67d1 + 979ddec commit a03a76a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
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

0 comments on commit a03a76a

Please sign in to comment.