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

[AND-151] Improve attachment factories #5494

Merged
merged 3 commits into from
Dec 5, 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 @@ -71,6 +71,7 @@
### ⬆️ Improved

### ✅ Added
- The `StreamAttachmentFactories.defaultFactories()` method now accepts a `skipTypes` parameter to skip specific factory types. [#5494](https://github.com/GetStream/stream-chat-android/pull/5494)

### ⚠️ Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ public final class io/getstream/chat/android/compose/ui/attachments/AttachmentFa
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 (Lkotlin/jvm/functions/Function0;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;Lkotlin/jvm/functions/Function0;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 defaultFactories (Lkotlin/jvm/functions/Function0;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;)Ljava/util/List;
public static synthetic fun defaultFactories$default (Lio/getstream/chat/android/compose/ui/attachments/StreamAttachmentFactories;Lkotlin/jvm/functions/Function0;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;ILjava/lang/Object;)Ljava/util/List;
public final fun defaultQuotedFactories ()Ljava/util/List;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public object StreamAttachmentFactories {
* @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.
* @param skipTypes A list of [AttachmentFactory.Type] that should be skipped from the default factories.
*
* @return A [List] of various [AttachmentFactory] instances that provide different attachments support.
*/
Expand Down Expand Up @@ -108,6 +109,7 @@ public object StreamAttachmentFactories {
previewHandlers: List<AttachmentPreviewHandler>,
attachment: Attachment,
) -> Unit = ::onFileAttachmentContentItemClick,
skipTypes: List<AttachmentFactory.Type> = emptyList(),
JcMinarro marked this conversation as resolved.
Show resolved Hide resolved
): List<AttachmentFactory> = listOf(
UploadAttachmentFactory(
onContentItemClick = onUploadContentItemClick,
Expand Down Expand Up @@ -138,7 +140,7 @@ public object StreamAttachmentFactories {
onContentItemClick = onFileContentItemClick,
),
UnsupportedAttachmentFactory,
)
).filterNot { skipTypes.contains(it.type) }

/**
* Default quoted attachment factories we provide, which can transform image, file and link attachments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.net.toUri
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import io.getstream.chat.android.client.extensions.durationInMs
Expand Down Expand Up @@ -140,7 +141,10 @@ public fun AudioRecordAttachmentContent(
val viewModel = viewModel(AudioPlayerViewModel::class.java, factory = viewModelFactory)

val audioRecordings = attachmentState.message.attachments
.filter { attachment -> attachment.isAudioRecording() && attachment.assetUrl != null }
.filter { attachment ->
val attachmentUrl = attachment.assetUrl ?: attachment.upload?.toUri()?.toString()
attachment.isAudioRecording() && attachmentUrl != null
}

val playerState by viewModel.state.collectAsStateWithLifecycle()

Expand Down Expand Up @@ -241,7 +245,7 @@ internal fun AudioRecordAttachmentContentItemBase(
onThumbDragStop: (Attachment, Float) -> Unit = { _, _ -> },
tailContent: @Composable (isPlaying: Boolean) -> Unit = {},
) {
val attachmentUrl = attachment.assetUrl
val attachmentUrl = attachment.assetUrl ?: attachment.upload?.toUri()?.toString()
val isCurrentAttachment = attachmentUrl == playerState.current.audioUri
val trackProgress = playerState.current.playingProgress.takeIf { isCurrentAttachment }
?: attachmentUrl?.let { playerState.seekTo.getOrDefault(it.hashCode(), 0f) } ?: 0f
Expand Down
Loading