More click listener...

This commit is contained in:
Benoit Marty 2021-05-31 17:02:04 +02:00
parent 316e685690
commit 6dd1bc3385
16 changed files with 90 additions and 147 deletions

View File

@ -24,6 +24,8 @@ import android.widget.FrameLayout
import androidx.core.view.isInvisible import androidx.core.view.isInvisible
import androidx.core.view.isVisible import androidx.core.view.isVisible
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.onClick
import im.vector.app.databinding.ViewButtonStateBinding import im.vector.app.databinding.ViewButtonStateBinding
class ButtonStateView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) class ButtonStateView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0)
@ -36,12 +38,9 @@ class ButtonStateView @JvmOverloads constructor(context: Context, attrs: Attribu
object Error : State() object Error : State()
} }
var callback: Callback? = null var commonClicked: ClickListener? = null
var buttonClicked: ClickListener? = null
interface Callback { var retryClicked: ClickListener? = null
fun onButtonClicked()
fun onRetryClicked()
}
// Big or Flat button // Big or Flat button
var button: Button var button: Button
@ -54,8 +53,9 @@ class ButtonStateView @JvmOverloads constructor(context: Context, attrs: Attribu
layoutParams = LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) layoutParams = LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
views.buttonStateRetry.setOnClickListener { views.buttonStateRetry.onClick {
callback?.onRetryClicked() commonClicked?.invoke(it)
retryClicked?.invoke(it)
} }
// Read attributes // Read attributes
@ -80,8 +80,9 @@ class ButtonStateView @JvmOverloads constructor(context: Context, attrs: Attribu
} }
} }
button.setOnClickListener { button.onClick {
callback?.onButtonClicked() commonClicked?.invoke(it)
buttonClicked?.invoke(it)
} }
} }

View File

