-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from Infomaniak/display-picked-files
Adds and use the component to display picked files during a new transfer
- Loading branch information
Showing
21 changed files
with
765 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
app/src/main/java/com/infomaniak/swisstransfer/ui/components/CrossCircleButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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 android.content.res.Configuration | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material3.* | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.coerceAtLeast | ||
import androidx.compose.ui.unit.dp | ||
import com.infomaniak.swisstransfer.R | ||
import com.infomaniak.swisstransfer.ui.images.AppImages | ||
import com.infomaniak.swisstransfer.ui.images.icons.CrossThick | ||
import com.infomaniak.swisstransfer.ui.theme.Margin | ||
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme | ||
|
||
@Composable | ||
@OptIn(ExperimentalMaterial3Api::class) | ||
fun BoxScope.CrossCircleButton(onClick: (() -> Unit)?, size: Dp = 48.dp) { | ||
val buttonPadding = ((size - 24.dp) / 2f).coerceAtLeast(0.dp) | ||
|
||
CompositionLocalProvider(LocalRippleConfiguration provides RippleConfiguration(color = Color.White)) { | ||
Button( | ||
modifier = Modifier | ||
.size(size) | ||
.padding(buttonPadding) | ||
.align(Alignment.TopEnd), | ||
contentPadding = PaddingValues(0.dp), | ||
shape = CircleShape, | ||
colors = ButtonDefaults.buttonColors(containerColor = SwissTransferTheme.colors.fileItemRemoveButtonBackground), | ||
onClick = onClick ?: {}, | ||
) { | ||
Icon( | ||
modifier = Modifier.size(Margin.Small), | ||
imageVector = AppImages.AppIcons.CrossThick, | ||
contentDescription = stringResource(R.string.contentDescriptionButtonRemove), | ||
tint = Color.White, | ||
) | ||
} | ||
} | ||
} | ||
|
||
|
||
@Preview(name = "Light") | ||
@Preview(name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL) | ||
@Composable | ||
private fun CrossCircleButtonPreview() { | ||
SwissTransferTheme { | ||
Surface { | ||
Box { | ||
CrossCircleButton({}) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
app/src/main/java/com/infomaniak/swisstransfer/ui/components/FilePreview.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* 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.Canvas | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.Icon | ||
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.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.unit.Dp | ||
import coil.compose.AsyncImage | ||
import coil.request.ImageRequest | ||
import com.infomaniak.library.filetypes.FileType | ||
import com.infomaniak.swisstransfer.ui.theme.LocalIsDarkMode | ||
import com.infomaniak.swisstransfer.ui.utils.fileType | ||
import com.infomaniak.swisstransfer.ui.utils.hasPreview | ||
|
||
@Composable | ||
fun FilePreview( | ||
file: FileUiItem, | ||
circleColor: Color, | ||
circleSize: Dp, | ||
) { | ||
var displayPreview by rememberSaveable { mutableStateOf(file.hasPreview) } | ||
|
||
if (displayPreview) { | ||
FileThumbnail(file.uri, onError = { displayPreview = false }) | ||
} else { | ||
FileIcon(file.fileType, circleColor, circleSize) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun FileThumbnail(uri: String, onError: () -> Unit) { | ||
AsyncImage( | ||
model = ImageRequest.Builder(LocalContext.current) | ||
.data(uri) | ||
.crossfade(true) | ||
.build(), | ||
contentDescription = null, | ||
contentScale = ContentScale.Crop, | ||
onError = { onError() }, | ||
modifier = Modifier.fillMaxSize(), | ||
) | ||
} | ||
|
||
@Composable | ||
private fun FileIcon(fileType: FileType, color: Color, circleSize: Dp) { | ||
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) { | ||
Canvas(modifier = Modifier.size(circleSize)) { | ||
drawCircle(color = color) | ||
} | ||
|
||
Icon( | ||
modifier = Modifier.size(circleSize / 2), | ||
imageVector = fileType.icon, | ||
contentDescription = null, | ||
tint = fileType.color(LocalIsDarkMode.current), | ||
) | ||
} | ||
} |
Oops, something went wrong.