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

Create a FileTileList component #85

Merged
merged 6 commits into from
Oct 16, 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 @@ -133,7 +133,7 @@ private fun FileItemContent(
.align(Alignment.TopEnd),
contentPadding = PaddingValues(0.dp),
shape = CircleShape,
colors = ButtonDefaults.buttonColors(containerColor = SwissTransferTheme.colors.fileTileRemoveButtonBackground),
colors = ButtonDefaults.buttonColors(containerColor = SwissTransferTheme.colors.fileItemRemoveButtonBackground),
onClick = onRemove ?: {},
) {
Icon(
Expand Down Expand Up @@ -210,7 +210,6 @@ private fun FileItemPreview() {
{
var isChecked by remember { mutableStateOf(true) }


val iconFile = object : FileUiItem {
override val fileName: String = "How to not get fired.pdf"
override val uid: String = fileName
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* 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.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.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow
import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow

@Composable
fun FileItemList(
modifier: Modifier = Modifier,
files: List<FileUiItem>,
isRemoveButtonVisible: Boolean,
isCheckboxVisible: Boolean,
isUidChecked: (String) -> Boolean,
setUidCheckStatus: (String, Boolean) -> Unit,
onRemoveUid: (String) -> Unit,
) {
LazyVerticalGrid(
modifier = modifier,
columns = GridCells.Adaptive(150.dp),
verticalArrangement = Arrangement.spacedBy(Margin.Medium),
horizontalArrangement = Arrangement.spacedBy(Margin.Medium),
) {
items(files, key = { it.uid }) { file ->
FileItem(
file = file,
isRemoveButtonVisible = isRemoveButtonVisible,
isCheckboxVisible = isCheckboxVisible,
isChecked = { isUidChecked(file.uid) },
onClick = { if (isCheckboxVisible) setUidCheckStatus(file.uid, !isUidChecked(file.uid)) },
onRemove = { onRemoveUid(file.uid) },
)
}
}
}

@PreviewSmallWindow
@PreviewLargeWindow
@Composable
private fun FileItemListPreview() {
val files = listOf(object : FileUiItem {
override val fileName: String = "The 5-Step Guide to Not Breaking Your Code.txt"
override val uid: String = fileName
override val fileSizeInBytes: Long = 57689032
override val mimeType: String? = null
override val uri: String = ""
}, object : FileUiItem {
override val fileName: String = "Introduction to Turning It Off and On Again.pptx"
override val uid: String = fileName
override val fileSizeInBytes: Long = 89723143
override val mimeType: String? = null
override val uri: String = ""
}, object : FileUiItem {
override val fileName: String = "Learning to Copy and Paste: A Complete Guide.docx"
override val uid: String = fileName
override val fileSizeInBytes: Long = 237866728
override val mimeType: String? = null
override val uri: String = ""
})

SwissTransferTheme {
FileItemList(
files = files,
isRemoveButtonVisible = false,
isCheckboxVisible = true,
isUidChecked = { false },
setUidCheckStatus = { _, _ -> },
onRemoveUid = {},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.EmptyState
import com.infomaniak.swisstransfer.ui.components.FileUiItem
import com.infomaniak.swisstransfer.ui.components.FileItemList
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus
import com.infomaniak.swisstransfer.ui.images.illus.MascotSearching
import com.infomaniak.swisstransfer.ui.screen.main.components.BrandTopAppBarScaffold
import com.infomaniak.swisstransfer.ui.screen.main.received.components.ReceivedEmptyFab
import com.infomaniak.swisstransfer.ui.screen.main.sent.SentViewModel
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow
import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow
Expand All @@ -43,21 +46,61 @@ fun ReceivedScreen(
sentViewModel: SentViewModel = hiltViewModel<SentViewModel>(),
) {
val transfers by sentViewModel.transfers.collectAsStateWithLifecycle()
val isTransferChecked = sentViewModel.selectedTransferIds
val areTransfersEmpty by remember { derivedStateOf { transfers?.isEmpty() == true } }

ReceivedScreen { areTransfersEmpty }
ReceivedScreen(
isFileChecked = { uid -> isTransferChecked[uid] == true },
setFileCheckStatus = { uid, isChecked -> isTransferChecked[uid] = isChecked },
areTransfersEmpty = { areTransfersEmpty }
)
}

@Composable
private fun ReceivedScreen(areTransfersEmpty: () -> Boolean) {
private fun ReceivedScreen(
isFileChecked: (String) -> Boolean,
setFileCheckStatus: (String, Boolean) -> Unit,
areTransfersEmpty: () -> Boolean
) {
BrandTopAppBarScaffold(
floatingActionButton = { ReceivedEmptyFab(areTransfersEmpty) },
) {
EmptyState(
icon = AppIllus.MascotSearching,
title = R.string.noTransferReceivedTitle,
description = R.string.noTransferReceivedDescription,
)
if (areTransfersEmpty()) {
EmptyState(
icon = AppIllus.MascotSearching,
title = R.string.noTransferReceivedTitle,
description = R.string.noTransferReceivedDescription,
)
} else {
val files = listOf(object : FileUiItem {
override val fileName: String = "The 5-Step Guide to Not Breaking Your Code.txt"
override val uid: String = fileName
override val fileSizeInBytes: Long = 57689032
override val mimeType: String? = null
override val uri: String = ""
}, object : FileUiItem {
override val fileName: String = "Introduction to Turning It Off and On Again.pptx"
override val uid: String = fileName
override val fileSizeInBytes: Long = 89723143
override val mimeType: String? = null
override val uri: String = ""
}, object : FileUiItem {
override val fileName: String = "Learning to Copy and Paste: A Complete Guide.docx"
override val uid: String = fileName
override val fileSizeInBytes: Long = 237866728
override val mimeType: String? = null
override val uri: String = ""
})
FileItemList(
modifier = Modifier.padding(Margin.Medium),
files = files,
isRemoveButtonVisible = false,
isCheckboxVisible = true,
isUidChecked = isFileChecked,
setUidCheckStatus = setFileCheckStatus,
onRemoveUid = {},
)
}
}
}

Expand All @@ -67,7 +110,7 @@ private fun ReceivedScreen(areTransfersEmpty: () -> Boolean) {
private fun ReceivedScreenPreview() {
SwissTransferTheme {
Surface {
ReceivedScreen(areTransfersEmpty = { true })
ReceivedScreen(areTransfersEmpty = { true }, isFileChecked = { false }, setFileCheckStatus = { _, _ -> })
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,47 @@
*/
package com.infomaniak.swisstransfer.ui.screen.main.sent

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.infomaniak.swisstransfer.ui.components.FileUiItem
import com.infomaniak.swisstransfer.ui.components.FileItem
import com.infomaniak.swisstransfer.ui.components.FileItemList
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow
import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow

@Composable
fun SentListScreen(transfers: List<Any>) {
LazyVerticalGrid(
val transfers = listOf(object : FileUiItem {
override val fileName: String = "The 5-Step Guide to Not Breaking Your Code.txt"
override val uid: String = fileName
override val fileSizeInBytes: Long = 57689032
override val mimeType: String? = null
override val uri: String = ""
}, object : FileUiItem {
override val fileName: String = "Introduction to Turning It Off and On Again.pptx"
override val uid: String = fileName
override val fileSizeInBytes: Long = 89723143
override val mimeType: String? = null
override val uri: String = ""
}, object : FileUiItem {
override val fileName: String = "Learning to Copy and Paste: A Complete Guide.docx"
override val uid: String = fileName
override val fileSizeInBytes: Long = 237866728
override val mimeType: String? = null
override val uri: String = ""
})
FileItemList(
modifier = Modifier.padding(Margin.Medium),
columns = GridCells.Adaptive(150.dp),
verticalArrangement = Arrangement.spacedBy(Margin.Medium),
horizontalArrangement = Arrangement.spacedBy(Margin.Medium),
) {
val imageFile = object : FileUiItem {
override val fileName: String = "Time-Clock-Circle--Streamline-Ultimate.svg (1).png"
override val uid: String = fileName
override val fileSizeInBytes: Long = 456782
override val mimeType: String? = null
override val uri: String = "https://picsum.photos/200/300"
}

items(3) {
FileItem(
file = imageFile,
isRemoveButtonVisible = true,
isCheckboxVisible = true,
isChecked = { true },
onClick = {},
onRemove = {})
}
}
files = transfers,
isRemoveButtonVisible = true,
isCheckboxVisible = false,
isUidChecked = { false },
setUidCheckStatus = { _, _ -> },
onRemoveUid = {},
)
}

@PreviewSmallWindow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ private fun SentScreen(transfers: List<Any>?) {
SentListScreen(transfers)
}
}

}

@PreviewSmallWindow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package com.infomaniak.swisstransfer.ui.screen.main.sent

import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.snapshots.SnapshotStateMap
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -28,4 +30,5 @@ import javax.inject.Inject
@HiltViewModel
class SentViewModel @Inject constructor() : ViewModel() {
val transfers = flow<List<Any>> { emit(listOf(1)) }.stateIn(viewModelScope, SharingStarted.Eagerly, null)
val selectedTransferIds: SnapshotStateMap<String, Boolean> = mutableStateMapOf<String, Boolean>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ val CustomDarkColorScheme = CustomColorScheme(
navigationItemBackground = Color(dark2),
tertiaryButtonBackground = Color(dark2),
selectedSettingItem = Color(dark2),
fileTileRemoveButtonBackground = Color(black_translucent),
fileItemRemoveButtonBackground = Color(black_translucent),
transferTypeLinkContainer = Color(specific1),
transferTypeLinkOnContainer = Color(green_main),
transferTypeEmailContainer = Color(green_dark),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ val CustomLightColorScheme = CustomColorScheme(
navigationItemBackground = LightColorScheme.background,
tertiaryButtonBackground = Color(rabbit),
selectedSettingItem = Color(rabbit),
fileTileRemoveButtonBackground = Color(black_translucent),
fileItemRemoveButtonBackground = Color(black_translucent),
transferTypeLinkContainer = Color(specific1),
transferTypeLinkOnContainer = Color(green_main),
transferTypeEmailContainer = Color(specific2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ data class CustomColorScheme(
val navigationItemBackground: Color = Color.Unspecified,
val tertiaryButtonBackground: Color = Color.Unspecified,
val selectedSettingItem: Color = Color.Unspecified,
val fileTileRemoveButtonBackground: Color = Color.Unspecified,
val fileItemRemoveButtonBackground: Color = Color.Unspecified,
val transferTypeLinkContainer: Color = Color.Unspecified,
val transferTypeLinkOnContainer: Color = Color.Unspecified,
val transferTypeEmailContainer: Color = Color.Unspecified,
Expand Down
Loading