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

feat: add bottom sheet options to images and files on conversation media gallery [WPB-9049] #3337

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ import com.wire.android.util.ui.UIText
*/
interface SnackBarMessage {
val uiText: UIText
val actionLabel: UIText? get() = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.wire.android.R
import com.wire.android.model.SnackBarMessage
import com.wire.android.util.ui.UIText

sealed class ConversationSnackbarMessages(override val uiText: UIText) : SnackBarMessage {
sealed class ConversationSnackbarMessages(override val uiText: UIText, override val actionLabel: UIText? = null) : SnackBarMessage {
data object ErrorPickingAttachment : ConversationSnackbarMessages(UIText.StringResource(R.string.error_conversation_generic))
data object ErrorSendingAsset : ConversationSnackbarMessages(UIText.StringResource(R.string.error_conversation_sending_asset))
data object ErrorSendingImage : ConversationSnackbarMessages(UIText.StringResource(R.string.error_conversation_sending_image))
Expand All @@ -34,14 +34,19 @@ sealed class ConversationSnackbarMessages(override val uiText: UIText) : SnackBa
ConversationSnackbarMessages(UIText.StringResource(R.string.error_conversation_max_asset_size_limit, maxLimitInMB))

data class OnFileDownloaded(val assetName: String?) :
ConversationSnackbarMessages(UIText.StringResource(R.string.conversation_on_file_downloaded, assetName ?: ""))
ConversationSnackbarMessages(
uiText = UIText.StringResource(R.string.conversation_on_file_downloaded, assetName ?: ""),
actionLabel = UIText.StringResource(R.string.label_show)
)

data class OnResetSession(val text: UIText) : ConversationSnackbarMessages(text)
}

sealed class MediaGallerySnackbarMessages(override val uiText: UIText) : SnackBarMessage {
class OnImageDownloaded(val assetName: String? = null) :
MediaGallerySnackbarMessages(UIText.StringResource(R.string.media_gallery_on_image_downloaded, assetName ?: ""))
sealed class MediaGallerySnackbarMessages(override val uiText: UIText, override val actionLabel: UIText? = null) : SnackBarMessage {
class OnImageDownloaded(val assetName: String? = null) : MediaGallerySnackbarMessages(
uiText = UIText.StringResource(R.string.media_gallery_on_image_downloaded, assetName ?: ""),
actionLabel = UIText.StringResource(R.string.label_show)
)

data object OnImageDownloadError : MediaGallerySnackbarMessages(UIText.StringResource(R.string.media_gallery_on_image_download_error))
data object DeletingMessageError : MediaGallerySnackbarMessages(UIText.StringResource(R.string.error_conversation_deleting_message))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ import com.wire.android.navigation.WireDestination
import com.wire.android.ui.LocalActivity
import com.wire.android.ui.calling.getOutgoingCallIntent
import com.wire.android.ui.calling.ongoing.getOngoingCallIntent
import com.wire.android.ui.common.bottomsheet.MenuModalSheetHeader
import com.wire.android.ui.common.bottomsheet.WireMenuModalSheetContent
import com.wire.android.ui.common.bottomsheet.WireModalSheetLayout
import com.wire.android.ui.common.colorsScheme
import com.wire.android.ui.common.dialogs.ConfirmSendingPingDialog
import com.wire.android.ui.common.dialogs.InvalidLinkDialog
Expand Down Expand Up @@ -127,7 +124,7 @@ import com.wire.android.ui.home.conversations.call.ConversationListCallViewModel
import com.wire.android.ui.home.conversations.composer.MessageComposerViewModel
import com.wire.android.ui.home.conversations.delete.DeleteMessageDialog
import com.wire.android.ui.home.conversations.details.GroupConversationDetailsNavBackArgs
import com.wire.android.ui.home.conversations.edit.messageOptionsMenuItems
import com.wire.android.ui.home.conversations.edit.MessageOptionsModalSheetLayout
import com.wire.android.ui.home.conversations.info.ConversationDetailsData
import com.wire.android.ui.home.conversations.info.ConversationInfoViewModel
import com.wire.android.ui.home.conversations.info.ConversationInfoViewState
Expand All @@ -140,8 +137,7 @@ import com.wire.android.ui.home.conversations.messages.item.SwipableMessageConfi
import com.wire.android.ui.home.conversations.migration.ConversationMigrationViewModel
import com.wire.android.ui.home.conversations.model.ExpirationStatus
import com.wire.android.ui.home.conversations.model.UIMessage
import com.wire.android.ui.home.conversations.selfdeletion.SelfDeletionMapper.toSelfDeletionDuration
import com.wire.android.ui.home.conversations.selfdeletion.selfDeletionMenuItems
import com.wire.android.ui.home.conversations.selfdeletion.SelfDeletionOptionsModalSheetLayout
import com.wire.android.ui.home.conversations.sendmessage.SendMessageViewModel
import com.wire.android.ui.home.gallery.MediaGalleryActionType
import com.wire.android.ui.home.gallery.MediaGalleryNavBackArgs
Expand Down Expand Up @@ -841,42 +837,21 @@ private fun ConversationScreen(
}
}
)
WireModalSheetLayout(
SelfDeletionOptionsModalSheetLayout(
sheetState = conversationScreenState.selfDeletingSheetState,
sheetContent = { currentlySelected ->
WireMenuModalSheetContent(
header = MenuModalSheetHeader.Visible(title = stringResource(R.string.automatically_delete_message_after)),
menuItems = selfDeletionMenuItems(
currentlySelected = currentlySelected.duration.toSelfDeletionDuration(),
onSelfDeletionDurationChanged = { newTimer ->
conversationScreenState.selfDeletingSheetState.hide {
onNewSelfDeletingMessagesStatus(SelfDeletionTimer.Enabled(newTimer.value))
}
}
)
)
}
onNewSelfDeletingMessagesStatus = onNewSelfDeletingMessagesStatus
)
WireModalSheetLayout(
MessageOptionsModalSheetLayout(
sheetState = conversationScreenState.editSheetState,
sheetContent = { selectedMessage ->
WireMenuModalSheetContent(
header = MenuModalSheetHeader.Gone,
menuItems = messageOptionsMenuItems(
message = selectedMessage,
hideEditMessageMenu = remember { { conversationScreenState.editSheetState.hide() } },
onCopyClick = conversationScreenState::copyMessage,
onDeleteClick = onDeleteMessage,
onReactionClick = onReactionClick,
onDetailsClick = onMessageDetailsClick,
onReplyClick = messageComposerStateHolder::toReply,
onEditClick = messageComposerStateHolder::toEdit,
onShareAssetClick = { shareAsset(context, it) },
onDownloadAssetClick = onDownloadAssetClick,
onOpenAssetClick = onOpenAssetClick,
)
)
}
onCopyClick = conversationScreenState::copyMessage,
onDeleteClick = onDeleteMessage,
onReactionClick = onReactionClick,
onDetailsClick = onMessageDetailsClick,
onReplyClick = messageComposerStateHolder::toReply,
onEditClick = messageComposerStateHolder::toEdit,
onShareAssetClick = { shareAsset(context, it) },
onDownloadAssetClick = onDownloadAssetClick,
onOpenAssetClick = onOpenAssetClick,
)

SnackBarMessage(composerMessages, conversationMessages)
Expand Down Expand Up @@ -1132,7 +1107,7 @@ fun MessageList(
conversationDetailsData = conversationDetailsData,
showAuthor = showAuthor,
useSmallBottomPadding = useSmallBottomPadding,
audioMessagesState = audioMessagesState,
audioState = audioMessagesState[message.header.messageId],
assetStatus = assetStatuses[message.header.messageId]?.transferStatus,
onAudioClick = onAudioItemClicked,
onChangeAudioPosition = onChangeAudioPosition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ fun assetOptionsMenuItems(
add { DownloadAssetExternallyOption(onDownloadAsset) }
if (!isEphemeral) add { ShareAssetMenuOption(onShareAsset) }
if (isOpenable) add { OpenAssetExternallyOption(onOpenAsset) }
add { DeleteItemMenuOption(onDeleteClick) }
}
add { DeleteItemMenuOption(onDeleteClick) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,121 +19,38 @@
package com.wire.android.ui.home.conversations.edit

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import com.wire.android.ui.home.conversations.model.ExpirationStatus
import com.wire.android.ui.home.conversations.model.UIMessage
import com.wire.android.ui.home.conversations.model.UIMessageContent
import com.wire.android.util.Copyable
import com.wire.android.util.ui.UIText
import com.wire.kalium.logic.data.message.mention.MessageMention

@Composable
fun messageOptionsMenuItems(
message: UIMessage.Regular,
hideEditMessageMenu: (OnComplete) -> Unit,
onCopyClick: (text: String) -> Unit,
onDeleteClick: (messageId: String, isMyMessage: Boolean) -> Unit,
onReactionClick: (messageId: String, reactionEmoji: String) -> Unit,
onDetailsClick: (messageId: String, isSelfMessage: Boolean) -> Unit,
onReplyClick: (UIMessage.Regular) -> Unit,
onEditClick: (messageId: String, messageBody: String, mentions: List<MessageMention>) -> Unit,
onShareAssetClick: (messageId: String) -> Unit,
onDownloadAssetClick: (messageId: String) -> Unit,
onOpenAssetClick: (messageId: String) -> Unit
isAssetMessage: Boolean,
isEphemeral: Boolean,
isUploading: Boolean,
isOpenable: Boolean,
isComposite: Boolean,
isEditable: Boolean,
isCopyable: Boolean,
onCopyClick: () -> Unit,
onDeleteClick: () -> Unit,
onReactionClick: (reactionEmoji: String) -> Unit,
onDetailsClick: () -> Unit,
onReplyClick: () -> Unit,
onEditClick: () -> Unit,
onShareAssetClick: () -> Unit,
onDownloadAssetClick: () -> Unit,
onOpenAssetClick: () -> Unit
): List<@Composable () -> Unit> {
val localContext = LocalContext.current
val isUploading = message.isPending
val isDeleted = message.isDeleted
val isMyMessage = message.isMyMessage
val isComposite = message.messageContent is UIMessageContent.Composite
val isEphemeral = message.header.messageStatus.expirationStatus is ExpirationStatus.Expirable
val isEditable = !isUploading && !isDeleted && message.messageContent is UIMessageContent.TextMessage && isMyMessage
val isCopyable = !isUploading && !isDeleted && message.messageContent is Copyable

val onCopyItemClick = remember(message.messageContent) {
(message.messageContent as? Copyable)?.textToCopy(localContext.resources)?.let {
{
hideEditMessageMenu { onCopyClick(it) }
}
} ?: {}
}

val onDeleteItemClick = remember(message.header.messageId) {
{
hideEditMessageMenu {
onDeleteClick(message.header.messageId, message.isMyMessage)
}
}
}
val onReactionItemClick: (emoji: String) -> Unit = remember(message.header.messageId) {
{
hideEditMessageMenu {
onReactionClick(message.header.messageId, it)
}
}
}
val onReplyItemClick = remember(message.header.messageId) {
{
hideEditMessageMenu {
onReplyClick(message)
}
}
}
val onDetailsItemClick = remember(message.header.messageId) {
{
hideEditMessageMenu {
onDetailsClick(message.header.messageId, message.isMyMessage)
}
}
}
val onEditItemClick = remember(message) {
{
hideEditMessageMenu {
with(message.messageContent as UIMessageContent.TextMessage) {
onEditClick(
message.header.messageId,
messageBody.message.asString(localContext.resources),
if (messageBody.message is UIText.DynamicString) messageBody.message.mentions else listOf()
)
}
}
}
}
val onDownloadAssetItemClick = remember(message) {
{
hideEditMessageMenu {
onDownloadAssetClick(message.header.messageId)
}
}
}
val onOpenAssetItemClick = remember(message) {
{
hideEditMessageMenu {
onOpenAssetClick(message.header.messageId)
}
}
}
val onShareAssetItemClick = remember(message) {
{
hideEditMessageMenu {
onShareAssetClick(message.header.messageId)
}
}
}

return if (message.isAssetMessage) {
return if (isAssetMessage) {
assetMessageOptionsMenuItems(
isEphemeral = isEphemeral,
isUploading = isUploading,
isOpenable = true,
onDeleteClick = onDeleteItemClick,
onDetailsClick = onDetailsItemClick,
onShareAsset = onShareAssetItemClick,
onDownloadAsset = onDownloadAssetItemClick,
onReplyClick = onReplyItemClick,
onReactionClick = onReactionItemClick,
onOpenAsset = onOpenAssetItemClick,
isOpenable = isOpenable,
onDeleteClick = onDeleteClick,
onDetailsClick = onDetailsClick,
onShareAsset = onShareAssetClick,
onDownloadAsset = onDownloadAssetClick,
onReplyClick = onReplyClick,
onReactionClick = onReactionClick,
onOpenAsset = onOpenAssetClick,
)
} else {
textMessageEditMenuItems(
Expand All @@ -142,14 +59,12 @@ fun messageOptionsMenuItems(
isComposite = isComposite,
isEditable = isEditable,
isCopyable = isCopyable,
onDeleteClick = onDeleteItemClick,
onDetailsClick = onDetailsItemClick,
onReactionClick = onReactionItemClick,
onEditClick = onEditItemClick,
onCopyClick = onCopyItemClick,
onReplyClick = onReplyItemClick
onDeleteClick = onDeleteClick,
onDetailsClick = onDetailsClick,
onReactionClick = onReactionClick,
onEditClick = onEditClick,
onCopyClick = onCopyClick,
onReplyClick = onReplyClick
)
}
}

typealias OnComplete = () -> Unit
Loading
Loading