Skip to content

Commit

Permalink
Merge branch 'image-tile-component' into image-tile-list-component
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentListScreen.kt
  • Loading branch information
LunarX committed Oct 16, 2024
2 parents 0826abf + 10ccbef commit d47b8d3
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 43 deletions.
8 changes: 4 additions & 4 deletions FileTypes/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ android {
dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.ui.android)
implementation(libs.androidx.foundation.android)
implementation(libs.androidx.ui.tooling.preview.android)
implementation(filetype.androidx.ui.android)
implementation(filetype.androidx.foundation.android)
implementation(filetype.androidx.ui.tooling.preview.android)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(filetype.androidx.ui.tooling)
}
11 changes: 11 additions & 0 deletions FileTypes/gradle/filetype.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[versions]
uiAndroid = "1.7.3"
foundationAndroid = "1.7.3"
uiToolingPreviewAndroid = "1.7.3"
uiTooling = "1.7.3"

[libraries]
androidx-ui-android = { group = "androidx.compose.ui", name = "ui-android", version.ref = "uiAndroid" }
androidx-foundation-android = { group = "androidx.compose.foundation", name = "foundation-android", version.ref = "foundationAndroid" }
androidx-ui-tooling-preview-android = { group = "androidx.compose.ui", name = "ui-tooling-preview-android", version.ref = "uiToolingPreviewAndroid" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "uiTooling" }
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
*/
package com.infomaniak.library.filetypes

import android.util.Log
import android.webkit.MimeTypeMap
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import com.infomaniak.library.filetypes.icons.*
import org.jetbrains.annotations.TestOnly

