Skip to content

Commit

Permalink
Fix checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
JcMinarro committed Feb 10, 2025
1 parent 65f57cd commit 3e07673
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,4 @@ public fun randomChannelCapabilities(
.minus(exclude)
.shuffled()
.let { it.take(positiveRandomInt(it.size)) }
.toSet() + include
.toSet() + include
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;IIIIIIZIIIIIIIIIIIIZZ)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;IIIIIIZIIIIIIIIIIIIZZLandroid/graphics/drawable/Drawable;)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,11 +2601,12 @@ 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 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;IIIIIIZIIIIIIIIIIIIZZ)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;IIIIIIZIIIIIIIIIIIIZZIILjava/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;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 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 @@ -2659,6 +2660,7 @@ 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 getThreadMessagesStart ()I
public final fun getThreadReplyIcon ()I
public final fun getThreadsEnabled ()Z
Expand Down Expand Up @@ -2795,7 +2797,6 @@ 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;
protected 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 @@ -738,7 +738,7 @@ public class MessageListView : ConstraintLayout {
?.let { messageListViewStyle?.canReplyToMessage(it, ownCapabilities) }
?: false
}.let { swipeReplyCallback ->
ItemTouchHelper(swipeReplyCallback).let{ itemTouchHelper ->
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,9 @@ public data class MessageListViewStyle(
attributes.getResourceId(
R.styleable.MessageListView_streamUiSwipeToReplyIcon,
R.drawable.stream_ui_ic_arrow_curve_left_grey,
)
),
)


val replyEnabled = attributes.getBoolean(R.styleable.MessageListView_streamUiReplyEnabled, true)

val threadReplyIcon = attributes.getResourceId(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:Suppress("TooManyFunctions")

package io.getstream.chat.android.ui.feature.messages.list.internal

import io.getstream.chat.android.client.utils.attachment.isGiphy
Expand Down Expand Up @@ -75,4 +93,4 @@ internal fun MessageListViewStyle.canMarkAsUnread(
internal fun MessageListViewStyle.canRetryMessage(
currentUser: User?,
message: Message,
): Boolean = retryMessageEnabled && message.isOwnMessage(currentUser) && message.isMessageFailed()
): Boolean = retryMessageEnabled && message.isOwnMessage(currentUser) && message.isMessageFailed()
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.getstream.chat.android.ui.feature.messages.list.internal

import android.graphics.Canvas
Expand All @@ -13,60 +29,72 @@ import io.getstream.chat.android.ui.feature.messages.list.adapter.BaseMessageIte
import io.getstream.chat.android.ui.feature.messages.list.adapter.MessageListItem

internal class SwipeReplyCallback(
val replyDrawable: Drawable,
val canReply: (Message?) -> Boolean,
) : ItemTouchHelper.Callback() {
val replyDrawable: Drawable,
val canReply: (Message?) -> Boolean,
) : ItemTouchHelper.Callback() {

private val RecyclerView.ViewHolder.message: Message?
get() = asBaseMessageItemViewHolder()?.messageItem?.message
private val RecyclerView.ViewHolder.message: Message?
get() = asBaseMessageItemViewHolder()?.messageItem?.message

private val BaseMessageItemViewHolder<*>.messageItem: MessageListItem.MessageItem?
get() = data as? MessageListItem.MessageItem
private val BaseMessageItemViewHolder<*>.messageItem: MessageListItem.MessageItem?
get() = data as? MessageListItem.MessageItem

private fun RecyclerView.ViewHolder.asBaseMessageItemViewHolder(): BaseMessageItemViewHolder<*>? =
this as? BaseMessageItemViewHolder<*>
private fun RecyclerView.ViewHolder.asBaseMessageItemViewHolder(): BaseMessageItemViewHolder<*>? =
this as? BaseMessageItemViewHolder<*>

var onReply: (message: Message) -> Unit = {}
var onReply: (message: Message) -> Unit = {}

override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int =
when (canReply(viewHolder.message)) {
true -> makeMovementFlags(ACTION_STATE_IDLE, RIGHT)
false -> 0
}
override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int =
when (canReply(viewHolder.message)) {
true -> makeMovementFlags(ACTION_STATE_IDLE, RIGHT)
false -> 0
}

override fun onMove(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
target: RecyclerView.ViewHolder,
): Boolean = false
override fun onMove(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
target: RecyclerView.ViewHolder,
): Boolean = false

override fun getSwipeThreshold(viewHolder: RecyclerView.ViewHolder): Float = 0.3f
override fun getSwipeThreshold(viewHolder: RecyclerView.ViewHolder): Float = 0.3f

override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
viewHolder.message?.let { onReply(it) }
}
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
viewHolder.message?.let { onReply(it) }
}

override fun onChildDraw(
c: Canvas,
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
dX: Float,
dY: Float,
actionState: Int,
isCurrentlyActive: Boolean
) {
val rightAlignment = minOf(dX.toInt(), replyDrawable.intrinsicWidth*3)
val topAlignment = viewHolder.itemView.middleVerticalPoint - replyDrawable.intrinsicHeight/2
replyDrawable.bounds = Rect(
rightAlignment - replyDrawable.intrinsicWidth,
topAlignment,
rightAlignment,
topAlignment + replyDrawable.intrinsicHeight,
)
super.onChildDraw(c, recyclerView, viewHolder, minOf(dX, (recyclerView.width/2).toFloat()), dY, actionState, isCurrentlyActive)
replyDrawable.draw(c)
}
override fun onChildDraw(
canvas: Canvas,
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
dX: Float,
dY: Float,
actionState: Int,
isCurrentlyActive: Boolean,
) {
val rightAlignment = minOf(dX.toInt(), replyDrawable.intrinsicWidth * REPLY_DRAWABLE_SIZE_MULTIPLIER)
val topAlignment = viewHolder.itemView.middleVerticalPoint - replyDrawable.intrinsicHeight / 2
replyDrawable.bounds = Rect(
rightAlignment - replyDrawable.intrinsicWidth,
topAlignment,
rightAlignment,
topAlignment + replyDrawable.intrinsicHeight,
)
super.onChildDraw(
canvas,
recyclerView,
viewHolder,
minOf(dX, (recyclerView.width / 2).toFloat()),
dY,
actionState,
isCurrentlyActive,
)
replyDrawable.draw(canvas)
}

private val View.middleVerticalPoint: Int
get() = (top + bottom) / 2

private val View.middleVerticalPoint: Int
get() = (top + bottom) / 2
}
companion object {
private const val REPLY_DRAWABLE_SIZE_MULTIPLIER = 3
}
}
Loading

0 comments on commit 3e07673

Please sign in to comment.