Skip to content

Commit

Permalink
review: Extract TransferInfo to its own component
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Nov 7, 2024
1 parent 0c57b4e commit 55e4b7f
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.infomaniak.swisstransfer.ui.components.*
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIcons
import com.infomaniak.swisstransfer.ui.images.icons.*
import com.infomaniak.swisstransfer.ui.screen.main.components.SmallWindowTopAppBarScaffold
import com.infomaniak.swisstransfer.ui.screen.main.transferdetails.components.TransferInfo
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows
Expand Down Expand Up @@ -172,61 +173,6 @@ fun TransferDetailsScreen(
}
}

@Composable
private fun TransferInfo(transfer: TransferUi) {

val filesCount by remember { derivedStateOf { transfer.files.count() } }
val downloadedCount by remember { derivedStateOf { transfer.downloadLimit - transfer.downloadLeft } }

Row(verticalAlignment = Alignment.CenterVertically) {
Icon(
imageVector = AppIcons.FileZip,
tint = SwissTransferTheme.materialColors.primary,
contentDescription = null,
)
Spacer(Modifier.width(Margin.Mini))
TextDotText(
firstText = { pluralStringResource(R.plurals.filesCount, filesCount, filesCount) },
secondText = { Formatter.formatShortFileSize(LocalContext.current, transfer.sizeUploaded) },
color = SwissTransferTheme.colors.primaryTextColor,
)
}

HorizontalDivider(modifier = Modifier.padding(vertical = Margin.Medium))

Row(verticalAlignment = Alignment.CenterVertically) {
Icon(
modifier = Modifier.size(Margin.Medium),
imageVector = AppIcons.Clock,
tint = SwissTransferTheme.materialColors.primary,
contentDescription = null,
)
Text(
modifier = Modifier.padding(start = Margin.Mini),
text = stringResource(R.string.expiresIn, transfer.expiresInDays),
style = SwissTransferTheme.typography.bodySmallRegular,
color = SwissTransferTheme.colors.primaryTextColor,
)
}

HorizontalDivider(modifier = Modifier.padding(vertical = Margin.Medium))

Row(verticalAlignment = Alignment.CenterVertically) {
Icon(
modifier = Modifier.size(Margin.Medium),
imageVector = AppIcons.ArrowDownFile,
tint = SwissTransferTheme.materialColors.primary,
contentDescription = null,
)
Text(
modifier = Modifier.padding(start = Margin.Mini),
text = stringResource(R.string.downloadedTransferLabel, downloadedCount, transfer.downloadLimit),
style = SwissTransferTheme.typography.bodySmallRegular,
color = SwissTransferTheme.colors.primaryTextColor,
)
}
}

@Composable
private fun TransferMessage(transfer: TransferUi, transferSenderEmail: String?) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* 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.screen.main.transferdetails.components

import android.text.format.Formatter
import androidx.compose.foundation.layout.*
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.TextDotText
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIcons
import com.infomaniak.swisstransfer.ui.images.icons.ArrowDownFile
import com.infomaniak.swisstransfer.ui.images.icons.Clock
import com.infomaniak.swisstransfer.ui.images.icons.FileZip
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme

@Composable
fun TransferInfo(transfer: TransferUi) {

val filesCount by remember { derivedStateOf { transfer.files.count() } }
val downloadedCount by remember { derivedStateOf { transfer.downloadLimit - transfer.downloadLeft } }

Row(verticalAlignment = Alignment.CenterVertically) {
Icon(
imageVector = AppIcons.FileZip,
tint = SwissTransferTheme.materialColors.primary,
contentDescription = null,
)
Spacer(Modifier.width(Margin.Mini))
TextDotText(
firstText = { pluralStringResource(R.plurals.filesCount, filesCount, filesCount) },
secondText = { Formatter.formatShortFileSize(LocalContext.current, transfer.sizeUploaded) },
color = SwissTransferTheme.colors.primaryTextColor,
)
}

HorizontalDivider(modifier = Modifier.padding(vertical = Margin.Medium))

IconText(
icon = AppIcons.Clock,
text = stringResource(R.string.expiresIn, transfer.expiresInDays),
)

HorizontalDivider(modifier = Modifier.padding(vertical = Margin.Medium))

IconText(
icon = AppIcons.ArrowDownFile,
text = stringResource(R.string.downloadedTransferLabel, downloadedCount, transfer.downloadLimit),
)
}

@Composable
private fun IconText(icon: ImageVector, text: String) {
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(
modifier = Modifier.size(Margin.Medium),
imageVector = icon,
tint = SwissTransferTheme.materialColors.primary,
contentDescription = null,
)
Text(
modifier = Modifier.padding(start = Margin.Mini),
text = text,
style = SwissTransferTheme.typography.bodySmallRegular,
color = SwissTransferTheme.colors.primaryTextColor,
)
}
}

0 comments on commit 55e4b7f

Please sign in to comment.