mirror of
https://github.com/element-hq/element-android
synced 2024-11-23 18:05:36 +03:00
Increment reaction when reaction pill clicked in timeline
This commit is contained in:
parent
ef26519993
commit
f9142fedfd
4 changed files with 43 additions and 1 deletions
|
@ -483,6 +483,16 @@ class RoomDetailFragment :
|
|||
override fun onMemberNameClicked(informationData: MessageInformationData) {
|
||||
insertUserDisplayNameInTextEditor(informationData.memberName?.toString())
|
||||
}
|
||||
|
||||
override fun onClickOnReactionPill(informationData: MessageInformationData, reaction: String, on: Boolean) {
|
||||
if (on) {
|
||||
//we should test the current real state of reaction on this event
|
||||
roomDetailViewModel.process(RoomDetailActions.SendReaction(reaction,informationData.eventId))
|
||||
} else {
|
||||
//TODO it's an undo :/
|
||||
}
|
||||
}
|
||||
|
||||
// AutocompleteUserPresenter.Callback
|
||||
|
||||
override fun onQueryUsers(query: CharSequence?) {
|
||||
|
@ -566,6 +576,7 @@ class RoomDetailFragment :
|
|||
* @param text the text to insert.
|
||||
*/
|
||||
private fun insertUserDisplayNameInTextEditor(text: String?) {
|
||||
//TODO move logic outside of fragment
|
||||
if (null != text) {
|
||||
// var vibrate = false
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class TimelineEventController(private val dateFormatter: TimelineDateFormatter,
|
|||
private val backgroundHandler: Handler = TimelineAsyncHelper.getBackgroundHandler()
|
||||
) : EpoxyController(backgroundHandler, backgroundHandler), Timeline.Listener {
|
||||
|
||||
interface Callback {
|
||||
interface Callback : ReactionPillCallback {
|
||||
fun onEventVisible(event: TimelineEvent)
|
||||
fun onUrlClicked(url: String)
|
||||
fun onImageMessageClicked(messageImageContent: MessageImageContent, mediaData: ImageContentRenderer.Data, view: View)
|
||||
|
@ -60,6 +60,10 @@ class TimelineEventController(private val dateFormatter: TimelineDateFormatter,
|
|||
fun onMemberNameClicked(informationData: MessageInformationData)
|
||||
}
|
||||
|
||||
interface ReactionPillCallback {
|
||||
fun onClickOnReactionPill(informationData: MessageInformationData, reaction: String, on: Boolean)
|
||||
}
|
||||
|
||||
private val collapsedEventIds = linkedSetOf<String>()
|
||||
private val mergeItemCollapseStates = HashMap<String, Boolean>()
|
||||
private val modelCache = arrayListOf<CacheItemData?>()
|
||||
|
|
|
@ -107,6 +107,7 @@ class MessageItemFactory(private val colorProvider: ColorProvider,
|
|||
.informationData(informationData)
|
||||
.filename(messageContent.body)
|
||||
.iconRes(R.drawable.filetype_audio)
|
||||
.reactionPillCallback(callback)
|
||||
.avatarClickListener(
|
||||
DebouncedClickListener(View.OnClickListener { view ->
|
||||
callback?.onAvatarClicked(informationData)
|
||||
|
@ -134,6 +135,7 @@ class MessageItemFactory(private val colorProvider: ColorProvider,
|
|||
return MessageFileItem_()
|
||||
.informationData(informationData)
|
||||
.filename(messageContent.body)
|
||||
.reactionPillCallback(callback)
|
||||
.iconRes(R.drawable.filetype_attachment)
|
||||
.avatarClickListener(
|
||||
DebouncedClickListener(View.OnClickListener { view ->
|
||||
|
@ -180,6 +182,7 @@ class MessageItemFactory(private val colorProvider: ColorProvider,
|
|||
.playable(messageContent.info?.mimeType == "image/gif")
|
||||
.informationData(informationData)
|
||||
.mediaData(data)
|
||||
.reactionPillCallback(callback)
|
||||
.avatarClickListener(
|
||||
DebouncedClickListener(View.OnClickListener { view ->
|
||||
callback?.onAvatarClicked(informationData)
|
||||
|
@ -226,6 +229,7 @@ class MessageItemFactory(private val colorProvider: ColorProvider,
|
|||
.playable(true)
|
||||
.informationData(informationData)
|
||||
.mediaData(thumbnailData)
|
||||
.reactionPillCallback(callback)
|
||||
.avatarClickListener(
|
||||
DebouncedClickListener(View.OnClickListener { view ->
|
||||
callback?.onAvatarClicked(informationData)
|
||||
|
@ -257,6 +261,7 @@ class MessageItemFactory(private val colorProvider: ColorProvider,
|
|||
return MessageTextItem_()
|
||||
.message(linkifiedBody)
|
||||
.informationData(informationData)
|
||||
.reactionPillCallback(callback)
|
||||
.avatarClickListener(
|
||||
DebouncedClickListener(View.OnClickListener { view ->
|
||||
callback?.onAvatarClicked(informationData)
|
||||
|
@ -294,6 +299,7 @@ class MessageItemFactory(private val colorProvider: ColorProvider,
|
|||
return MessageTextItem_()
|
||||
.message(message)
|
||||
.informationData(informationData)
|
||||
.reactionPillCallback(callback)
|
||||
.avatarClickListener(
|
||||
DebouncedClickListener(View.OnClickListener { view ->
|
||||
callback?.onAvatarClicked(informationData)
|
||||
|
@ -322,6 +328,7 @@ class MessageItemFactory(private val colorProvider: ColorProvider,
|
|||
return MessageTextItem_()
|
||||
.message(message)
|
||||
.informationData(informationData)
|
||||
.reactionPillCallback(callback)
|
||||
.avatarClickListener(
|
||||
DebouncedClickListener(View.OnClickListener { view ->
|
||||
callback?.onAvatarClicked(informationData)
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.airbnb.epoxy.EpoxyAttribute
|
|||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.utils.DimensionUtils.dpToPx
|
||||
import im.vector.riotredesign.features.home.AvatarRenderer
|
||||
import im.vector.riotredesign.features.home.room.detail.timeline.TimelineEventController
|
||||
import im.vector.riotredesign.features.reactions.widget.ReactionButton
|
||||
|
||||
|
||||
|
@ -49,6 +50,19 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : BaseEventItem<H>() {
|
|||
@EpoxyAttribute
|
||||
var memberClickListener: View.OnClickListener? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var reactionPillCallback: TimelineEventController.ReactionPillCallback? = null
|
||||
|
||||
var reactionClickListener: ReactionButton.ReactedListener = object : ReactionButton.ReactedListener {
|
||||
override fun onReacted(reactionButton: ReactionButton) {
|
||||
reactionPillCallback?.onClickOnReactionPill(informationData, reactionButton.reactionString,true)
|
||||
}
|
||||
|
||||
override fun onUnReacted(reactionButton: ReactionButton) {
|
||||
reactionPillCallback?.onClickOnReactionPill(informationData, reactionButton.reactionString,false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun bind(holder: H) {
|
||||
super.bind(holder)
|
||||
if (informationData.showInformation) {
|
||||
|
@ -91,6 +105,8 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : BaseEventItem<H>() {
|
|||
informationData.orderedReactionList?.chunked(7)?.firstOrNull()?.forEachIndexed { index, reaction ->
|
||||
(holder.reactionWrapper?.children?.elementAtOrNull(index) as? ReactionButton)?.let { reactionButton ->
|
||||
reactionButton.isVisible = true
|
||||
reactionButton.reactedListener = reactionClickListener
|
||||
reactionButton.setTag(R.id.messageBottomInfo, reaction.first)
|
||||
idToRefInFlow.add(reactionButton.id)
|
||||
reactionButton.reactionString = reaction.first
|
||||
reactionButton.reactionCount = reaction.second
|
||||
|
@ -107,6 +123,10 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : BaseEventItem<H>() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun unbind(holder: H) {
|
||||
super.unbind(holder)
|
||||
}
|
||||
|
||||
protected fun View.renderSendState() {
|
||||
isClickable = informationData.sendState.isSent()
|
||||
alpha = if (informationData.sendState.isSent()) 1f else 0.5f
|
||||
|
|
Loading…
Reference in a new issue