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

[PBE-5803] allow hiding file size in attachment component #5383

Merged
merged 3 commits into from
Aug 29, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -98,6 +98,7 @@ public object StreamAttachmentFactories {
streamCdnImageResizing: StreamCdnImageResizing,
skipEnrichUrl: Boolean,
) -> Unit = ::onMediaAttachmentContentItemClick,
showFileSize: (Attachment) -> Boolean = { true },
onFileContentItemClick: (
previewHandlers: List<AttachmentPreviewHandler>,
attachment: Attachment,
Expand All @@ -121,9 +122,9 @@ public object StreamAttachmentFactories {
onContentItemClick = onMediaContentItemClick,
),
FileAttachmentFactory(
showFileSize = showFileSize,
onContentItemClick = onFileContentItemClick,
),
FileAttachmentFactory(),
AudioRecordAttachmentFactory(),
UnsupportedAttachmentFactory(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AttachmentPreviewHandler>,
attachment: Attachment,
Expand Down Expand Up @@ -108,6 +109,7 @@ public fun FileAttachmentContent(
onLongClick = { onItemLongClick(message) },
),
attachment = attachment,
showFileSize = showFileSize,
)
}
}
Expand All @@ -122,6 +124,7 @@ public fun FileAttachmentContent(
@Composable
public fun FileAttachmentItem(
attachment: Attachment,
showFileSize: (Attachment) -> Boolean,
modifier: Modifier = Modifier,
) {
Surface(
Expand All @@ -137,7 +140,7 @@ public fun FileAttachmentItem(
verticalAlignment = Alignment.CenterVertically,
) {
FileAttachmentImage(attachment = attachment)
FileAttachmentDescription(attachment = attachment)
FileAttachmentDescription(attachment = attachment, showFileSize = showFileSize)
FileAttachmentDownloadIcon(attachment = attachment)
}
}
Expand All @@ -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)
Expand All @@ -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,
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import io.getstream.chat.android.uiutils.extension.isAnyFileType
*/
@Suppress("FunctionName")
public fun FileAttachmentFactory(
showFileSize: (Attachment) -> Boolean = { true },
onContentItemClick: (
previewHandlers: List<AttachmentPreviewHandler>,
attachment: Attachment,
Expand All @@ -57,6 +58,7 @@ public fun FileAttachmentFactory(
.wrapContentHeight()
.width(ChatTheme.dimens.attachmentsContentFileWidth),
attachmentState = state,
showFileSize = showFileSize,
onItemClick = onContentItemClick,
)
},
Expand Down
Loading