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

feat: Add TransferDetails screen #138

Merged
merged 18 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions Core2/src/main/java/com/infomaniak/core2/DateUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ import java.util.Locale
const val FORMAT_DATE_DEFAULT = "dd.MM.yy"
const val FORMAT_DATE_TITLE = "E d MMMM"
const val FORMAT_DATE_SIMPLE = "dd/MM/yyyy"
const val FORMAT_DATE_FULL = "EEEE d MMMM"

fun Date.format(pattern: String = FORMAT_DATE_DEFAULT): String = SimpleDateFormat(pattern, Locale.getDefault()).format(this)
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ private fun FileItemContent(
) {
Card(
onClick = onClick,
modifier = Modifier.aspectRatio(164 / 152f),
modifier = Modifier.aspectRatio(164.0f / 152.0f),
colors = CardDefaults.cardColors(containerColor = SwissTransferTheme.materialColors.background),
shape = CustomShapes.SMALL,
border = BorderStroke(width = Dimens.BorderWidth, SwissTransferTheme.materialColors.outlineVariant),
border = BorderStroke(width = Dimens.BorderWidth, color = SwissTransferTheme.materialColors.outlineVariant),
) {
Box(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
package com.infomaniak.swisstransfer.ui.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.grid.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.PreviewParameter
Expand All @@ -36,25 +35,35 @@ fun FileItemList(
modifier: Modifier = Modifier,
files: List<FileUi>,
isRemoveButtonVisible: Boolean,
isCheckboxVisible: Boolean,
isCheckboxVisible: () -> Boolean,
isUidChecked: (String) -> Boolean,
setUidCheckStatus: (String, Boolean) -> Unit,
onRemoveUid: (String) -> Unit,
onRemoveUid: ((String) -> Unit)? = null,
header: (@Composable LazyGridItemScope.() -> Unit)? = null,
) {
LazyVerticalGrid(
modifier = modifier,
columns = GridCells.Adaptive(150.dp),
verticalArrangement = Arrangement.spacedBy(Margin.Medium),
horizontalArrangement = Arrangement.spacedBy(Margin.Medium),
contentPadding = PaddingValues(bottom = Margin.Mini),
) {

header?.let {
item(
span = { GridItemSpan(maxLineSpan) },
content = it,
)
}

items(files, key = { it.uid }) { file ->
FileItem(
file = file,
isRemoveButtonVisible = isRemoveButtonVisible,
isCheckboxVisible = isCheckboxVisible,
isCheckboxVisible = isCheckboxVisible(),
isChecked = { isUidChecked(file.uid) },
onClick = { if (isCheckboxVisible) setUidCheckStatus(file.uid, !isUidChecked(file.uid)) },
onRemove = { onRemoveUid(file.uid) },
onClick = { if (isCheckboxVisible()) setUidCheckStatus(file.uid, !isUidChecked(file.uid)) },
onRemove = { onRemoveUid?.invoke(file.uid) },
)
}
}
Expand All @@ -67,7 +76,7 @@ private fun FileItemListPreview(@PreviewParameter(FileUiListPreviewParameter::cl
FileItemList(
files = files,
isRemoveButtonVisible = false,
isCheckboxVisible = true,
isCheckboxVisible = { true },
isUidChecked = { false },
setUidCheckStatus = { _, _ -> },
onRemoveUid = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,20 @@ import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows

@Composable
@OptIn(ExperimentalMaterial3Api::class)
fun SwissTransferTopAppBar(
@StringRes titleRes: Int,
navigationMenu: TopAppBarButton? = null,
vararg actionMenus: TopAppBarButton,
) {
SwissTransferTopAppBar(title = stringResource(titleRes), navigationMenu, *actionMenus)
}

@Composable
@OptIn(ExperimentalMaterial3Api::class)
fun SwissTransferTopAppBar(
title: String,
navigationMenu: TopAppBarButton? = null,
vararg actionMenus: TopAppBarButton,
) {
TopAppBar(
colors = TopAppBarDefaults.topAppBarColors(
Expand All @@ -45,7 +54,7 @@ fun SwissTransferTopAppBar(
actionIconContentColor = SwissTransferTheme.colors.toolbarIconColor,
navigationIconContentColor = SwissTransferTheme.colors.toolbarIconColor,
),
title = { Text(stringResource(id = titleRes), style = SwissTransferTheme.typography.h2) },
title = { Text(title, style = SwissTransferTheme.typography.h2) },
navigationIcon = { navigationMenu?.let { MenuButton(navigationMenu) } },
actions = { actionMenus.forEach { actionMenu -> MenuButton(actionMenu) } },
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import androidx.compose.material3.adaptive.layout.calculatePaneScaffoldDirective
import androidx.compose.material3.adaptive.navigation.ThreePaneScaffoldNavigator
import androidx.compose.material3.adaptive.navigation.rememberListDetailPaneScaffoldNavigator
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.infomaniak.swisstransfer.ui.theme.LocalWindowAdaptiveInfo
Expand Down Expand Up @@ -72,3 +76,18 @@ fun <T> TwoPaneScaffold(
modifier = modifier,
)
}

/**
* Keep the DetailPane's content in memory so that it's always available while navigating back.
* When leaving the DetailPane, its content becomes `null`, which creates a visual glitch in the back animation.
*/
@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
fun <T> ThreePaneScaffoldNavigator<T>.safeCurrentContent(): T? {
var oldContent by rememberSaveable { mutableStateOf<T?>(null) }

val newContent = currentDestination?.content ?: oldContent
currentDestination?.content?.let { oldContent = it }

return newContent
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fun TransferFilePreview(file: FileUi? = null, remainingFilesCount: Int? = null)
// .build(),
// contentDescription = null,
// contentScale = ContentScale.Crop,
// onError = { }, // TODO ?
// onError = {}, // TODO ?
// modifier = Modifier
// .size(Margin.Giant)
// .clip(CustomShapes.SMALL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package com.infomaniak.swisstransfer.ui.components.transfer

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
Expand All @@ -35,6 +36,7 @@ import com.infomaniak.swisstransfer.ui.components.TextDotText
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIcons
import com.infomaniak.swisstransfer.ui.images.icons.ChevronRightThick
import com.infomaniak.swisstransfer.ui.theme.CustomShapes
import com.infomaniak.swisstransfer.ui.theme.Dimens
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.HumanReadableSizeUtils
Expand All @@ -45,7 +47,11 @@ import java.util.UUID

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun TransferItem(transfer: TransferUi, onClick: () -> Unit) {
fun TransferItem(
transfer: TransferUi,
isSelected: () -> Boolean,
onClick: () -> Unit,
) {

val createdDate = Date(transfer.createdDateTimestamp).format(FORMAT_DATE_TITLE)
val expirationDate = Date(transfer.expirationDateTimestamp)
Expand All @@ -66,11 +72,17 @@ fun TransferItem(transfer: TransferUi, onClick: () -> Unit) {
stringResource(R.string.expiresIn, remainingDays) to SwissTransferTheme.colors.secondaryTextColor
}
}
val border = if (isSelected()) {
BorderStroke(width = Dimens.BorderWidth, color = SwissTransferTheme.colors.transferListStroke)
} else {
null
}

Card(
onClick = onClick,
colors = CardDefaults.cardColors(containerColor = SwissTransferTheme.materialColors.surfaceContainerHighest),
shape = CustomShapes.SMALL,
border = border,
) {
Row(
modifier = Modifier.padding(Margin.Medium),
Expand Down Expand Up @@ -178,6 +190,7 @@ private fun Preview() {
),
),
),
isSelected = { false },
onClick = {},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
package com.infomaniak.swisstransfer.ui.components.transfer

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
Expand All @@ -40,15 +39,19 @@ import java.util.UUID
fun TransferItemList(
modifier: Modifier = Modifier,
transfers: List<TransferUi>,
getSelectedTransferUuid: () -> String?,
onClick: (TransferUi) -> Unit,
) {

val selectedTransferUuid = getSelectedTransferUuid()

LazyColumn(
modifier = modifier,
verticalArrangement = Arrangement.spacedBy(Margin.Medium),
contentPadding = PaddingValues(top = Margin.Mini),
) {

item {
Spacer(modifier = Modifier.height(Margin.Mini))
Text(
text = stringResource(R.string.receivedFilesTitle),
style = SwissTransferTheme.typography.h1,
Expand All @@ -61,7 +64,11 @@ fun TransferItemList(
contentType = { transfers[it] },
itemContent = {
val transfer = transfers[it]
TransferItem(transfer) { onClick(transfer) }
TransferItem(
transfer = transfer,
isSelected = { selectedTransferUuid == transfer.uuid },
onClick = { onClick(transfer) },
)
},
)
}
Expand Down Expand Up @@ -160,7 +167,11 @@ private fun Preview() {

SwissTransferTheme {
Surface {
TransferItemList(transfers = transfers, onClick = {})
TransferItemList(
transfers = transfers,
getSelectedTransferUuid = { null },
onClick = {},
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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.images.icons

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.PathFillType.Companion.NonZero
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.ImageVector.Builder
import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.infomaniak.swisstransfer.ui.images.AppImages
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIcons
import androidx.compose.ui.graphics.StrokeCap.Companion.Round as strokeCapRound
import androidx.compose.ui.graphics.StrokeJoin.Companion.Round as strokeJoinRound

val AppIcons.ArrowDownBar: ImageVector
get() {

if (_arrowDownBar != null) return _arrowDownBar!!

_arrowDownBar = Builder(
name = "ArrowDownBar",
defaultWidth = 24.0.dp,
defaultHeight = 24.0.dp,
viewportWidth = 24.0f,
viewportHeight = 24.0f,
).apply {
path(
stroke = SolidColor(Color(0xFF9f9f9f)),
strokeLineWidth = 1.5f,
strokeLineCap = strokeCapRound,
strokeLineJoin = strokeJoinRound,
strokeLineMiter = 4.0f,
pathFillType = NonZero,
) {
moveTo(12.0f, 1.936f)
lineTo(12.0f, 16.157f)
}
path(
stroke = SolidColor(Color(0xFF9f9f9f)),
strokeLineWidth = 1.5f,
strokeLineCap = strokeCapRound,
strokeLineJoin = strokeJoinRound,
strokeLineMiter = 4.0f,
pathFillType = NonZero,
) {
moveTo(8.171f, 12.328f)
lineTo(12.0f, 16.157f)
lineTo(15.829f, 12.328f)
}
path(
stroke = SolidColor(Color(0xFF9f9f9f)),
strokeLineWidth = 1.5f,
strokeLineCap = strokeCapRound,
strokeLineJoin = strokeJoinRound,
strokeLineMiter = 4.0f,
pathFillType = NonZero,
) {
moveTo(22.94f, 22.064f)
lineTo(1.061f, 22.064f)
}
}
.build()
return _arrowDownBar!!
}

private var _arrowDownBar: ImageVector? = null

@Preview
@Composable
private fun Preview() {
Box {
Image(
imageVector = AppIcons.ArrowDownBar,
contentDescription = null,
modifier = Modifier.size(AppImages.previewSize)
)
}
}
Loading
Loading