Skip to content

Commit

Permalink
Refactor swipeToReply attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
JcMinarro committed Feb 15, 2025
1 parent 21a8000 commit 341a64b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2542,7 +2542,7 @@ public abstract interface class io/getstream/chat/android/ui/feature/messages/li

public final class io/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle : io/getstream/chat/android/ui/helper/ViewStyle {
public static final field Companion Lio/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle$Companion;
public fun <init> (Lio/getstream/chat/android/ui/feature/messages/list/ScrollButtonViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$NewMessagesBehaviour;Lio/getstream/chat/android/ui/feature/messages/list/MessageListItemStyle;Lio/getstream/chat/android/ui/feature/messages/list/GiphyViewHolderStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageReplyStyle;Lio/getstream/chat/android/ui/feature/messages/list/UnreadLabelButtonStyle;ZIIZIZIIIZIIZIIZIZIIZZZZZZLio/getstream/chat/android/ui/font/TextStyle;Lio/getstream/chat/android/ui/font/TextStyle;IILio/getstream/chat/android/ui/font/TextStyle;ILio/getstream/chat/android/ui/font/TextStyle;IIIIIIZIIIIIIIIIIIIZZLandroid/graphics/drawable/Drawable;)V
public fun <init> (Lio/getstream/chat/android/ui/feature/messages/list/ScrollButtonViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$NewMessagesBehaviour;Lio/getstream/chat/android/ui/feature/messages/list/MessageListItemStyle;Lio/getstream/chat/android/ui/feature/messages/list/GiphyViewHolderStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageReplyStyle;Lio/getstream/chat/android/ui/feature/messages/list/UnreadLabelButtonStyle;ZIIZIZIIIZIIZIIZIZIIZZZZZZLio/getstream/chat/android/ui/font/TextStyle;Lio/getstream/chat/android/ui/font/TextStyle;IILio/getstream/chat/android/ui/font/TextStyle;ILio/getstream/chat/android/ui/font/TextStyle;IIIIIIZIIIIIIIIIIIIZZZI)V
public final fun component1 ()Lio/getstream/chat/android/ui/feature/messages/list/ScrollButtonViewStyle;
public final fun component10 ()I
public final fun component11 ()Z
Expand Down Expand Up @@ -2601,12 +2601,13 @@ public final class io/getstream/chat/android/ui/feature/messages/list/MessageLis
public final fun component6 ()Lio/getstream/chat/android/ui/feature/messages/list/MessageReplyStyle;
public final fun component60 ()Z
public final fun component61 ()Z
public final fun component62 ()Landroid/graphics/drawable/Drawable;
public final fun component62 ()Z
public final fun component63 ()I
public final fun component7 ()Lio/getstream/chat/android/ui/feature/messages/list/UnreadLabelButtonStyle;
public final fun component8 ()Z
public final fun component9 ()I
public final fun copy (Lio/getstream/chat/android/ui/feature/messages/list/ScrollButtonViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$NewMessagesBehaviour;Lio/getstream/chat/android/ui/feature/messages/list/MessageListItemStyle;Lio/getstream/chat/android/ui/feature/messages/list/GiphyViewHolderStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageReplyStyle;Lio/getstream/chat/android/ui/feature/messages/list/UnreadLabelButtonStyle;ZIIZIZIIIZIIZIIZIZIIZZZZZZLio/getstream/chat/android/ui/font/TextStyle;Lio/getstream/chat/android/ui/font/TextStyle;IILio/getstream/chat/android/ui/font/TextStyle;ILio/getstream/chat/android/ui/font/TextStyle;IIIIIIZIIIIIIIIIIIIZZLandroid/graphics/drawable/Drawable;)Lio/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle;
public static synthetic fun copy$default (Lio/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/ScrollButtonViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$NewMessagesBehaviour;Lio/getstream/chat/android/ui/feature/messages/list/MessageListItemStyle;Lio/getstream/chat/android/ui/feature/messages/list/GiphyViewHolderStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageReplyStyle;Lio/getstream/chat/android/ui/feature/messages/list/UnreadLabelButtonStyle;ZIIZIZIIIZIIZIIZIZIIZZZZZZLio/getstream/chat/android/ui/font/TextStyle;Lio/getstream/chat/android/ui/font/TextStyle;IILio/getstream/chat/android/ui/font/TextStyle;ILio/getstream/chat/android/ui/font/TextStyle;IIIIIIZIIIIIIIIIIIIZZLandroid/graphics/drawable/Drawable;IILjava/lang/Object;)Lio/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle;
public final fun copy (Lio/getstream/chat/android/ui/feature/messages/list/ScrollButtonViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$NewMessagesBehaviour;Lio/getstream/chat/android/ui/feature/messages/list/MessageListItemStyle;Lio/getstream/chat/android/ui/feature/messages/list/GiphyViewHolderStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageReplyStyle;Lio/getstream/chat/android/ui/feature/messages/list/UnreadLabelButtonStyle;ZIIZIZIIIZIIZIIZIZIIZZZZZZLio/getstream/chat/android/ui/font/TextStyle;Lio/getstream/chat/android/ui/font/TextStyle;IILio/getstream/chat/android/ui/font/TextStyle;ILio/getstream/chat/android/ui/font/TextStyle;IIIIIIZIIIIIIIIIIIIZZZI)Lio/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle;
public static synthetic fun copy$default (Lio/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/ScrollButtonViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageListView$NewMessagesBehaviour;Lio/getstream/chat/android/ui/feature/messages/list/MessageListItemStyle;Lio/getstream/chat/android/ui/feature/messages/list/GiphyViewHolderStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageViewStyle;Lio/getstream/chat/android/ui/feature/messages/list/MessageReplyStyle;Lio/getstream/chat/android/ui/feature/messages/list/UnreadLabelButtonStyle;ZIIZIZIIIZIIZIIZIZIIZZZZZZLio/getstream/chat/android/ui/font/TextStyle;Lio/getstream/chat/android/ui/font/TextStyle;IILio/getstream/chat/android/ui/font/TextStyle;ILio/getstream/chat/android/ui/font/TextStyle;IIIIIIZIIIIIIIIIIIIZZZIIILjava/lang/Object;)Lio/getstream/chat/android/ui/feature/messages/list/MessageListViewStyle;
public fun equals (Ljava/lang/Object;)Z
public final fun getAudioRecordPlayerViewStyle ()Lio/getstream/chat/android/ui/feature/messages/list/MessageViewStyle;
public final fun getBackgroundColor ()I
Expand Down Expand Up @@ -2660,7 +2661,8 @@ public final class io/getstream/chat/android/ui/feature/messages/list/MessageLis
public final fun getScrollButtonEndMargin ()I
public final fun getScrollButtonViewStyle ()Lio/getstream/chat/android/ui/feature/messages/list/ScrollButtonViewStyle;
public final fun getShowReactionsForUnsentMessages ()Z
public final fun getSwipeToReplyIcon ()Landroid/graphics/drawable/Drawable;
public final fun getSwipeToReplyEnabled ()Z
public final fun getSwipeToReplyIcon ()I
public final fun getThreadMessagesStart ()I
public final fun getThreadReplyIcon ()I
public final fun getThreadsEnabled ()Z
Expand Down Expand Up @@ -2797,6 +2799,7 @@ public abstract class io/getstream/chat/android/ui/feature/messages/list/adapter
public fun <init> (Landroid/view/View;)V
public abstract fun bindData (Lio/getstream/chat/android/ui/feature/messages/list/adapter/MessageListItem;Lio/getstream/chat/android/ui/feature/messages/list/adapter/MessageListItemPayloadDiff;)V
protected final fun getContext ()Landroid/content/Context;
public final fun getData ()Lio/getstream/chat/android/ui/feature/messages/list/adapter/MessageListItem;
public fun messageContainerView ()Landroid/view/View;
public fun onAttachedToWindow ()V
public fun onDetachedFromWindow ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,24 +732,27 @@ public class MessageListView : ConstraintLayout {
}

private fun initSwipeToReply() {
messageListViewStyle?.swipeToReplyIcon?.let { swipeToReplyIcon ->
SwipeReplyCallback(swipeToReplyIcon) { message ->
message
?.let { messageListViewStyle?.canReplyToMessage(it, ownCapabilities) }
?: false
}.let { swipeReplyCallback ->
ItemTouchHelper(swipeReplyCallback).let { itemTouchHelper ->
swipeReplyCallback.onReply = {
// We need to detach and attach the itemTouchHelper to the RecyclerView to make it work after
// the reply action is completed.
itemTouchHelper.attachToRecyclerView(null)
messageListViewStyle?.swipeToReplyIcon
?.takeUnless { messageListViewStyle?.swipeToReplyEnabled == false }
?.let(context::getDrawable)
?.let { swipeToReplyIcon ->
SwipeReplyCallback(swipeToReplyIcon) { message ->
message
?.let { messageListViewStyle?.canReplyToMessage(it, ownCapabilities) }
?: false
}.let { swipeReplyCallback ->
ItemTouchHelper(swipeReplyCallback).let { itemTouchHelper ->
swipeReplyCallback.onReply = {
// We need to detach and attach the itemTouchHelper to the RecyclerView to make it work
// after the reply action is completed.
itemTouchHelper.attachToRecyclerView(null)
itemTouchHelper.attachToRecyclerView(binding.chatMessagesRV)
messageReplyHandler.onMessageReply(it.cid, it)
}
itemTouchHelper.attachToRecyclerView(binding.chatMessagesRV)
messageReplyHandler.onMessageReply(it.cid, it)
}
itemTouchHelper.attachToRecyclerView(binding.chatMessagesRV)
}
}
}
}

private fun configureAttributes(attributeSet: AttributeSet?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package io.getstream.chat.android.ui.feature.messages.list
import android.content.Context
import android.content.res.TypedArray
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.Gravity
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.annotation.LayoutRes
import io.getstream.chat.android.ui.R
import io.getstream.chat.android.ui.common.state.messages.list.MessageOptionsUserReactionAlignment
Expand Down Expand Up @@ -101,6 +101,8 @@ import io.getstream.chat.android.ui.utils.extensions.use
* @property optionsOverlayMessageOptionsMarginEnd Defines the end margin between the message option list on the options overlay and the parent.
* @property showReactionsForUnsentMessages If we need to show the edit reactions bubble for unsent messages on the options overlay.
* @property readCountEnabled Enables/disables read count. Enabled by default.
* @property swipeToReplyEnabled Enables/disables swipe to reply feature. Enabled by default.
* @property swipeToReplyIcon Icon for swipe to reply feature. Default value is [R.drawable.stream_ui_ic_arrow_curve_left_grey].
*/
public data class MessageListViewStyle(
public val scrollButtonViewStyle: ScrollButtonViewStyle,
Expand Down Expand Up @@ -164,7 +166,8 @@ public data class MessageListViewStyle(
public val optionsOverlayMessageOptionsMarginEnd: Int,
public val showReactionsForUnsentMessages: Boolean,
public val readCountEnabled: Boolean,
public val swipeToReplyIcon: Drawable?,
public val swipeToReplyEnabled: Boolean,
@DrawableRes public val swipeToReplyIcon: Int,
) : ViewStyle {
public companion object {
private val DEFAULT_BACKGROUND_COLOR = R.color.stream_ui_white_snow
Expand Down Expand Up @@ -341,11 +344,9 @@ public data class MessageListViewStyle(
R.drawable.stream_ui_ic_arrow_curve_left_grey,
)

val replyToSwipeIcon: Drawable? = context.getDrawableCompat(
attributes.getResourceId(
R.styleable.MessageListView_streamUiSwipeToReplyIcon,
R.drawable.stream_ui_ic_arrow_curve_left_grey,
),
val replyToSwipeIcon: Int = attributes.getResourceId(
R.styleable.MessageListView_streamUiSwipeToReplyIcon,
R.drawable.stream_ui_ic_arrow_curve_left_grey,
)

val replyEnabled = attributes.getBoolean(R.styleable.MessageListView_streamUiReplyEnabled, true)
Expand Down Expand Up @@ -603,6 +604,11 @@ public data class MessageListViewStyle(
true,
)

val swipeToReplyEnabled = attributes.getBoolean(
R.styleable.MessageListView_streamUiSwipeToReply,
true,
)

val userBlockEnabled = attributes.getBoolean(
R.styleable.MessageListView_streamUiBlockUserOptionEnabled,
true,
Expand Down Expand Up @@ -682,6 +688,7 @@ public data class MessageListViewStyle(
optionsOverlayMessageOptionsMarginEnd = optionsOverlayMessageOptionsMarginEnd,
showReactionsForUnsentMessages = showReactionsForUnsentMessages,
readCountEnabled = readCountEnabled,
swipeToReplyEnabled = swipeToReplyEnabled,
swipeToReplyIcon = replyToSwipeIcon,
).let(TransformStyle.messageListStyleTransformer::transform)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@
<attr name="streamUiShowReactionsForUnsentMessages" format="boolean" />
<!-- Shows a counter next to the read status of a message. -->
<attr name="streamUiReadCount" format="boolean" />
<attr name="streamUiSwipeToReply" format="boolean" />

<!-- Audio record player view style -->
<attr name="streamUiMessageListAudioRecordPlayerViewStyleOwn" format="reference" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public fun randomMessageListViewStyle(
optionsOverlayMessageOptionsMarginEnd: Int = randomInt(),
showReactionsForUnsentMessages: Boolean = randomBoolean(),
readCountEnabled: Boolean = randomBoolean(),
swipeToReplyIcon: Drawable? = null,
swipeToReplyEnabled: Boolean = randomBoolean(),
swipeToReplyIcon: Int = randomInt(),
): MessageListViewStyle = MessageListViewStyle(
scrollButtonViewStyle = scrollButtonViewStyle,
scrollButtonBehaviour = scrollButtonBehaviour,
Expand Down Expand Up @@ -190,6 +191,7 @@ public fun randomMessageListViewStyle(
optionsOverlayMessageOptionsMarginEnd = optionsOverlayMessageOptionsMarginEnd,
showReactionsForUnsentMessages = showReactionsForUnsentMessages,
readCountEnabled = readCountEnabled,
swipeToReplyEnabled = swipeToReplyEnabled,
swipeToReplyIcon = swipeToReplyIcon,
)

Expand Down

0 comments on commit 341a64b

Please sign in to comment.