From e0675d5d1dbbd0601a88a15806be044d0dda6b26 Mon Sep 17 00:00:00 2001 From: Evgenii Kozlov Date: Mon, 13 Jan 2025 13:03:27 +0100 Subject: [PATCH] DROID-3223 Space-level chat | Fix | Attachment number (#1987) --- .../presentation/DiscussionView.kt | 4 + .../ui/DiscussionScreen.kt | 144 +++++++++--------- 2 files changed, 80 insertions(+), 68 deletions(-) diff --git a/feature-discussions/src/main/java/com/anytypeio/anytype/feature_discussions/presentation/DiscussionView.kt b/feature-discussions/src/main/java/com/anytypeio/anytype/feature_discussions/presentation/DiscussionView.kt index 0f63ab4c39..8e47f41b23 100644 --- a/feature-discussions/src/main/java/com/anytypeio/anytype/feature_discussions/presentation/DiscussionView.kt +++ b/feature-discussions/src/main/java/com/anytypeio/anytype/feature_discussions/presentation/DiscussionView.kt @@ -87,4 +87,8 @@ sealed interface DiscussionView { data class Image(val hash: Hash): Avatar() } } +} + +object ChatConfig { + const val MAX_ATTACHMENT_COUNT = 10 } \ No newline at end of file diff --git a/feature-discussions/src/main/java/com/anytypeio/anytype/feature_discussions/ui/DiscussionScreen.kt b/feature-discussions/src/main/java/com/anytypeio/anytype/feature_discussions/ui/DiscussionScreen.kt index 58ca01af16..ecfe20ff0b 100644 --- a/feature-discussions/src/main/java/com/anytypeio/anytype/feature_discussions/ui/DiscussionScreen.kt +++ b/feature-discussions/src/main/java/com/anytypeio/anytype/feature_discussions/ui/DiscussionScreen.kt @@ -143,6 +143,7 @@ import com.anytypeio.anytype.core_utils.const.DateConst.TIME_H24 import com.anytypeio.anytype.core_utils.ext.formatTimeInMillis import com.anytypeio.anytype.core_utils.ext.parseImagePath import com.anytypeio.anytype.feature_discussions.R +import com.anytypeio.anytype.feature_discussions.presentation.ChatConfig import com.anytypeio.anytype.feature_discussions.presentation.DiscussionView import com.anytypeio.anytype.feature_discussions.presentation.DiscussionViewModel import com.anytypeio.anytype.feature_discussions.presentation.DiscussionViewModel.ChatBoxMode @@ -522,12 +523,17 @@ private fun ChatBox( onChatBoxMediaPicked: (List) -> Unit, onChatBoxFilePicked: (List) -> Unit, ) { - val uploadMediaLauncher = rememberLauncherForActivityResult(ActivityResultContracts.PickMultipleVisualMedia()) { + + val uploadMediaLauncher = rememberLauncherForActivityResult( + ActivityResultContracts.PickMultipleVisualMedia(maxItems = ChatConfig.MAX_ATTACHMENT_COUNT) + ) { onChatBoxMediaPicked(it) } - val uploadFileLauncher = rememberLauncherForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { - onChatBoxFilePicked(it) + val uploadFileLauncher = rememberLauncherForActivityResult( + ActivityResultContracts.OpenMultipleDocuments() + ) { uris -> + onChatBoxFilePicked(uris.take(ChatConfig.MAX_ATTACHMENT_COUNT)) } var showDropdownMenu by remember { mutableStateOf(false) } @@ -763,76 +769,78 @@ private fun ChatBox( .align(Alignment.Center) .padding(horizontal = 4.dp, vertical = 4.dp) ) - MaterialTheme( - shapes = MaterialTheme.shapes.copy( - medium = RoundedCornerShape( - 12.dp - ) - ), - colors = MaterialTheme.colors.copy( - surface = colorResource(id = R.color.background_secondary) - ) - ) { - DropdownMenu( - offset = DpOffset(8.dp, 40.dp), - expanded = showDropdownMenu, - onDismissRequest = { - showDropdownMenu = false - }, - modifier = Modifier - .align(Alignment.BottomEnd) - .defaultMinSize( - minWidth = 252.dp + if (attachments.size < ChatConfig.MAX_ATTACHMENT_COUNT) { + MaterialTheme( + shapes = MaterialTheme.shapes.copy( + medium = RoundedCornerShape( + 12.dp ) + ), + colors = MaterialTheme.colors.copy( + surface = colorResource(id = R.color.background_secondary) + ) ) { - DropdownMenuItem( - text = { - Text( - text = stringResource(R.string.chat_attachment_object), - color = colorResource(id = R.color.text_primary) - ) - }, - onClick = { + DropdownMenu( + offset = DpOffset(8.dp, 40.dp), + expanded = showDropdownMenu, + onDismissRequest = { showDropdownMenu = false - onAttachObjectClicked() - } - ) - Divider( - paddingStart = 0.dp, - paddingEnd = 0.dp - ) - DropdownMenuItem( - text = { - Text( - text = stringResource(R.string.chat_attachment_media), - color = colorResource(id = R.color.text_primary) - ) }, - onClick = { - showDropdownMenu = false - uploadMediaLauncher.launch( - PickVisualMediaRequest(mediaType = ActivityResultContracts.PickVisualMedia.ImageOnly) + modifier = Modifier + .align(Alignment.BottomEnd) + .defaultMinSize( + minWidth = 252.dp ) - } - ) - Divider( - paddingStart = 0.dp, - paddingEnd = 0.dp - ) - DropdownMenuItem( - text = { - Text( - text = stringResource(R.string.chat_attachment_file), - color = colorResource(id = R.color.text_primary) - ) - }, - onClick = { - showDropdownMenu = false - uploadFileLauncher.launch( - arrayOf("*/*") - ) - } - ) + ) { + DropdownMenuItem( + text = { + Text( + text = stringResource(R.string.chat_attachment_object), + color = colorResource(id = R.color.text_primary) + ) + }, + onClick = { + showDropdownMenu = false + onAttachObjectClicked() + } + ) + Divider( + paddingStart = 0.dp, + paddingEnd = 0.dp + ) + DropdownMenuItem( + text = { + Text( + text = stringResource(R.string.chat_attachment_media), + color = colorResource(id = R.color.text_primary) + ) + }, + onClick = { + showDropdownMenu = false + uploadMediaLauncher.launch( + PickVisualMediaRequest(mediaType = ActivityResultContracts.PickVisualMedia.ImageOnly) + ) + } + ) + Divider( + paddingStart = 0.dp, + paddingEnd = 0.dp + ) + DropdownMenuItem( + text = { + Text( + text = stringResource(R.string.chat_attachment_file), + color = colorResource(id = R.color.text_primary) + ) + }, + onClick = { + showDropdownMenu = false + uploadFileLauncher.launch( + arrayOf("*/*") + ) + } + ) + } } } }