Use ClickListener and onClick extension wherever it's possible on Epoxy items - step 2

This commit is contained in:
Benoit Marty 2021-05-31 15:32:38 +02:00
parent 90634a9f9c
commit dddca8ce59
47 changed files with 244 additions and 276 deletions

View file

@ -30,13 +30,13 @@ abstract class ErrorWithRetryItem : VectorEpoxyModel<ErrorWithRetryItem.Holder>(
var text: String? = null
@EpoxyAttribute
var listener: (() -> Unit)? = null
var listener: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.textView.text = text
holder.buttonView.isVisible = listener != null
holder.buttonView.setOnClickListener { listener?.invoke() }
holder.buttonView.onClick(listener)
}
class Holder : VectorEpoxyHolder() {

View file

@ -23,8 +23,10 @@ import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.detail.timeline.tools.findPillsAndProcess
@ -62,13 +64,13 @@ abstract class BottomSheetMessagePreviewItem : VectorEpoxyModel<BottomSheetMessa
var movementMethod: MovementMethod? = null
@EpoxyAttribute
var userClicked: (() -> Unit)? = null
var userClicked: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
avatarRenderer.render(matrixItem, holder.avatar)
holder.avatar.setOnClickListener { userClicked?.invoke() }
holder.sender.setOnClickListener { userClicked?.invoke() }
holder.avatar.onClick(userClicked)
holder.sender.onClick(userClicked)
holder.sender.setTextOrHide(matrixItem.displayName)
data?.let {
imageContentRenderer?.render(it, ImageContentRenderer.Mode.THUMBNAIL, holder.imagePreview)

View file

@ -24,6 +24,7 @@ import im.vector.app.EmojiCompatFontProvider
import im.vector.app.R
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
/**
* A quick reaction list for bottom sheet.
@ -50,7 +51,7 @@ abstract class BottomSheetQuickReactionsItem : VectorEpoxyModel<BottomSheetQuick
textView.text = texts[index]
textView.alpha = if (selecteds[index]) 0.2f else 1f
textView.setOnClickListener {
textView.onClick {
listener?.didSelect(texts[index], !selecteds[index])
}
}

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2021 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 im.vector.app.core.ui.list
import im.vector.app.core.epoxy.ClickListener
data class Action(
val title: String,
val listener: ClickListener
)

View file

@ -29,6 +29,7 @@ import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setTextOrHide
/**
@ -37,10 +38,6 @@ import im.vector.app.core.extensions.setTextOrHide
@EpoxyModelClass(layout = R.layout.item_generic_empty_state)
abstract class GenericEmptyWithActionItem : VectorEpoxyModel<GenericEmptyWithActionItem.Holder>() {
class Action(var title: String) {
var perform: Runnable? = null
}
@EpoxyAttribute
var title: CharSequence? = null
@ -77,9 +74,7 @@ abstract class GenericEmptyWithActionItem : VectorEpoxyModel<GenericEmptyWithAct
}
holder.actionButton.setTextOrHide(buttonAction?.title)
holder.actionButton.setOnClickListener {
buttonAction?.perform?.run()
}
holder.actionButton.onClick(buttonAction?.listener)
}
class Holder : VectorEpoxyHolder() {

View file

@ -21,8 +21,10 @@ import androidx.annotation.ColorInt
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.features.themes.ThemeUtils
@ -42,7 +44,7 @@ abstract class GenericFooterItem : VectorEpoxyModel<GenericFooterItem.Holder>()
var style: ItemStyle = ItemStyle.NORMAL_TEXT
@EpoxyAttribute
var itemClickAction: GenericItem.Action? = null
var itemClickAction: ClickListener? = null
@EpoxyAttribute
var centered: Boolean = true
@ -65,9 +67,7 @@ abstract class GenericFooterItem : VectorEpoxyModel<GenericFooterItem.Holder>()
holder.text.setTextColor(ThemeUtils.getColor(holder.view.context, R.attr.riotx_text_secondary))
}
holder.view.setOnClickListener {
itemClickAction?.perform?.run()
}
holder.view.onClick(itemClickAction)
}
class Holder : VectorEpoxyHolder() {

View file

@ -25,8 +25,10 @@ import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setTextOrHide
/**
@ -38,10 +40,6 @@ import im.vector.app.core.extensions.setTextOrHide
@EpoxyModelClass(layout = R.layout.item_generic_list)
abstract class GenericItem : VectorEpoxyModel<GenericItem.Holder>() {
class Action(var title: String) {
var perform: Runnable? = null
}
@EpoxyAttribute
var title: CharSequence? = null
@ -69,7 +67,7 @@ abstract class GenericItem : VectorEpoxyModel<GenericItem.Holder>() {
var destructiveButtonAction: Action? = null
@EpoxyAttribute
var itemClickAction: Action? = null
var itemClickAction: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
@ -100,18 +98,12 @@ abstract class GenericItem : VectorEpoxyModel<GenericItem.Holder>() {
}
holder.actionButton.setTextOrHide(buttonAction?.title)
holder.actionButton.setOnClickListener {
buttonAction?.perform?.run()
}
holder.actionButton.onClick(buttonAction?.listener)
holder.destructiveButton.setTextOrHide(destructiveButtonAction?.title)
holder.destructiveButton.setOnClickListener {
destructiveButtonAction?.perform?.run()
}
holder.destructiveButton.onClick(destructiveButtonAction?.listener)
holder.root.setOnClickListener {
itemClickAction?.perform?.run()
}
holder.root.onClick(itemClickAction)
}
class Holder : VectorEpoxyHolder() {

View file

@ -24,10 +24,11 @@ import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.core.utils.DebouncedClickListener
import im.vector.app.features.themes.ThemeUtils
/**
@ -36,6 +37,7 @@ import im.vector.app.features.themes.ThemeUtils
* Can display an accessory on the right, that can be an image or an indeterminate progress.
* If provided with an action, will display a button at the bottom of the list item.
*/
// TODO This class is not following the name convention. Should end with `Item
@EpoxyModelClass(layout = R.layout.item_generic_with_value)
abstract class GenericItemWithValue : VectorEpoxyModel<GenericItemWithValue.Holder>() {
@ -54,7 +56,7 @@ abstract class GenericItemWithValue : VectorEpoxyModel<GenericItemWithValue.Hold
var titleIconResourceId: Int = -1
@EpoxyAttribute
var itemClickAction: View.OnClickListener? = null
var itemClickAction: ClickListener? = null
@EpoxyAttribute
var itemLongClickAction: View.OnLongClickListener? = null
@ -78,7 +80,7 @@ abstract class GenericItemWithValue : VectorEpoxyModel<GenericItemWithValue.Hold
holder.valueText.setTextColor(ThemeUtils.getColor(holder.view.context, R.attr.riotx_text_primary))
}
holder.view.setOnClickListener(itemClickAction?.let { DebouncedClickListener(it) })
holder.view.onClick(itemClickAction)
holder.view.setOnLongClickListener(itemLongClickAction)
}

View file

@ -25,8 +25,10 @@ import androidx.core.widget.ImageViewCompat
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.features.themes.ThemeUtils
@ -43,7 +45,7 @@ abstract class GenericPillItem : VectorEpoxyModel<GenericPillItem.Holder>() {
var style: ItemStyle = ItemStyle.NORMAL_TEXT
@EpoxyAttribute
var itemClickAction: GenericItem.Action? = null
var itemClickAction: ClickListener? = null
@EpoxyAttribute
var centered: Boolean = false
@ -76,9 +78,7 @@ abstract class GenericPillItem : VectorEpoxyModel<GenericPillItem.Holder>() {
ImageViewCompat.setImageTintList(holder.imageView, null)
}
holder.view.setOnClickListener {
itemClickAction?.perform?.run()
}
holder.view.onClick(itemClickAction)
}
class Holder : VectorEpoxyHolder() {

View file

@ -18,10 +18,10 @@ package im.vector.app.core.ui.views
import androidx.cardview.widget.CardView
import androidx.core.view.isVisible
import im.vector.app.core.utils.DebouncedClickListener
import org.matrix.android.sdk.api.session.call.CallState
import im.vector.app.core.epoxy.onClick
import im.vector.app.features.call.utils.EglUtils
import im.vector.app.features.call.webrtc.WebRtcCall
import org.matrix.android.sdk.api.session.call.CallState
import org.webrtc.RendererCommon
import org.webrtc.SurfaceViewRenderer
@ -88,11 +88,9 @@ class KnownCallsViewHolder {
this.currentCallsView = activeCallView
this.pipWrapper = pipWrapper
this.currentCallsView?.callback = interactionListener
pipWrapper.setOnClickListener(
DebouncedClickListener({
interactionListener.onTapToReturnToCall()
})
)
pipWrapper.onClick {
interactionListener.onTapToReturnToCall()
}
this.currentCall?.addListener(tickListener)
}

View file

@ -21,7 +21,6 @@ import androidx.recyclerview.widget.RecyclerView
import com.airbnb.epoxy.TypedEpoxyController
import im.vector.app.EmojiCompatFontProvider
import im.vector.app.features.autocomplete.AutocompleteClickListener
import im.vector.app.features.reactions.ReactionClickListener
import im.vector.app.features.reactions.data.EmojiItem
import javax.inject.Inject
@ -51,13 +50,7 @@ class AutocompleteEmojiController @Inject constructor(
id(emojiItem.name)
emojiItem(emojiItem)
emojiTypeFace(host.emojiTypeface)
onClickListener(
object : ReactionClickListener {
override fun onReactionSelected(reaction: String) {
host.listener?.onItemClick(reaction)
}
}
)
onClickListener { host.listener?.onItemClick(emojiItem.emoji) }
}
}

View file

@ -21,10 +21,11 @@ import android.widget.TextView
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.features.reactions.ReactionClickListener
import im.vector.app.features.reactions.data.EmojiItem
@EpoxyModelClass(layout = R.layout.item_autocomplete_emoji)
@ -37,7 +38,7 @@ abstract class AutocompleteEmojiItem : VectorEpoxyModel<AutocompleteEmojiItem.Ho
var emojiTypeFace: Typeface? = null
@EpoxyAttribute
var onClickListener: ReactionClickListener? = null
var onClickListener: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
@ -45,10 +46,7 @@ abstract class AutocompleteEmojiItem : VectorEpoxyModel<AutocompleteEmojiItem.Ho
holder.emojiText.typeface = emojiTypeFace ?: Typeface.DEFAULT
holder.emojiNameText.text = emojiItem.name
holder.emojiKeywordText.setTextOrHide(emojiItem.keywords.joinToString())
holder.view.setOnClickListener {
onClickListener?.onReactionSelected(emojiItem.emoji)
}
holder.view.onClick(onClickListener)
}
class Holder : VectorEpoxyHolder() {

View file

@ -25,8 +25,10 @@ import androidx.core.widget.ImageViewCompat
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setTextOrHide
/**
@ -52,14 +54,11 @@ abstract class BottomSheetVerificationActionItem : VectorEpoxyModel<BottomSheetV
var iconColor: Int = -1
@EpoxyAttribute
lateinit var listener: () -> Unit
lateinit var listener: ClickListener
override fun bind(holder: Holder) {
super.bind(holder)
holder.view.setOnClickListener {
listener.invoke()
}
holder.view.onClick(listener)
holder.title.text = title
holder.title.setTextColor(titleColor)

View file

@ -21,7 +21,6 @@ import im.vector.app.R
import im.vector.app.core.epoxy.noResultItem
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.ui.list.GenericItem
import im.vector.app.core.ui.list.genericItem
import me.gujun.android.span.span
import org.json.JSONObject
@ -51,11 +50,9 @@ class RoomStateListController @Inject constructor(
id(entry.key)
title(entry.key)
description(host.stringProvider.getQuantityString(R.plurals.entries, entry.value.size, entry.value.size))
itemClickAction(GenericItem.Action("view").apply {
perform = Runnable {
host.interactionListener?.processAction(RoomDevToolAction.ShowStateEventType(entry.key))
}
})
itemClickAction {
host.interactionListener?.processAction(RoomDevToolAction.ShowStateEventType(entry.key))
}
}
}
}
@ -93,11 +90,9 @@ class RoomStateListController @Inject constructor(
}
})
description(contentJson)
itemClickAction(GenericItem.Action("view").apply {
perform = Runnable {
host.interactionListener?.processAction(RoomDevToolAction.ShowStateEvent(stateEvent))
}
})
itemClickAction {
host.interactionListener?.processAction(RoomDevToolAction.ShowStateEvent(stateEvent))
}
}
}
}

View file

@ -22,8 +22,10 @@ import androidx.core.graphics.drawable.DrawableCompat
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.features.themes.ThemeUtils
@EpoxyModelClass(layout = R.layout.item_form_advanced_toggle)
@ -31,7 +33,7 @@ abstract class FormAdvancedToggleItem : VectorEpoxyModel<FormAdvancedToggleItem.
@EpoxyAttribute lateinit var title: CharSequence
@EpoxyAttribute var expanded: Boolean = false
@EpoxyAttribute var listener: (() -> Unit)? = null
@EpoxyAttribute var listener: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
@ -42,7 +44,7 @@ abstract class FormAdvancedToggleItem : VectorEpoxyModel<FormAdvancedToggleItem.
}
holder.titleView.setCompoundDrawablesWithIntrinsicBounds(null, null, expandedArrowDrawable, null)
holder.titleView.text = title
holder.view.setOnClickListener { listener?.invoke() }
holder.view.onClick(listener)
}
class Holder : VectorEpoxyHolder() {

View file

@ -17,15 +17,16 @@
package im.vector.app.features.form
import android.text.Editable
import android.view.View
import androidx.appcompat.widget.AppCompatButton
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.epoxy.setValueOnce
import im.vector.app.core.platform.SimpleTextWatcher
@ -48,7 +49,7 @@ abstract class FormEditTextWithButtonItem : VectorEpoxyModel<FormEditTextWithBut
var onTextChange: ((String) -> Unit)? = null
@EpoxyAttribute
var onButtonClicked: ((View) -> Unit)? = null
var onButtonClicked: ClickListener? = null
private val onTextChangeListener = object : SimpleTextWatcher() {
override fun afterTextChanged(s: Editable) {
@ -68,8 +69,7 @@ abstract class FormEditTextWithButtonItem : VectorEpoxyModel<FormEditTextWithBut
holder.textInputEditText.addTextChangedListener(onTextChangeListener)
holder.textInputButton.text = buttonText
holder.textInputButton.setOnClickListener(onButtonClicked)
holder.textInputButton.onClick(onButtonClicked)
}
override fun shouldSaveViewState(): Boolean {

View file

@ -22,8 +22,10 @@ import android.widget.TextView
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.platform.CheckableConstraintLayout
import im.vector.app.features.home.AvatarRenderer
import org.matrix.android.sdk.api.util.MatrixItem
@ -34,11 +36,11 @@ abstract class GroupSummaryItem : VectorEpoxyModel<GroupSummaryItem.Holder>() {
@EpoxyAttribute lateinit var avatarRenderer: AvatarRenderer
@EpoxyAttribute lateinit var matrixItem: MatrixItem
@EpoxyAttribute var selected: Boolean = false
@EpoxyAttribute var listener: (() -> Unit)? = null
@EpoxyAttribute var listener: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.rootView.setOnClickListener { listener?.invoke() }
holder.rootView.onClick(listener)
holder.groupNameView.text = matrixItem.displayName
holder.rootView.isChecked = selected
avatarRenderer.render(matrixItem, holder.avatarImageView)

View file

@ -26,8 +26,10 @@ import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.platform.CheckableConstraintLayout
import im.vector.app.features.home.room.list.UnreadCounterBadgeView
import im.vector.app.features.themes.ThemeUtils
@ -36,7 +38,7 @@ import im.vector.app.features.themes.ThemeUtils
abstract class HomeSpaceSummaryItem : VectorEpoxyModel<HomeSpaceSummaryItem.Holder>() {
@EpoxyAttribute var selected: Boolean = false
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: (() -> Unit)? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: ClickListener? = null
@EpoxyAttribute var countState : UnreadCounterBadgeView.State = UnreadCounterBadgeView.State(0, false)
@EpoxyAttribute var showSeparator: Boolean = false
@ -47,7 +49,7 @@ abstract class HomeSpaceSummaryItem : VectorEpoxyModel<HomeSpaceSummaryItem.Hold
override fun bind(holder: Holder) {
super.bind(holder)
holder.rootView.setOnClickListener { listener?.invoke() }
holder.rootView.onClick(listener)
holder.groupNameView.text = holder.view.context.getString(R.string.group_details_home)
holder.rootView.isChecked = selected
holder.rootView.context.resources

View file

@ -54,11 +54,6 @@ abstract class BreadcrumbsItem : VectorEpoxyModel<BreadcrumbsItem.Holder>() {
holder.typingIndicator.isVisible = hasTypingUsers
}
override fun unbind(holder: Holder) {
holder.rootView.setOnClickListener(null)
super.unbind(holder)
}
class Holder : VectorEpoxyHolder() {
val unreadCounterBadgeView by bind<UnreadCounterBadgeView>(R.id.breadcrumbsUnreadCounterBadgeView)
val unreadIndentIndicator by bind<View>(R.id.breadcrumbsUnreadIndicator)

View file

@ -23,7 +23,9 @@ import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import com.airbnb.epoxy.EpoxyModelWithHolder
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.onClick
import im.vector.app.features.home.AvatarRenderer
import org.matrix.android.sdk.api.util.MatrixItem
@ -33,7 +35,7 @@ abstract class DisplayReadReceiptItem : EpoxyModelWithHolder<DisplayReadReceiptI
@EpoxyAttribute lateinit var matrixItem: MatrixItem
@EpoxyAttribute var timestamp: CharSequence? = null
@EpoxyAttribute lateinit var avatarRenderer: AvatarRenderer
@EpoxyAttribute var userClicked: (() -> Unit)? = null
@EpoxyAttribute var userClicked: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
@ -45,7 +47,7 @@ abstract class DisplayReadReceiptItem : EpoxyModelWithHolder<DisplayReadReceiptI
} ?: run {
holder.timestampView.isVisible = false
}
holder.view.setOnClickListener { userClicked?.invoke() }
holder.view.onClick(userClicked)
}
class Holder : VectorEpoxyHolder() {

View file

@ -36,15 +36,15 @@ class DisplayReadReceiptsController @Inject constructor(private val dateFormatte
var listener: Listener? = null
override fun buildModels(readReceipts: List<ReadReceiptData>) {
readReceipts.forEach {
val timestamp = dateFormatter.format(it.timestamp, DateFormatKind.DEFAULT_DATE_AND_TIME)
readReceipts.forEach { readReceiptData ->
val timestamp = dateFormatter.format(readReceiptData.timestamp, DateFormatKind.DEFAULT_DATE_AND_TIME)
DisplayReadReceiptItem_()
.id(it.userId)
.matrixItem(it.toMatrixItem())
.id(readReceiptData.userId)
.matrixItem(readReceiptData.toMatrixItem())
.avatarRenderer(avatarRender)
.timestamp(timestamp)
.userClicked { listener?.didSelectUser(it.userId) }
.addIf(session.myUserId != it.userId, this)
.userClicked { listener?.didSelectUser(readReceiptData.userId) }
.addIf(session.myUserId != readReceiptData.userId, this)
}
}

View file

@ -27,8 +27,8 @@ import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.ui.views.SendStateImageView
import im.vector.app.core.utils.DebouncedClickListener
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.detail.timeline.MessageColorProvider
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
@ -45,12 +45,17 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
@EpoxyAttribute
lateinit var attributes: Attributes
private val _avatarClickListener = DebouncedClickListener({
attributes.avatarCallback?.onAvatarClicked(attributes.informationData)
})
private val _memberNameClickListener = DebouncedClickListener({
attributes.avatarCallback?.onMemberNameClicked(attributes.informationData)
})
private val _avatarClickListener = object : ClickListener {
override fun invoke(p1: View) {
attributes.avatarCallback?.onAvatarClicked(attributes.informationData)
}
}
private val _memberNameClickListener = object : ClickListener {
override fun invoke(p1: View) {
attributes.avatarCallback?.onMemberNameClicked(attributes.informationData)
}
}
override fun bind(holder: H) {
super.bind(holder)
@ -60,9 +65,9 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
width = attributes.avatarSize
}
holder.avatarImageView.visibility = View.VISIBLE
holder.avatarImageView.setOnClickListener(_avatarClickListener)
holder.avatarImageView.onClick(_avatarClickListener)
holder.memberNameView.visibility = View.VISIBLE
holder.memberNameView.setOnClickListener(_memberNameClickListener)
holder.memberNameView.onClick(_memberNameClickListener)
holder.timeView.visibility = View.VISIBLE
holder.timeView.text = attributes.informationData.time
holder.memberNameView.text = attributes.informationData.memberName

View file

@ -29,6 +29,7 @@ import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setLeftDrawable
import im.vector.app.core.extensions.setTextWithColoredPart
import im.vector.app.features.home.AvatarRenderer
@ -65,11 +66,11 @@ abstract class CallTileTimelineItem : AbsBaseMessageItem<CallTileTimelineItem.Ho
}
if (attributes.callStatus == CallStatus.INVITED && !attributes.informationData.sentByMe && attributes.isStillActive) {
holder.acceptRejectViewGroup.isVisible = true
holder.acceptView.setOnClickListener {
holder.acceptView.onClick {
attributes.callback?.onTimelineItemAction(RoomDetailAction.AcceptCall(callId = attributes.callId))
}
holder.rejectView.setLeftDrawable(R.drawable.ic_call_hangup, R.color.riotx_notice)
holder.rejectView.setOnClickListener {
holder.rejectView.onClick {
attributes.callback?.onTimelineItemAction(RoomDetailAction.EndCall)
}
holder.statusView.isVisible = false

View file

@ -31,8 +31,8 @@ import androidx.core.view.updateLayoutParams
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.core.utils.DebouncedClickListener
import im.vector.app.core.utils.tappableMatchingText
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.detail.RoomDetailAction
@ -172,28 +172,28 @@ abstract class MergedRoomCreationItem : BasedMergedItem<MergedRoomCreationItem.H
holder.roomAvatarImageView.isVisible = roomItem != null
if (roomItem != null) {
attributes.avatarRenderer.render(roomItem, holder.roomAvatarImageView)
holder.roomAvatarImageView.setOnClickListener(DebouncedClickListener({ view ->
holder.roomAvatarImageView.onClick { view ->
if (shouldSetAvatar) {
attributes.callback?.onTimelineItemAction(RoomDetailAction.QuickActionSetAvatar)
} else {
// Note: this is no op if there is no avatar on the room
attributes.callback?.onTimelineItemAction(RoomDetailAction.ShowRoomAvatarFullScreen(roomItem, view))
}
}))
}
}
holder.setAvatarButton.isVisible = shouldSetAvatar
if (shouldSetAvatar) {
holder.setAvatarButton.setOnClickListener(DebouncedClickListener({
holder.setAvatarButton.onClick {
attributes.callback?.onTimelineItemAction(RoomDetailAction.QuickActionSetAvatar)
}))
}
}
holder.addPeopleButton.isVisible = !isDirect
if (!isDirect) {
holder.addPeopleButton.setOnClickListener(DebouncedClickListener({
holder.addPeopleButton.onClick {
attributes.callback?.onTimelineItemAction(RoomDetailAction.QuickActionInvitePeople)
}))
}
}
}

View file

@ -23,6 +23,7 @@ import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import com.google.android.material.button.MaterialButton
import im.vector.app.R
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.features.home.room.detail.RoomDetailAction
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
@ -59,7 +60,7 @@ abstract class MessageOptionsItem : AbsMessageItem<MessageOptionsItem.Holder>()
as MaterialButton
holder.buttonContainer.addView(materialButton, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
materialButton.text = option.label
materialButton.setOnClickListener {
materialButton.onClick {
callback?.onTimelineItemAction(RoomDetailAction.ReplyToOptions(relatedEventId, index, option.value ?: "$index"))
}
}

View file

@ -24,8 +24,9 @@ import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.core.utils.DebouncedClickListener
import im.vector.app.features.home.room.detail.RoomDetailAction
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
import org.matrix.android.sdk.api.session.room.model.message.MessageOptionsContent
@ -143,14 +144,16 @@ abstract class MessagePollItem : AbsMessageItem<MessagePollItem.Holder>() {
override fun bindView(itemView: View) {
super.bindView(itemView)
val buttons = listOf(button1, button2, button3, button4, button5)
val clickListener = DebouncedClickListener({
val optionIndex = buttons.indexOf(it)
if (optionIndex != -1 && pollId != null) {
val compatValue = if (optionIndex < optionValues?.size ?: 0) optionValues?.get(optionIndex) else null
callback?.onTimelineItemAction(RoomDetailAction.ReplyToOptions(pollId!!, optionIndex, compatValue ?: "$optionIndex"))
val clickListener = object : ClickListener {
override fun invoke(p1: View) {
val optionIndex = buttons.indexOf(p1)
if (optionIndex != -1 && pollId != null) {
val compatValue = if (optionIndex < optionValues?.size ?: 0) optionValues?.get(optionIndex) else null
callback?.onTimelineItemAction(RoomDetailAction.ReplyToOptions(pollId!!, optionIndex, compatValue ?: "$optionIndex"))
}
}
})
buttons.forEach { it.setOnClickListener(clickListener) }
}
buttons.forEach { it.onClick(clickListener) }
}
}

View file

@ -22,7 +22,9 @@ import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import com.airbnb.epoxy.EpoxyModelWithHolder
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.onClick
/**
* Item displaying an emoji reaction (single line with emoji, author, time)
@ -40,7 +42,7 @@ abstract class ReactionInfoSimpleItem : EpoxyModelWithHolder<ReactionInfoSimpleI
var timeStamp: CharSequence? = null
@EpoxyAttribute
var userClicked: (() -> Unit)? = null
var userClicked: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
@ -52,7 +54,7 @@ abstract class ReactionInfoSimpleItem : EpoxyModelWithHolder<ReactionInfoSimpleI
} ?: run {
holder.timeStampView.isVisible = false
}
holder.view.setOnClickListener { userClicked?.invoke() }
holder.view.onClick(userClicked)
}
class Holder : VectorEpoxyHolder() {

View file

@ -52,13 +52,13 @@ class ViewReactionsEpoxyController @Inject constructor(
}
}
is Success -> {
state.mapReactionKeyToMemberList()?.forEach {
state.mapReactionKeyToMemberList()?.forEach { reactionInfo ->
reactionInfoSimpleItem {
id(it.eventId)
timeStamp(it.timestamp)
reactionKey(host.emojiCompatWrapper.safeEmojiSpanify(it.reactionKey))
authorDisplayName(it.authorName ?: it.authorId)
userClicked { host.listener?.didSelectUser(it.authorId) }
id(reactionInfo.eventId)
timeStamp(reactionInfo.timestamp)
reactionKey(host.emojiCompatWrapper.safeEmojiSpanify(reactionInfo.reactionKey))
authorDisplayName(reactionInfo.authorName ?: reactionInfo.authorId)
userClicked { host.listener?.didSelectUser(reactionInfo.authorId) }
}
}
}

View file

@ -22,6 +22,7 @@ import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.features.home.room.list.widget.NotifsFabMenuView
@EpoxyModelClass(layout = R.layout.item_room_filter_footer)
@ -35,9 +36,9 @@ abstract class FilteredRoomFooterItem : VectorEpoxyModel<FilteredRoomFooterItem.
override fun bind(holder: Holder) {
super.bind(holder)
holder.createRoomButton.setOnClickListener { listener?.createRoom(currentFilter) }
holder.createDirectChat.setOnClickListener { listener?.createDirectChat() }
holder.openRoomDirectory.setOnClickListener { listener?.openRoomDirectory(currentFilter) }
holder.createRoomButton.onClick { listener?.createRoom(currentFilter) }
holder.createDirectChat.onClick { listener?.createDirectChat() }
holder.openRoomDirectory.onClick { listener?.openRoomDirectory(currentFilter) }
}
class Holder : VectorEpoxyHolder() {

View file

@ -22,12 +22,13 @@ import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.recyclerview.widget.RecyclerView
import im.vector.app.R
import im.vector.app.core.utils.DebouncedClickListener
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.onClick
import im.vector.app.databinding.ItemRoomCategoryBinding
import im.vector.app.features.themes.ThemeUtils
class SectionHeaderAdapter constructor(
private val onClickAction: (() -> Unit)
private val onClickAction: ClickListener
) : RecyclerView.Adapter<SectionHeaderAdapter.VH>() {
data class RoomsSectionData(
@ -59,7 +60,7 @@ class SectionHeaderAdapter constructor(
override fun getItemViewType(position: Int) = R.layout.item_room_category
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
return VH.create(parent, this.onClickAction)
return VH.create(parent, onClickAction)
}
override fun onBindViewHolder(holder: VH, position: Int) {
@ -70,13 +71,11 @@ class SectionHeaderAdapter constructor(
class VH constructor(
private val binding: ItemRoomCategoryBinding,
onClickAction: (() -> Unit)
onClickAction: ClickListener
) : RecyclerView.ViewHolder(binding.root) {
init {
binding.root.setOnClickListener(DebouncedClickListener({
onClickAction.invoke()
}))
binding.root.onClick(onClickAction)
}
fun bind(roomsSectionData: RoomsSectionData) {
@ -91,7 +90,7 @@ class SectionHeaderAdapter constructor(
}
companion object {
fun create(parent: ViewGroup, onClickAction: () -> Unit): VH {
fun create(parent: ViewGroup, onClickAction: ClickListener): VH {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_room_category, parent, false)
val binding = ItemRoomCategoryBinding.bind(view)

View file

@ -63,13 +63,13 @@ class EmojiSearchResultController @Inject constructor(
}
} else {
// Build the search results
results.forEach {
results.forEach { emojiItem ->
emojiSearchResultItem {
id(it.name)
emojiItem(it)
id(emojiItem.name)
emojiItem(emojiItem)
emojiTypeFace(host.emojiTypeface)
currentQuery(data.query)
onClickListener(host.listener)
onClickListener { host.listener?.onReactionSelected(emojiItem.emoji) }
}
}
}

View file

@ -21,7 +21,9 @@ import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import com.airbnb.epoxy.EpoxyModelWithHolder
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.features.reactions.data.EmojiItem
@ -35,7 +37,7 @@ abstract class EmojiSearchResultItem : EpoxyModelWithHolder<EmojiSearchResultIte
var currentQuery: String? = null
@EpoxyAttribute
var onClickListener: ReactionClickListener? = null
var onClickListener: ClickListener? = null
@EpoxyAttribute
var emojiTypeFace: Typeface? = null
@ -47,9 +49,7 @@ abstract class EmojiSearchResultItem : EpoxyModelWithHolder<EmojiSearchResultIte
holder.emojiText.typeface = emojiTypeFace ?: Typeface.DEFAULT
holder.emojiNameText.text = emojiItem.name
holder.emojiKeywordText.setTextOrHide(emojiItem.keywords.joinToString())
holder.view.setOnClickListener {
onClickListener?.onReactionSelected(emojiItem.emoji)
}
holder.view.onClick(onClickListener)
}
class Holder : VectorEpoxyHolder() {

View file

@ -16,7 +16,6 @@
*/
package im.vector.app.features.roommemberprofile.devices
import android.view.View
import com.airbnb.epoxy.TypedEpoxyController
import com.airbnb.mvrx.Fail
import com.airbnb.mvrx.Loading
@ -131,9 +130,9 @@ class DeviceListEpoxyController @Inject constructor(private val stringProvider:
if (device.isVerified) R.color.riotx_positive_accent else R.color.riotx_destructive_accent
)
)
itemClickAction(View.OnClickListener {
itemClickAction {
host.interactionListener?.onDeviceSelected(device)
})
}
}
}
}

