Skip to content

Commit

Permalink
refactor: Move expiry check to TransferUiExt
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Nov 7, 2024
1 parent 9662068 commit 968a3b8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.HumanReadableSizeUtils
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows
import com.infomaniak.swisstransfer.ui.utils.isExpired
import java.util.Calendar
import java.util.Date
import java.util.UUID
Expand All @@ -47,15 +48,12 @@ import java.util.UUID
fun TransferItem(transfer: TransferUi, onClick: () -> Unit) {

val createdDate = Date(transfer.createdDateTimestamp).format(FORMAT_DATE_TITLE)
val remainingDays = transfer.expiresInDays
val remainingDownloads = transfer.downloadLeft
val uploadedSize = HumanReadableSizeUtils.getHumanReadableSize(LocalContext.current, transfer.sizeUploaded)
val files = transfer.files
val filesCount = files.count()
val (expiryText, expiryColor) = if (remainingDays < 0 || remainingDownloads == 0) {
val (expiryText, expiryColor) = if (transfer.isExpired) {
stringResource(R.string.transferExpired) to SwissTransferTheme.materialColors.error
} else {
stringResource(R.string.expiresIn, remainingDays) to SwissTransferTheme.colors.secondaryTextColor
stringResource(R.string.expiresIn, transfer.expiresInDays) to SwissTransferTheme.colors.secondaryTextColor
}

Card(
Expand Down Expand Up @@ -87,7 +85,7 @@ fun TransferItem(transfer: TransferUi, onClick: () -> Unit) {

Spacer(modifier = Modifier.height(Margin.Mini))
ContextualFlowRow(
itemCount = filesCount,
itemCount = files.count(),
maxLines = 1,
horizontalArrangement = Arrangement.spacedBy(Margin.Mini),
overflow = ContextualFlowRowOverflow.expandIndicator { TransferFilePreview(remainingFilesCount = totalItemCount - shownItemCount) },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Infomaniak SwissTransfer - Android
* 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.swisstransfer.ui.utils

import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi

val TransferUi.isExpired: Boolean get() = expiresInDays < 0 || downloadLeft <= 0

0 comments on commit 968a3b8

Please sign in to comment.