diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e52f56fecb..9eb33c7f2da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -86,6 +86,7 @@ - Expose `topBarContent` and `bottomBarContent` in `MessageScreen`. [#5377](https://github.com/GetStream/stream-chat-android/pull/5377) ### ⬆️ Improved +- Added `showFileSize` parameter to `StreamAttachmentFactories.defaultFactories` to control file size UI visibility. [#5383](https://github.com/GetStream/stream-chat-android/pull/5383) ### ✅ Added - Add `PollDialogs` component used to show poll dialogs. [#5370](https://github.com/GetStream/stream-chat-android/pull/5370) diff --git a/stream-chat-android-compose/api/stream-chat-android-compose.api b/stream-chat-android-compose/api/stream-chat-android-compose.api index 0f19379f9be..7bebbf530fa 100644 --- a/stream-chat-android-compose/api/stream-chat-android-compose.api +++ b/stream-chat-android-compose/api/stream-chat-android-compose.api @@ -383,8 +383,8 @@ public class io/getstream/chat/android/compose/ui/attachments/AttachmentFactory public final class io/getstream/chat/android/compose/ui/attachments/StreamAttachmentFactories { public static final field $stable I public static final field INSTANCE Lio/getstream/chat/android/compose/ui/attachments/StreamAttachmentFactories; - public final fun defaultFactories (ILio/getstream/chat/android/ui/common/utils/GiphyInfoType;Lio/getstream/chat/android/ui/common/utils/GiphySizingMode;Landroidx/compose/ui/layout/ContentScale;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function6;Lkotlin/jvm/functions/Function2;)Ljava/util/List; - public static synthetic fun defaultFactories$default (Lio/getstream/chat/android/compose/ui/attachments/StreamAttachmentFactories;ILio/getstream/chat/android/ui/common/utils/GiphyInfoType;Lio/getstream/chat/android/ui/common/utils/GiphySizingMode;Landroidx/compose/ui/layout/ContentScale;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function6;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Ljava/util/List; + public final fun defaultFactories (ILio/getstream/chat/android/ui/common/utils/GiphyInfoType;Lio/getstream/chat/android/ui/common/utils/GiphySizingMode;Landroidx/compose/ui/layout/ContentScale;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function6;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljava/util/List; + public static synthetic fun defaultFactories$default (Lio/getstream/chat/android/compose/ui/attachments/StreamAttachmentFactories;ILio/getstream/chat/android/ui/common/utils/GiphyInfoType;Lio/getstream/chat/android/ui/common/utils/GiphySizingMode;Landroidx/compose/ui/layout/ContentScale;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function6;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Ljava/util/List; public final fun defaultQuotedFactories ()Ljava/util/List; } @@ -440,9 +440,9 @@ public final class io/getstream/chat/android/compose/ui/attachments/content/Comp } public final class io/getstream/chat/android/compose/ui/attachments/content/FileAttachmentContentKt { - public static final fun FileAttachmentContent (Lio/getstream/chat/android/compose/state/messages/attachments/AttachmentState;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V + public static final fun FileAttachmentContent (Lio/getstream/chat/android/compose/state/messages/attachments/AttachmentState;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V public static final fun FileAttachmentImage (Lio/getstream/chat/android/models/Attachment;Landroidx/compose/runtime/Composer;I)V - public static final fun FileAttachmentItem (Lio/getstream/chat/android/models/Attachment;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V + public static final fun FileAttachmentItem (Lio/getstream/chat/android/models/Attachment;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V } public final class io/getstream/chat/android/compose/ui/attachments/content/FileAttachmentPreviewContentKt { @@ -536,8 +536,8 @@ public final class io/getstream/chat/android/compose/ui/attachments/factory/Comp } public final class io/getstream/chat/android/compose/ui/attachments/factory/FileAttachmentFactoryKt { - public static final fun FileAttachmentFactory (Lkotlin/jvm/functions/Function2;)Lio/getstream/chat/android/compose/ui/attachments/AttachmentFactory; - public static synthetic fun FileAttachmentFactory$default (Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lio/getstream/chat/android/compose/ui/attachments/AttachmentFactory; + public static final fun FileAttachmentFactory (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lio/getstream/chat/android/compose/ui/attachments/AttachmentFactory; + public static synthetic fun FileAttachmentFactory$default (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lio/getstream/chat/android/compose/ui/attachments/AttachmentFactory; } public final class io/getstream/chat/android/compose/ui/attachments/factory/GiphyAttachmentFactoryKt { diff --git a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/StreamAttachmentFactories.kt b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/StreamAttachmentFactories.kt index 317f3cf452d..79fbc96b0b2 100644 --- a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/StreamAttachmentFactories.kt +++ b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/StreamAttachmentFactories.kt @@ -74,7 +74,7 @@ public object StreamAttachmentFactories { * @param onGiphyContentItemClick Lambda called when a giphy attachment content item gets clicked. * @param onMediaContentItemClick Lambda called when a image or video attachment content item gets clicked. * @param onFileContentItemClick Lambda called when a file attachment content item gets clicked. - + * @param showFileSize Lambda called to determine if the file size should be shown for a given attachment. * * @return A [List] of various [AttachmentFactory] instances that provide different attachments support. */ @@ -98,6 +98,7 @@ public object StreamAttachmentFactories { streamCdnImageResizing: StreamCdnImageResizing, skipEnrichUrl: Boolean, ) -> Unit = ::onMediaAttachmentContentItemClick, + showFileSize: (Attachment) -> Boolean = { true }, onFileContentItemClick: ( previewHandlers: List, attachment: Attachment, @@ -121,9 +122,9 @@ public object StreamAttachmentFactories { onContentItemClick = onMediaContentItemClick, ), FileAttachmentFactory( + showFileSize = showFileSize, onContentItemClick = onFileContentItemClick, ), - FileAttachmentFactory(), AudioRecordAttachmentFactory(), UnsupportedAttachmentFactory(), ) diff --git a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/content/FileAttachmentContent.kt b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/content/FileAttachmentContent.kt index 070e330a2f5..41031facc79 100644 --- a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/content/FileAttachmentContent.kt +++ b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/content/FileAttachmentContent.kt @@ -78,6 +78,7 @@ import io.getstream.chat.android.ui.common.utils.extensions.imagePreviewUrl public fun FileAttachmentContent( attachmentState: AttachmentState, modifier: Modifier = Modifier, + showFileSize: (Attachment) -> Boolean = { true }, onItemClick: ( previewHandlers: List, attachment: Attachment, @@ -108,6 +109,7 @@ public fun FileAttachmentContent( onLongClick = { onItemLongClick(message) }, ), attachment = attachment, + showFileSize = showFileSize, ) } } @@ -122,6 +124,7 @@ public fun FileAttachmentContent( @Composable public fun FileAttachmentItem( attachment: Attachment, + showFileSize: (Attachment) -> Boolean, modifier: Modifier = Modifier, ) { Surface( @@ -137,7 +140,7 @@ public fun FileAttachmentItem( verticalAlignment = Alignment.CenterVertically, ) { FileAttachmentImage(attachment = attachment) - FileAttachmentDescription(attachment = attachment) + FileAttachmentDescription(attachment = attachment, showFileSize = showFileSize) FileAttachmentDownloadIcon(attachment = attachment) } } @@ -150,7 +153,10 @@ public fun FileAttachmentItem( * @param attachment The attachment for which the information is displayed. */ @Composable -private fun FileAttachmentDescription(attachment: Attachment) { +private fun FileAttachmentDescription( + attachment: Attachment, + showFileSize: (Attachment) -> Boolean, +) { Column( modifier = Modifier .fillMaxWidth(0.85f) @@ -166,11 +172,13 @@ private fun FileAttachmentDescription(attachment: Attachment) { color = ChatTheme.colors.textHighEmphasis, ) - Text( - text = MediaStringUtil.convertFileSizeByteCount(attachment.fileSize.toLong()), - style = ChatTheme.typography.footnote, - color = ChatTheme.colors.textLowEmphasis, - ) + if (showFileSize(attachment)) { + Text( + text = MediaStringUtil.convertFileSizeByteCount(attachment.fileSize.toLong()), + style = ChatTheme.typography.footnote, + color = ChatTheme.colors.textLowEmphasis, + ) + } } } diff --git a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/factory/FileAttachmentFactory.kt b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/factory/FileAttachmentFactory.kt index 6485206eac9..f6dc142e456 100644 --- a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/factory/FileAttachmentFactory.kt +++ b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/factory/FileAttachmentFactory.kt @@ -36,6 +36,7 @@ import io.getstream.chat.android.uiutils.extension.isAnyFileType */ @Suppress("FunctionName") public fun FileAttachmentFactory( + showFileSize: (Attachment) -> Boolean = { true }, onContentItemClick: ( previewHandlers: List, attachment: Attachment, @@ -57,6 +58,7 @@ public fun FileAttachmentFactory( .wrapContentHeight() .width(ChatTheme.dimens.attachmentsContentFileWidth), attachmentState = state, + showFileSize = showFileSize, onItemClick = onContentItemClick, ) },