View file

@ -45,8 +45,8 @@ class DeviceTrustInfoEpoxyController @Inject constructor(private val stringProvi
override fun buildModels(data: DeviceListViewState?) {
val host = this
data?.selectedDevice?.let {
val isVerified = it.trustLevel?.isVerified() == true
data?.selectedDevice?.let { cryptoDeviceInfo ->
val isVerified = cryptoDeviceInfo.trustLevel?.isVerified() == true
genericItem {
id("title")
style(ItemStyle.BIG_TEXT)
@ -78,13 +78,13 @@ class DeviceTrustInfoEpoxyController @Inject constructor(private val stringProvi
}
genericItemWithValue {
id(it.deviceId)
id(cryptoDeviceInfo.deviceId)
titleIconResourceId(if (isVerified) R.drawable.ic_shield_trusted else R.drawable.ic_shield_warning)
title(
span {
+(it.displayName() ?: "")
+(cryptoDeviceInfo.displayName() ?: "")
span {
text = " (${it.deviceId})"
text = " (${cryptoDeviceInfo.deviceId})"
textColor = host.colorProvider.getColorFromAttribute(R.attr.riotx_text_secondary)
textSize = host.dimensionConverter.spToPx(14)
}
@ -107,7 +107,7 @@ class DeviceTrustInfoEpoxyController @Inject constructor(private val stringProvi
iconRes(R.drawable.ic_arrow_right)
iconColor(host.colorProvider.getColor(R.color.riotx_accent))
listener {
host.interactionListener?.onVerifyManually(it)
host.interactionListener?.onVerifyManually(cryptoDeviceInfo)
}
}
}

View file

@ -16,15 +16,15 @@
package im.vector.app.features.roomprofile.uploads.media
import android.view.View
import android.widget.ImageView
import androidx.core.view.ViewCompat
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.utils.DebouncedClickListener
import im.vector.app.core.epoxy.onClick
import im.vector.app.features.media.ImageContentRenderer
@EpoxyModelClass(layout = R.layout.item_uploads_image)
@ -33,15 +33,11 @@ abstract class UploadsImageItem : VectorEpoxyModel<UploadsImageItem.Holder>() {
@EpoxyAttribute lateinit var imageContentRenderer: ImageContentRenderer
@EpoxyAttribute lateinit var data: ImageContentRenderer.Data
@EpoxyAttribute var listener: Listener? = null
@EpoxyAttribute var listener: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.view.setOnClickListener(
DebouncedClickListener({
listener?.onItemClicked(holder.imageView, data)
})
)
holder.view.onClick(listener)
imageContentRenderer.render(data, holder.imageView, IMAGE_SIZE_DP)
ViewCompat.setTransitionName(holder.imageView, "imagePreview_${id()}")
}
@ -49,8 +45,4 @@ abstract class UploadsImageItem : VectorEpoxyModel<UploadsImageItem.Holder>() {
class Holder : VectorEpoxyHolder() {
val imageView by bind<ImageView>(R.id.uploadsImagePreview)
}
interface Listener {
fun onItemClicked(view: View, data: ImageContentRenderer.Data)
}
}

View file

@ -87,11 +87,9 @@ class UploadsMediaController @Inject constructor(
id(uploadEvent.eventId)
imageContentRenderer(host.imageContentRenderer)
data(data)
listener(object : UploadsImageItem.Listener {
override fun onItemClicked(view: View, data: ImageContentRenderer.Data) {
host.listener?.onOpenImageClicked(view, data)
}
})
listener {
host.listener?.onOpenImageClicked(it, data)
}
}
}
MessageType.MSGTYPE_VIDEO -> {
@ -100,11 +98,9 @@ class UploadsMediaController @Inject constructor(
id(uploadEvent.eventId)
imageContentRenderer(host.imageContentRenderer)
data(data)
listener(object : UploadsVideoItem.Listener {
override fun onItemClicked(view: View, data: VideoContentRenderer.Data) {
host.listener?.onOpenVideoClicked(view, data)
}
})
listener {
host.listener?.onOpenVideoClicked(it, data)
}
}
}
}

View file

@ -16,15 +16,15 @@
package im.vector.app.features.roomprofile.uploads.media
import android.view.View
import android.widget.ImageView
import androidx.core.view.ViewCompat
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.utils.DebouncedClickListener
import im.vector.app.core.epoxy.onClick
import im.vector.app.features.media.ImageContentRenderer
import im.vector.app.features.media.VideoContentRenderer
@ -34,15 +34,11 @@ abstract class UploadsVideoItem : VectorEpoxyModel<UploadsVideoItem.Holder>() {
@EpoxyAttribute lateinit var imageContentRenderer: ImageContentRenderer
@EpoxyAttribute lateinit var data: VideoContentRenderer.Data
@EpoxyAttribute var listener: Listener? = null
@EpoxyAttribute var listener: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.view.setOnClickListener(
DebouncedClickListener({
listener?.onItemClicked(holder.imageView, data)
})
)
holder.view.onClick(listener)
imageContentRenderer.render(data.thumbnailMediaData, holder.imageView, IMAGE_SIZE_DP)
ViewCompat.setTransitionName(holder.imageView, "videoPreview_${id()}")
}
@ -50,8 +46,4 @@ abstract class UploadsVideoItem : VectorEpoxyModel<UploadsVideoItem.Holder>() {
class Holder : VectorEpoxyHolder() {
val imageView by bind<ImageView>(R.id.uploadsVideoPreview)
}
interface Listener {
fun onItemClicked(view: View, data: VideoContentRenderer.Data)
}
}

View file

@ -26,7 +26,6 @@ import im.vector.app.core.epoxy.loadingItem
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.ui.list.genericFooterItem
import im.vector.app.core.ui.list.genericItemWithValue
import im.vector.app.core.utils.DebouncedClickListener
import org.matrix.android.sdk.api.session.accountdata.AccountDataEvent
import javax.inject.Inject
@ -69,9 +68,9 @@ class AccountDataEpoxyController @Inject constructor(
genericItemWithValue {
id(accountData.type)
title(accountData.type)
itemClickAction(DebouncedClickListener({
itemClickAction {
host.interactionListener?.didTap(accountData)
}))
}
itemLongClickAction(View.OnLongClickListener {
host.interactionListener?.didLongTap(accountData)
true

View file

@ -23,7 +23,6 @@ import im.vector.app.core.date.DateFormatKind
import im.vector.app.core.date.VectorDateFormatter
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.ui.list.GenericItem
import im.vector.app.core.ui.list.GenericItem_
import im.vector.app.core.utils.createUIHandler
import me.gujun.android.span.span
@ -58,7 +57,7 @@ class GossipingTrailPagedEpoxyController @Inject constructor(
val event = item ?: return GenericItem_().apply { id(currentPosition) }
return GenericItem_().apply {
id(event.hashCode())
itemClickAction(GenericItem.Action("view").apply { perform = Runnable { host.interactionListener?.didTap(event) } })
itemClickAction { host.interactionListener?.didTap(event) }
title(
if (event.isEncrypted()) {
"${event.getClearType()} [encrypted]"

View file

@ -19,22 +19,19 @@ package im.vector.app.features.spaces
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.utils.DebouncedClickListener
import im.vector.app.core.epoxy.onClick
@EpoxyModelClass(layout = R.layout.item_space_add)
abstract class SpaceAddItem : VectorEpoxyModel<SpaceAddItem.Holder>() {
@EpoxyAttribute var listener: (() -> Unit)? = null
@EpoxyAttribute var listener: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.view.setOnClickListener(
DebouncedClickListener({
listener?.invoke()
})
)
holder.view.onClick(listener)
}
class Holder : VectorEpoxyHolder()

View file

@ -119,15 +119,15 @@ class SpaceSummaryController @Inject constructor(
// show invites on top
summaries?.filter { it.membership == Membership.INVITE }
?.forEach {
?.forEach { roomSummary ->
spaceSummaryItem {
avatarRenderer(host.avatarRenderer)
id(it.roomId)
matrixItem(it.toMatrixItem())
id(roomSummary.roomId)
matrixItem(roomSummary.toMatrixItem())
countState(UnreadCounterBadgeView.State(1, true))
selected(false)
description(host.stringProvider.getString(R.string.you_are_invited))
listener { host.callback?.onSpaceInviteSelected(it) }
listener { host.callback?.onSpaceInviteSelected(roomSummary) }
}
}

View file

@ -26,11 +26,12 @@ import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.core.platform.CheckableConstraintLayout
import im.vector.app.core.utils.DebouncedClickListener
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.list.UnreadCounterBadgeView
import org.matrix.android.sdk.api.util.MatrixItem
@ -41,31 +42,23 @@ abstract class SpaceSummaryItem : VectorEpoxyModel<SpaceSummaryItem.Holder>() {
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) lateinit var avatarRenderer: AvatarRenderer
@EpoxyAttribute lateinit var matrixItem: MatrixItem
@EpoxyAttribute var selected: Boolean = false
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: (() -> Unit)? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var onMore: (() -> Unit)? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var toggleExpand: (() -> Unit)? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: ClickListener? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var onMore: ClickListener? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var toggleExpand: ClickListener? = null
@EpoxyAttribute var expanded: Boolean = false
@EpoxyAttribute var hasChildren: Boolean = false
@EpoxyAttribute var indent: Int = 0
@EpoxyAttribute var countState : UnreadCounterBadgeView.State = UnreadCounterBadgeView.State(0, false)
@EpoxyAttribute var countState: UnreadCounterBadgeView.State = UnreadCounterBadgeView.State(0, false)
@EpoxyAttribute var description: String? = null
@EpoxyAttribute var showSeparator: Boolean = false
override fun bind(holder: Holder) {
super.bind(holder)
holder.rootView.setOnClickListener { listener?.invoke() }
holder.rootView.onClick(listener)
holder.groupNameView.text = matrixItem.displayName
holder.rootView.isChecked = selected
if (onMore != null) {
holder.moreView.isVisible = true
holder.moreView.setOnClickListener(
DebouncedClickListener({ _ ->
onMore?.invoke()
})
)
} else {
holder.moreView.isVisible = false
}
holder.moreView.isVisible = onMore != null
holder.moreView.onClick(onMore)
holder.secondLineText.setTextOrHide(description)
if (hasChildren) {
@ -75,11 +68,7 @@ abstract class SpaceSummaryItem : VectorEpoxyModel<SpaceSummaryItem.Holder>() {
if (expanded) R.drawable.ic_expand_less else R.drawable.ic_expand_more
)
)
holder.collapseIndicator.setOnClickListener(
DebouncedClickListener({ _ ->
toggleExpand?.invoke()
})
)
holder.collapseIndicator.onClick(toggleExpand)
} else {
holder.collapseIndicator.isGone = true
}

View file

@ -25,10 +25,11 @@ import androidx.core.view.updateLayoutParams
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.platform.CheckableConstraintLayout
import im.vector.app.core.utils.DebouncedClickListener
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.list.UnreadCounterBadgeView
import org.matrix.android.sdk.api.util.MatrixItem
@ -39,9 +40,9 @@ abstract class SubSpaceSummaryItem : VectorEpoxyModel<SubSpaceSummaryItem.Holder
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) lateinit var avatarRenderer: AvatarRenderer
@EpoxyAttribute lateinit var matrixItem: MatrixItem
@EpoxyAttribute var selected: Boolean = false
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: (() -> Unit)? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var onMore: (() -> Unit)? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var toggleExpand: (() -> Unit)? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: ClickListener? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var onMore: ClickListener? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var toggleExpand: ClickListener? = null
@EpoxyAttribute var expanded: Boolean = false
@EpoxyAttribute var hasChildren: Boolean = false
@EpoxyAttribute var indent: Int = 0
@ -49,31 +50,18 @@ abstract class SubSpaceSummaryItem : VectorEpoxyModel<SubSpaceSummaryItem.Holder
override fun bind(holder: Holder) {
super.bind(holder)
holder.rootView.setOnClickListener { listener?.invoke() }
holder.rootView.onClick(listener)
holder.groupNameView.text = matrixItem.displayName
holder.rootView.isChecked = selected
if (onMore != null) {
holder.moreView.isVisible = true
holder.moreView.setOnClickListener(
DebouncedClickListener({ _ ->
onMore?.invoke()
})
)
} else {
holder.moreView.isVisible = false
}
holder.moreView.isVisible = onMore != null
holder.moreView.onClick(onMore)
holder.collapseIndicator.setImageDrawable(
ContextCompat.getDrawable(holder.view.context,
if (expanded) R.drawable.ic_expand_less else R.drawable.ic_expand_more
)
)
holder.collapseIndicator.setOnClickListener(
DebouncedClickListener({ _ ->
toggleExpand?.invoke()
})
)
holder.collapseIndicator.onClick(toggleExpand)
holder.collapseIndicator.isVisible = hasChildren
holder.indentSpace.isVisible = indent > 0

View file

@ -22,10 +22,10 @@ import android.view.View
import android.view.ViewGroup
import com.airbnb.mvrx.activityViewModel
import im.vector.app.R
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.platform.OnBackPressed
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.utils.DebouncedClickListener
import im.vector.app.databinding.FragmentSpaceCreateChoosePrivateModelBinding
import javax.inject.Inject
@ -41,13 +41,13 @@ class ChoosePrivateSpaceTypeFragment @Inject constructor(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
views.justMeButton.setOnClickListener(DebouncedClickListener({
views.justMeButton.onClick {
sharedViewModel.handle(CreateSpaceAction.SetSpaceTopology(SpaceTopology.JustMe))
}))
}
views.teammatesButton.setOnClickListener(DebouncedClickListener({
views.teammatesButton.onClick {
sharedViewModel.handle(CreateSpaceAction.SetSpaceTopology(SpaceTopology.MeAndTeammates))
}))
}
sharedViewModel.subscribe { state ->
views.accessInfoHelpText.text = stringProvider.getString(R.string.create_spaces_make_sure_access, state.name ?: "")

View file

@ -21,8 +21,8 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.airbnb.mvrx.activityViewModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.utils.DebouncedClickListener
import im.vector.app.databinding.FragmentSpaceCreateChooseTypeBinding
import javax.inject.Inject
@ -36,12 +36,12 @@ class ChooseSpaceTypeFragment @Inject constructor() : VectorBaseFragment<Fragmen
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
views.publicButton.setOnClickListener(DebouncedClickListener({
views.publicButton.onClick {
sharedViewModel.handle(CreateSpaceAction.SetRoomType(SpaceType.Public))
}))
}
views.privateButton.setOnClickListener(DebouncedClickListener({
sharedViewModel.handle(CreateSpaceAction.SetRoomType(SpaceType.Private))
}))
views.privateButton.onClick {
sharedViewModel.handle(CreateSpaceAction.SetRoomType(SpaceType.Private))
}
}
}

View file

@ -16,16 +16,18 @@
package im.vector.app.features.spaces.explore
import android.view.View
import com.airbnb.epoxy.TypedEpoxyController
import com.airbnb.mvrx.Fail
import com.airbnb.mvrx.Incomplete
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.errorWithRetryItem
import im.vector.app.core.epoxy.loadingItem
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.ui.list.GenericEmptyWithActionItem
import im.vector.app.core.ui.list.Action
import im.vector.app.core.ui.list.genericEmptyWithActionItem
import im.vector.app.core.ui.list.genericPillItem
import im.vector.app.features.home.AvatarRenderer
@ -106,11 +108,15 @@ class SpaceDirectoryController @Inject constructor(
apply {
if (data?.canAddRooms == true) {
description(host.stringProvider.getString(R.string.this_space_has_no_rooms_admin))
val action = GenericEmptyWithActionItem.Action(host.stringProvider.getString(R.string.space_add_existing_rooms))
action.perform = Runnable {
host.listener?.addExistingRooms(data.spaceId)
}
buttonAction(action)
buttonAction(
Action(
title = host.stringProvider.getString(R.string.space_add_existing_rooms),
listener = object : ClickListener {
override fun invoke(p1: View) {
host.listener?.addExistingRooms(data.spaceId)
}
}
))
} else {
description(host.stringProvider.getString(R.string.this_space_has_no_rooms_not_admin))
}

View file

@ -24,7 +24,6 @@ import im.vector.app.core.epoxy.profiles.profileMatrixItemWithPowerLevel
import im.vector.app.core.extensions.join
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.ui.list.GenericItem
import im.vector.app.core.ui.list.genericItem
import im.vector.app.core.utils.DimensionConverter
import im.vector.app.features.home.AvatarRenderer
@ -149,11 +148,9 @@ class SpacePeopleListController @Inject constructor(
}
}
)
itemClickAction(GenericItem.Action("invite").apply {
perform = Runnable {
host.listener?.onInviteToSpaceSelected()
}
})
itemClickAction {
host.listener?.onInviteToSpaceSelected()
}
}
}
}