private val MEDIA_COLOR_LIGHT = Color(0xFF00BCD4)
private val MEDIA_COLOR_DARK = Color(0xFF86DEEA)
Expand All @@ -49,7 +47,7 @@ enum class FileType(val icon: ImageVector, private val colorLight: Color, privat

companion object {
fun guessFromFileName(fileName: String): FileType {
val extension = fileName.extractExtension()
val extension = fileName.extractExtension() ?: return UNKNOWN
val mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) ?: return UNKNOWN
return guessFromMimeType(mimeType)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal object FileTypeGuesser {
"application/x-pdf",
)

val calendarMatches = mimeTypeSetOf(
private val calendarMatches = mimeTypeSetOf(
"application/ics",
"text/calendar",
)
Expand Down Expand Up @@ -133,7 +133,7 @@ internal object FileTypeGuesser {

private fun mimeTypeSetOf(vararg mimeTypes: String) = MimeTypeSet(mimeTypes.toSet())

class MimeTypeSet(private val mimeTypes: Set<String>) : Set<String> by mimeTypes {
private class MimeTypeSet(private val mimeTypes: Set<String>) : Set<String> by mimeTypes {
override fun contains(element: String): Boolean = mimeTypes.any { mimeType -> element.startsWith(mimeType) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
*/
package com.infomaniak.library.filetypes

internal object FileTypeIcons
import androidx.compose.ui.unit.dp

internal object FileTypeIcons {
val previewSize = 250.dp
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.infomaniak.library.filetypes.FileTypeIcons
import com.infomaniak.library.filetypes.FileTypeIcons.previewSize
import androidx.compose.ui.graphics.StrokeCap.Companion.Round as strokeCapRound
import androidx.compose.ui.graphics.StrokeJoin.Companion.Round as strokeJoinRound

Expand Down Expand Up @@ -124,7 +125,7 @@ private var _archive: ImageVector? = null
@Preview
@Composable
private fun Preview() {
Box(modifier = Modifier.padding(12.dp)) {
Box(modifier = Modifier.padding(previewSize)) {
Image(imageVector = FileTypeIcons.Archive, contentDescription = null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.infomaniak.library.filetypes.FileTypeIcons
import com.infomaniak.library.filetypes.FileTypeIcons.previewSize
import androidx.compose.ui.graphics.StrokeCap.Companion.Round as strokeCapRound
import androidx.compose.ui.graphics.StrokeJoin.Companion.Round as strokeJoinRound

Expand Down Expand Up @@ -109,7 +110,7 @@ private var _audio: ImageVector? = null
@Preview
@Composable
private fun Preview() {
Box(modifier = Modifier.padding(12.dp)) {
Box(modifier = Modifier.padding(previewSize)) {
Image(imageVector = FileTypeIcons.Audio, contentDescription = null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.infomaniak.library.filetypes.FileTypeIcons
import com.infomaniak.library.filetypes.FileTypeIcons.previewSize
import androidx.compose.ui.graphics.StrokeCap.Companion.Round as strokeCapRound
import androidx.compose.ui.graphics.StrokeJoin.Companion.Round as strokeJoinRound

Expand Down Expand Up @@ -66,7 +67,7 @@ private var _calendar: ImageVector? = null
@Preview
@Composable
private fun Preview() {
Box(modifier = Modifier.padding(12.dp)) {
Box(modifier = Modifier.padding(previewSize)) {
Image(imageVector = FileTypeIcons.Calendar, contentDescription = null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.infomaniak.library.filetypes.FileTypeIcons
import com.infomaniak.library.filetypes.FileTypeIcons.previewSize
import androidx.compose.ui.graphics.StrokeCap.Companion.Round as strokeCapRound
import androidx.compose.ui.graphics.StrokeJoin.Companion.Round as strokeJoinRound

Expand Down Expand Up @@ -78,7 +79,7 @@ private var _code: ImageVector? = null
@Preview
@Composable
private fun Preview() {
Box(modifier = Modifier.padding(12.dp)) {
Box(modifier = Modifier.padding(previewSize)) {
Image(imageVector = FileTypeIcons.Code, contentDescription = null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.infomaniak.library.filetypes.FileTypeIcons
import com.infomaniak.library.filetypes.FileTypeIcons.previewSize
import androidx.compose.ui.graphics.StrokeCap.Companion.Round as strokeCapRound
import androidx.compose.ui.graphics.StrokeJoin.Companion.Round as strokeJoinRound

Expand Down Expand Up @@ -80,7 +81,7 @@ private var _font: ImageVector? = null
@Preview
@Composable
private fun Preview() {
Box(modifier = Modifier.padding(12.dp)) {
Box(modifier = Modifier.padding(previewSize)) {
Image(imageVector = FileTypeIcons.Font, contentDescription = null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.infomaniak.library.filetypes.FileTypeIcons
import com.infomaniak.library.filetypes.FileTypeIcons.previewSize
import androidx.compose.ui.graphics.StrokeCap.Companion.Round as strokeCapRound
import androidx.compose.ui.graphics.StrokeJoin.Companion.Round as strokeJoinRound

Expand Down Expand Up @@ -76,7 +77,7 @@ private var _image: ImageVector? = null
@Preview
@Composable
private fun Preview() {
Box(modifier = Modifier.padding(12.dp)) {
Box(modifier = Modifier.padding(previewSize)) {
Image(imageVector = FileTypeIcons.Image, contentDescription = null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.infomaniak.library.filetypes.FileTypeIcons
import com.infomaniak.library.filetypes.FileTypeIcons.previewSize
import androidx.compose.ui.graphics.StrokeCap.Companion.Round as strokeCapRound
import androidx.compose.ui.graphics.StrokeJoin.Companion.Round as strokeJoinRound

Expand Down Expand Up @@ -96,7 +97,7 @@ private var _pdf: ImageVector? = null
@Preview
@Composable
private fun Preview() {
Box(modifier = Modifier.padding(12.dp)) {
Box(modifier = Modifier.padding(previewSize)) {
Image(imageVector = FileTypeIcons.Pdf, contentDescription = null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.infomaniak.library.filetypes.FileTypeIcons
import com.infomaniak.library.filetypes.FileTypeIcons.previewSize
import androidx.compose.ui.graphics.StrokeCap.Companion.Round as strokeCapRound
import androidx.compose.ui.graphics.StrokeJoin.Companion.Round as strokeJoinRound

Expand Down Expand Up @@ -89,7 +90,7 @@ private var _points: ImageVector? = null
@Preview
@Composable
private fun Preview() {
Box(modifier = Modifier.padding(12.dp)) {
Box(modifier = Modifier.padding(previewSize)) {
Image(imageVector = FileTypeIcons.Points, contentDescription = null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.infomaniak.library.filetypes.FileTypeIcons
import com.infomaniak.library.filetypes.FileTypeIcons.previewSize
import androidx.compose.ui.graphics.StrokeCap.Companion.Round as strokeCapRound
import androidx.compose.ui.graphics.StrokeJoin.Companion.Round as strokeJoinRound

Expand Down Expand Up @@ -87,7 +88,7 @@ private var _sheet: ImageVector? = null
@Preview
@Composable
private fun Preview() {
Box(modifier = Modifier.padding(12.dp)) {
Box(modifier = Modifier.padding(previewSize)) {
Image(imageVector = FileTypeIcons.Sheet, contentDescription = null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.infomaniak.library.filetypes.FileTypeIcons
import com.infomaniak.library.filetypes.FileTypeIcons.previewSize
import androidx.compose.ui.graphics.StrokeCap.Companion.Round as strokeCapRound
import androidx.compose.ui.graphics.StrokeJoin.Companion.Round as strokeJoinRound

Expand Down Expand Up @@ -68,7 +69,7 @@ private var _text: ImageVector? = null
@Preview
@Composable
private fun Preview() {
Box(modifier = Modifier.padding(12.dp)) {
Box(modifier = Modifier.padding(previewSize)) {
Image(imageVector = FileTypeIcons.Text, contentDescription = null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.infomaniak.library.filetypes.FileTypeIcons
import com.infomaniak.library.filetypes.FileTypeIcons.previewSize
import androidx.compose.ui.graphics.StrokeCap.Companion.Round as strokeCapRound
import androidx.compose.ui.graphics.StrokeJoin.Companion.Round as strokeJoinRound

Expand Down Expand Up @@ -62,7 +63,7 @@ private var _unknown: ImageVector? = null
@Preview
@Composable
private fun Preview() {
Box(modifier = Modifier.padding(12.dp)) {
Box(modifier = Modifier.padding(previewSize)) {
Image(imageVector = FileTypeIcons.Unknown, contentDescription = null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.infomaniak.library.filetypes.FileTypeIcons
import com.infomaniak.library.filetypes.FileTypeIcons.previewSize
import androidx.compose.ui.graphics.StrokeCap.Companion.Round as strokeCapRound
import androidx.compose.ui.graphics.StrokeJoin.Companion.Round as strokeJoinRound

Expand Down Expand Up @@ -76,7 +77,7 @@ private var _vcard: ImageVector? = null
@Preview
@Composable
private fun Preview() {
Box(modifier = Modifier.padding(12.dp)) {
Box(modifier = Modifier.padding(previewSize)) {
Image(imageVector = FileTypeIcons.Vcard, contentDescription = null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.infomaniak.library.filetypes.FileTypeIcons
import com.infomaniak.library.filetypes.FileTypeIcons.previewSize
import androidx.compose.ui.graphics.StrokeCap.Companion.Round as strokeCapRound
import androidx.compose.ui.graphics.StrokeJoin.Companion.Round as strokeJoinRound

Expand Down Expand Up @@ -78,7 +79,7 @@ private var _video: ImageVector? = null
@Preview
@Composable
private fun Preview() {
Box(modifier = Modifier.padding(12.dp)) {
Box(modifier = Modifier.padding(previewSize)) {
Image(imageVector = FileTypeIcons.Video, contentDescription = null)
}
}
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ kapt {
}

dependencies {
implementation(project(":FileTypes"))
implementation(kotlin("reflect"))

implementation(libs.androidx.core.ktx)
Expand All @@ -90,7 +91,6 @@ dependencies {

// Compose preview tools
implementation(libs.compose.ui.tooling.preview)
implementation(project(":FileTypes"))
debugImplementation(libs.compose.ui.tooling)

// Hilt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ interface FileUiItem {
}

@Composable
fun FileTile(
fun FileItem(
file: FileUiItem,
isRemoveButtonVisible: Boolean,
isCheckboxVisible: Boolean,
isChecked: () -> Boolean = { false },
onClick: () -> Unit,
onRemove: (() -> Unit)? = null,
) {
FileTileContent(
FileItemContent(
content = {
var displayPreview by rememberSaveable { mutableStateOf(file.hasPreview) }

Expand All @@ -90,7 +90,7 @@ fun FileTile(
}

@Composable
private fun FileTileContent(
private fun FileItemContent(
content: @Composable () -> Unit,
onClick: () -> Unit,
isCheckboxVisible: Boolean,
Expand Down Expand Up @@ -199,7 +199,7 @@ private fun FileIcon(fileType: FileType) {
@PreviewSmallWindow
@PreviewLargeWindow
@Composable
private fun FileTilePreview() {
private fun FileItemPreview() {
SwissTransferTheme {
Surface {
Column(
Expand All @@ -217,7 +217,7 @@ private fun FileTilePreview() {
override val mimeType: String? = null
override val uri: String = ""
}
FileTile(
FileItem(
iconFile,
isRemoveButtonVisible = true,
isCheckboxVisible = true,
Expand All @@ -235,7 +235,7 @@ private fun FileTilePreview() {
override val mimeType: String? = null
override val uri: String = "https://picsum.photos/200/300"
}
FileTile(
FileItem(
file = imageFile,
isRemoveButtonVisible = true,
isCheckboxVisible = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fun FileTileList(
horizontalArrangement = Arrangement.spacedBy(Margin.Medium),
) {
items(files, key = { it.uid }) { file ->
FileTile(
FileItem(
file = file,
isRemoveButtonVisible = isRemoveButtonVisible,
isCheckboxVisible = isCheckboxVisible,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.infomaniak.swisstransfer.ui.components.FileUiItem
import com.infomaniak.swisstransfer.ui.components.FileTileList
import com.infomaniak.swisstransfer.ui.components.FileItem
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow
Expand Down
Loading

0 comments on commit d47b8d3

Please sign in to comment.