@ -23,8 +23,10 @@ import androidx.core.graphics.drawable.DrawableCompat
import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R 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.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.features.themes.ThemeUtils import im.vector.app.features.themes.ThemeUtils
@EpoxyModelClass(layout = R.layout.item_room_category) @EpoxyModelClass(layout = R.layout.item_room_category)
@ -34,7 +36,7 @@ abstract class RoomCategoryItem : VectorEpoxyModel<RoomCategoryItem.Holder>() {
@EpoxyAttribute var expanded: Boolean = false @EpoxyAttribute var expanded: Boolean = false
@EpoxyAttribute var unreadNotificationCount: Int = 0 @EpoxyAttribute var unreadNotificationCount: Int = 0
@EpoxyAttribute var showHighlighted: Boolean = false @EpoxyAttribute var showHighlighted: Boolean = false
@EpoxyAttribute var listener: (() -> Unit)? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: ClickListener? = null
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
@ -46,7 +48,7 @@ abstract class RoomCategoryItem : VectorEpoxyModel<RoomCategoryItem.Holder>() {
holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted)) holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted))
holder.titleView.setCompoundDrawablesWithIntrinsicBounds(null, null, expandedArrowDrawable, null) holder.titleView.setCompoundDrawablesWithIntrinsicBounds(null, null, expandedArrowDrawable, null)
holder.titleView.text = title holder.titleView.text = title
holder.rootView.setOnClickListener { listener?.invoke() } holder.rootView.onClick(listener)
} }
class Holder : VectorEpoxyHolder() { class Holder : VectorEpoxyHolder() {

View File

@ -22,8 +22,10 @@ import android.widget.TextView
import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R 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.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel 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.extensions.setTextOrHide
import im.vector.app.core.platform.ButtonStateView import im.vector.app.core.platform.ButtonStateView
import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.AvatarRenderer
@ -37,36 +39,16 @@ abstract class RoomInvitationItem : VectorEpoxyModel<RoomInvitationItem.Holder>(
@EpoxyAttribute lateinit var avatarRenderer: AvatarRenderer @EpoxyAttribute lateinit var avatarRenderer: AvatarRenderer
@EpoxyAttribute lateinit var matrixItem: MatrixItem @EpoxyAttribute lateinit var matrixItem: MatrixItem
@EpoxyAttribute var secondLine: CharSequence? = null @EpoxyAttribute var secondLine: CharSequence? = null
@EpoxyAttribute var listener: (() -> Unit)? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: ClickListener? = null
@EpoxyAttribute lateinit var changeMembershipState: ChangeMembershipState @EpoxyAttribute lateinit var changeMembershipState: ChangeMembershipState
@EpoxyAttribute var acceptListener: (() -> Unit)? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var acceptListener: ClickListener? = null
@EpoxyAttribute var rejectListener: (() -> Unit)? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var rejectListener: ClickListener? = null
private val acceptCallback = object : ButtonStateView.Callback {
override fun onButtonClicked() {
acceptListener?.invoke()
}
override fun onRetryClicked() {
acceptListener?.invoke()
}
}
private val rejectCallback = object : ButtonStateView.Callback {
override fun onButtonClicked() {
rejectListener?.invoke()
}
override fun onRetryClicked() {
rejectListener?.invoke()
}
}
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
holder.rootView.setOnClickListener { listener?.invoke() } holder.rootView.onClick(listener)
holder.acceptView.callback = acceptCallback holder.acceptView.commonClicked = acceptListener
holder.rejectView.callback = rejectCallback holder.rejectView.commonClicked = rejectListener
InviteButtonStateBinder.bind(holder.acceptView, holder.rejectView, changeMembershipState) InviteButtonStateBinder.bind(holder.acceptView, holder.rejectView, changeMembershipState)
holder.titleView.text = matrixItem.getBestName() holder.titleView.text = matrixItem.getBestName()
holder.subtitleView.setTextOrHide(secondLine) holder.subtitleView.setTextOrHide(secondLine)

View File

@ -23,10 +23,8 @@ import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.updateLayoutParams import androidx.core.view.updateLayoutParams
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.di.HasScreenInjector import im.vector.app.core.di.HasScreenInjector
import im.vector.app.core.platform.ButtonStateView
import im.vector.app.databinding.VectorInviteViewBinding import im.vector.app.databinding.VectorInviteViewBinding
import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.AvatarRenderer
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
import org.matrix.android.sdk.api.util.toMatrixItem import org.matrix.android.sdk.api.util.toMatrixItem
@ -56,25 +54,8 @@ class VectorInviteView @JvmOverloads constructor(context: Context, attrs: Attrib
} }
inflate(context, R.layout.vector_invite_view, this) inflate(context, R.layout.vector_invite_view, this)
views = VectorInviteViewBinding.bind(this) views = VectorInviteViewBinding.bind(this)
views.inviteAcceptView.callback = object : ButtonStateView.Callback { views.inviteAcceptView.commonClicked = { callback?.onAcceptInvite() }
override fun onButtonClicked() { views.inviteRejectView.commonClicked = { callback?.onRejectInvite() }
callback?.onAcceptInvite()
}
override fun onRetryClicked() {
callback?.onAcceptInvite()
}
}
views.inviteRejectView.callback = object : ButtonStateView.Callback {
override fun onButtonClicked() {
callback?.onRejectInvite()
}
override fun onRetryClicked() {
callback?.onRejectInvite()
}
}
} }
fun render(sender: RoomMemberSummary, mode: Mode = Mode.LARGE, changeMembershipState: ChangeMembershipState) { fun render(sender: RoomMemberSummary, mode: Mode = Mode.LARGE, changeMembershipState: ChangeMembershipState) {

View File

@ -51,19 +51,8 @@ class MatrixToRoomSpaceFragment @Inject constructor(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
views.matrixToCardMainButton.callback = object : ButtonStateView.Callback { views.matrixToCardMainButton.commonClicked = { mainButtonClicked() }
override fun onButtonClicked() { views.matrixToCardSecondaryButton.commonClicked = { secondaryButtonClicked() }
mainButtonClicked()
}
override fun onRetryClicked() = onButtonClicked()
}
views.matrixToCardSecondaryButton.callback = object : ButtonStateView.Callback {
override fun onButtonClicked() {
secondaryButtonClicked()
}
override fun onRetryClicked() = onButtonClicked()
}
} }
override fun invalidate() = withState(sharedViewModel) { state -> override fun invalidate() = withState(sharedViewModel) { state ->

View File

@ -22,8 +22,10 @@ import android.widget.TextView
import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R 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.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel 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.extensions.setTextOrHide
import im.vector.app.core.platform.ButtonStateView import im.vector.app.core.platform.ButtonStateView
import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.AvatarRenderer
@ -50,15 +52,15 @@ abstract class PublicRoomItem : VectorEpoxyModel<PublicRoomItem.Holder>() {
@EpoxyAttribute @EpoxyAttribute
var joinState: JoinState = JoinState.NOT_JOINED var joinState: JoinState = JoinState.NOT_JOINED
@EpoxyAttribute @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var globalListener: (() -> Unit)? = null var globalListener: ClickListener? = null
@EpoxyAttribute @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var joinListener: (() -> Unit)? = null var joinListener: ClickListener? = null
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
holder.rootView.setOnClickListener { globalListener?.invoke() } holder.rootView.onClick(globalListener)
avatarRenderer.render(matrixItem, holder.avatarView) avatarRenderer.render(matrixItem, holder.avatarView)
holder.nameView.text = matrixItem.displayName holder.nameView.text = matrixItem.displayName
@ -76,16 +78,7 @@ abstract class PublicRoomItem : VectorEpoxyModel<PublicRoomItem.Holder>() {
} }
) )
holder.buttonState.callback = object : ButtonStateView.Callback { holder.buttonState.commonClicked = { joinListener?.invoke(it) }
override fun onButtonClicked() {
joinListener?.invoke()
}
override fun onRetryClicked() {
// Same action
onButtonClicked()
}
}
} }
class Holder : VectorEpoxyHolder() { class Holder : VectorEpoxyHolder() {

View File

@ -22,8 +22,10 @@ import android.widget.TextView
import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R 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.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.AvatarRenderer
import org.matrix.android.sdk.api.util.MatrixItem import org.matrix.android.sdk.api.util.MatrixItem
@ -36,12 +38,12 @@ abstract class UnknownRoomItem : VectorEpoxyModel<UnknownRoomItem.Holder>() {
@EpoxyAttribute @EpoxyAttribute
lateinit var matrixItem: MatrixItem lateinit var matrixItem: MatrixItem
@EpoxyAttribute @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var globalListener: (() -> Unit)? = null var globalListener: ClickListener? = null
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
holder.rootView.setOnClickListener { globalListener?.invoke() } holder.rootView.onClick(globalListener)
avatarRenderer.render(matrixItem, holder.avatarView) avatarRenderer.render(matrixItem, holder.avatarView)
holder.nameView.text = matrixItem.displayName holder.nameView.text = matrixItem.displayName
} }

View File

@ -25,8 +25,10 @@ import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R 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.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel 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.extensions.setTextOrHide
import im.vector.app.core.glide.GlideApp import im.vector.app.core.glide.GlideApp
@ -48,12 +50,12 @@ abstract class RoomDirectoryItem : VectorEpoxyModel<RoomDirectoryItem.Holder>()
@EpoxyAttribute @EpoxyAttribute
var checked: Boolean = false var checked: Boolean = false
@EpoxyAttribute @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var globalListener: (() -> Unit)? = null var globalListener: ClickListener? = null
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
holder.rootView.setOnClickListener { globalListener?.invoke() } holder.rootView.onClick(globalListener)
// Avatar // Avatar
GlideApp.with(holder.avatarView) GlideApp.with(holder.avatarView)

View File

@ -57,16 +57,7 @@ class RoomPreviewNoPreviewFragment @Inject constructor(
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
setupToolbar(views.roomPreviewNoPreviewToolbar) setupToolbar(views.roomPreviewNoPreviewToolbar)
views.roomPreviewNoPreviewJoin.callback = object : ButtonStateView.Callback { views.roomPreviewNoPreviewJoin.commonClicked = { roomPreviewViewModel.handle(RoomPreviewAction.Join) }
override fun onButtonClicked() {
roomPreviewViewModel.handle(RoomPreviewAction.Join)
}
override fun onRetryClicked() {
// Same action
onButtonClicked()
}
}
} }
override fun invalidate() = withState(roomPreviewViewModel) { state -> override fun invalidate() = withState(roomPreviewViewModel) { state ->

View File

@ -23,8 +23,10 @@ import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R 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.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.resources.ColorProvider import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.ui.views.ShieldImageView import im.vector.app.core.ui.views.ShieldImageView
import im.vector.app.core.utils.DimensionConverter import im.vector.app.core.utils.DimensionConverter
@ -47,8 +49,8 @@ abstract class DeviceItem : VectorEpoxyModel<DeviceItem.Holder>() {
@EpoxyAttribute @EpoxyAttribute
var currentDevice = false var currentDevice = false
@EpoxyAttribute @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var itemClickAction: (() -> Unit)? = null var itemClickAction: ClickListener? = null
@EpoxyAttribute @EpoxyAttribute
var detailedMode = false var detailedMode = false
@ -73,7 +75,7 @@ abstract class DeviceItem : VectorEpoxyModel<DeviceItem.Holder>() {
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
holder.root.setOnClickListener { itemClickAction?.invoke() } holder.root.onClick(itemClickAction)
if (e2eCapable) { if (e2eCapable) {
val shield = TrustUtils.shieldForTrust( val shield = TrustUtils.shieldForTrust(

View File

@ -21,8 +21,10 @@ import android.widget.TextView
import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R 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.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel 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.extensions.setTextOrHide
import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.AvatarRenderer
import org.matrix.android.sdk.api.util.MatrixItem import org.matrix.android.sdk.api.util.MatrixItem
@ -39,12 +41,12 @@ abstract class UserItem : VectorEpoxyModel<UserItem.Holder>() {
@EpoxyAttribute @EpoxyAttribute
lateinit var matrixItem: MatrixItem lateinit var matrixItem: MatrixItem
@EpoxyAttribute @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var itemClickAction: (() -> Unit)? = null var itemClickAction: ClickListener? = null
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
holder.root.setOnClickListener { itemClickAction?.invoke() } holder.root.onClick(itemClickAction)
avatarRenderer.render(matrixItem, holder.avatarImage) avatarRenderer.render(matrixItem, holder.avatarImage)
holder.userIdText.setTextOrHide(matrixItem.id) holder.userIdText.setTextOrHide(matrixItem.id)

View File

@ -20,23 +20,23 @@ import android.widget.Button
import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R 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.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel 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.extensions.setTextOrHide
@EpoxyModelClass(layout = R.layout.item_login_centered_button) @EpoxyModelClass(layout = R.layout.item_login_centered_button)
abstract class LoginCenterButtonItem : VectorEpoxyModel<LoginCenterButtonItem.Holder>() { abstract class LoginCenterButtonItem : VectorEpoxyModel<LoginCenterButtonItem.Holder>() {
@EpoxyAttribute var text: String? = null @EpoxyAttribute var text: String? = null
@EpoxyAttribute var listener: (() -> Unit)? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: ClickListener? = null
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
holder.button.setTextOrHide(text) holder.button.setTextOrHide(text)
holder.button.setOnClickListener { holder.button.onClick(listener)
listener?.invoke()
}
} }
class Holder : VectorEpoxyHolder() { class Holder : VectorEpoxyHolder() {

View File

@ -21,8 +21,10 @@ import android.widget.TextView
import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R 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.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
@EpoxyModelClass(layout = R.layout.item_login_error_retry) @EpoxyModelClass(layout = R.layout.item_login_error_retry)
abstract class LoginErrorWithRetryItem : VectorEpoxyModel<LoginErrorWithRetryItem.Holder>() { abstract class LoginErrorWithRetryItem : VectorEpoxyModel<LoginErrorWithRetryItem.Holder>() {
@ -30,13 +32,13 @@ abstract class LoginErrorWithRetryItem : VectorEpoxyModel<LoginErrorWithRetryIte
@EpoxyAttribute @EpoxyAttribute
var text: String? = null var text: String? = null
@EpoxyAttribute @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var listener: (() -> Unit)? = null var listener: ClickListener? = null
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
holder.textView.text = text holder.textView.text = text
holder.buttonView.setOnClickListener { listener?.invoke() } holder.buttonView.onClick(listener)
} }
class Holder : VectorEpoxyHolder() { class Holder : VectorEpoxyHolder() {

View File

@ -25,9 +25,11 @@ import com.airbnb.epoxy.EpoxyModelClass
import com.google.android.material.textfield.TextInputEditText import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
import im.vector.app.R 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.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.addTextChangedListenerOnce import im.vector.app.core.epoxy.addTextChangedListenerOnce
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.extensions.showPassword import im.vector.app.core.extensions.showPassword
import im.vector.app.core.platform.SimpleTextWatcher import im.vector.app.core.platform.SimpleTextWatcher
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
@ -40,8 +42,8 @@ abstract class LoginPasswordFormItem : VectorEpoxyModel<LoginPasswordFormItem.Ho
@EpoxyAttribute var submitEnabled: Boolean = false @EpoxyAttribute var submitEnabled: Boolean = false
@EpoxyAttribute var errorText: String? = null @EpoxyAttribute var errorText: String? = null
@EpoxyAttribute lateinit var stringProvider: StringProvider @EpoxyAttribute lateinit var stringProvider: StringProvider
@EpoxyAttribute var passwordRevealClickListener: (() -> Unit)? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var passwordRevealClickListener: ClickListener? = null
@EpoxyAttribute var forgetPasswordClickListener: (() -> Unit)? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var forgetPasswordClickListener: ClickListener? = null
@EpoxyAttribute var submitClickListener: ((String) -> Unit)? = null @EpoxyAttribute var submitClickListener: ((String) -> Unit)? = null
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var onPasswordEdited: ((String) -> Unit)? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var onPasswordEdited: ((String) -> Unit)? = null
@ -57,8 +59,8 @@ abstract class LoginPasswordFormItem : VectorEpoxyModel<LoginPasswordFormItem.Ho
setupAutoFill(holder) setupAutoFill(holder)
holder.passwordFieldTil.error = errorText holder.passwordFieldTil.error = errorText
renderPasswordField(holder) renderPasswordField(holder)
holder.passwordReveal.setOnClickListener { passwordRevealClickListener?.invoke() } holder.passwordReveal.onClick(passwordRevealClickListener)
holder.forgetPassword.setOnClickListener { forgetPasswordClickListener?.invoke() } holder.forgetPassword.onClick(forgetPasswordClickListener)
holder.submit.isEnabled = submitEnabled holder.submit.isEnabled = submitEnabled
holder.submit.setOnClickListener { submitClickListener?.invoke(holder.passwordField.text.toString()) } holder.submit.setOnClickListener { submitClickListener?.invoke(holder.passwordField.text.toString()) }
holder.passwordField.addTextChangedListenerOnce(textChangeListener) holder.passwordField.addTextChangedListenerOnce(textChangeListener)

View File

@ -20,23 +20,23 @@ import android.widget.Button
import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R 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.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel 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.extensions.setTextOrHide
@EpoxyModelClass(layout = R.layout.item_login_red_button) @EpoxyModelClass(layout = R.layout.item_login_red_button)
abstract class LoginRedButtonItem : VectorEpoxyModel<LoginRedButtonItem.Holder>() { abstract class LoginRedButtonItem : VectorEpoxyModel<LoginRedButtonItem.Holder>() {
@EpoxyAttribute var text: String? = null @EpoxyAttribute var text: String? = null
@EpoxyAttribute var listener: (() -> Unit)? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var listener: ClickListener? = null
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
holder.button.setTextOrHide(text) holder.button.setTextOrHide(text)
holder.button.setOnClickListener { holder.button.onClick(listener)
listener?.invoke()
}
} }
class Holder : VectorEpoxyHolder() { class Holder : VectorEpoxyHolder() {

View File

@ -79,24 +79,16 @@ class SpaceInviteBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetIn
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
views.spaceCard.matrixToCardMainButton.callback = object : ButtonStateView.Callback { views.spaceCard.matrixToCardMainButton.commonClicked = {
override fun onButtonClicked() { // quick local echo
// quick local echo views.spaceCard.matrixToCardMainButton.render(ButtonStateView.State.Loading)
views.spaceCard.matrixToCardMainButton.render(ButtonStateView.State.Loading) views.spaceCard.matrixToCardSecondaryButton.button.isEnabled = false
views.spaceCard.matrixToCardSecondaryButton.button.isEnabled = false viewModel.handle(SpaceInviteBottomSheetAction.DoJoin)
viewModel.handle(SpaceInviteBottomSheetAction.DoJoin)
}
override fun onRetryClicked() = onButtonClicked()
} }
views.spaceCard.matrixToCardSecondaryButton.callback = object : ButtonStateView.Callback { views.spaceCard.matrixToCardSecondaryButton.commonClicked = {
override fun onButtonClicked() { views.spaceCard.matrixToCardMainButton.button.isEnabled = false
views.spaceCard.matrixToCardMainButton.button.isEnabled = false views.spaceCard.matrixToCardSecondaryButton.render(ButtonStateView.State.Loading)
views.spaceCard.matrixToCardSecondaryButton.render(ButtonStateView.State.Loading) viewModel.handle(SpaceInviteBottomSheetAction.DoReject)
viewModel.handle(SpaceInviteBottomSheetAction.DoReject)
}
override fun onRetryClicked() = onButtonClicked()
} }
viewModel.observeViewEvents { viewModel.observeViewEvents {
@ -144,15 +136,15 @@ class SpaceInviteBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetIn
Uninitialized -> { Uninitialized -> {
views.spaceCard.matrixToCardMainButton.render(ButtonStateView.State.Button) views.spaceCard.matrixToCardMainButton.render(ButtonStateView.State.Button)
} }
is Loading -> { is Loading -> {
views.spaceCard.matrixToCardMainButton.render(ButtonStateView.State.Loading) views.spaceCard.matrixToCardMainButton.render(ButtonStateView.State.Loading)
views.spaceCard.matrixToCardSecondaryButton.button.isEnabled = false views.spaceCard.matrixToCardSecondaryButton.button.isEnabled = false
} }
is Success -> { is Success -> {
interactionListener?.spaceInviteBottomSheetOnAccept(inviteArgs.spaceId) interactionListener?.spaceInviteBottomSheetOnAccept(inviteArgs.spaceId)
dismiss() dismiss()
} }
is Fail -> { is Fail -> {
views.spaceCard.matrixToCardMainButton.render(ButtonStateView.State.Error) views.spaceCard.matrixToCardMainButton.render(ButtonStateView.State.Error)
views.spaceCard.matrixToCardSecondaryButton.button.isEnabled = true views.spaceCard.matrixToCardSecondaryButton.button.isEnabled = true
} }
@ -162,15 +154,15 @@ class SpaceInviteBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetIn
Uninitialized -> { Uninitialized -> {
views.spaceCard.matrixToCardSecondaryButton.render(ButtonStateView.State.Button) views.spaceCard.matrixToCardSecondaryButton.render(ButtonStateView.State.Button)
} }
is Loading -> { is Loading -> {
views.spaceCard.matrixToCardSecondaryButton.render(ButtonStateView.State.Loading) views.spaceCard.matrixToCardSecondaryButton.render(ButtonStateView.State.Loading)
views.spaceCard.matrixToCardMainButton.button.isEnabled = false views.spaceCard.matrixToCardMainButton.button.isEnabled = false
} }
is Success -> { is Success -> {
interactionListener?.spaceInviteBottomSheetOnDecline(inviteArgs.spaceId) interactionListener?.spaceInviteBottomSheetOnDecline(inviteArgs.spaceId)
dismiss() dismiss()
} }
is Fail -> { is Fail -> {
views.spaceCard.matrixToCardSecondaryButton.render(ButtonStateView.State.Error) views.spaceCard.matrixToCardSecondaryButton.render(ButtonStateView.State.Error)
views.spaceCard.matrixToCardSecondaryButton.button.isEnabled = true views.spaceCard.matrixToCardSecondaryButton.button.isEnabled = true
} }