From 0c7b9f4690bfe47e20afcbe21559df972424f3af Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 31 May 2021 11:58:04 +0200 Subject: [PATCH 01/15] Cleanup and format DebouncedClickListener --- .../app/core/utils/DebouncedClickListener.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/utils/DebouncedClickListener.kt b/vector/src/main/java/im/vector/app/core/utils/DebouncedClickListener.kt index 8f96a286d9..d5164371bb 100644 --- a/vector/src/main/java/im/vector/app/core/utils/DebouncedClickListener.kt +++ b/vector/src/main/java/im/vector/app/core/utils/DebouncedClickListener.kt @@ -15,6 +15,7 @@ */ package im.vector.app.core.utils +import android.os.SystemClock import android.view.View import java.util.WeakHashMap @@ -22,17 +23,20 @@ import java.util.WeakHashMap * Simple Debounced OnClickListener * Safe to use in different views */ -class DebouncedClickListener(val original: View.OnClickListener, private val minimumInterval: Long = 400) : View.OnClickListener { +class DebouncedClickListener( + val original: View.OnClickListener, + private val minimumInterval: Long = 400 +) : View.OnClickListener { private val lastClickMap = WeakHashMap() - override fun onClick(clickedView: View) { - val previousClickTimestamp = lastClickMap[clickedView] - val currentTimestamp = System.currentTimeMillis() + override fun onClick(v: View) { + val previousClickTimestamp = lastClickMap[v] + val currentTimestamp = SystemClock.elapsedRealtime() - lastClickMap[clickedView] = currentTimestamp + lastClickMap[v] = currentTimestamp - if (previousClickTimestamp == null || currentTimestamp - previousClickTimestamp.toLong() > minimumInterval) { - original.onClick(clickedView) + if (previousClickTimestamp == null || currentTimestamp - previousClickTimestamp > minimumInterval) { + original.onClick(v) } } } From 90634a9f9c6c2f1a8b46f1f9bf440950358ef0a8 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 31 May 2021 12:33:39 +0200 Subject: [PATCH 02/15] Use ClickListener and onClick extension wherever it's possible on Epoxy items --- .../java/im/vector/app/core/epoxy/Listener.kt | 6 +-- .../bottomsheet/BottomSheetActionItem.kt | 8 ++-- .../bottomsheet/BottomSheetRadioActionItem.kt | 10 ++--- .../bottomsheet/BottomSheetRoomPreviewItem.kt | 8 ++-- .../epoxy/profiles/BaseProfileMatrixItem.kt | 7 +-- .../BottomSheetGenericController.kt | 3 +- .../app/core/ui/list/GenericButtonItem.kt | 7 +-- .../core/ui/list/GenericPositiveButtonItem.kt | 8 ++-- .../app/core/ui/views/ReadReceiptsView.kt | 3 +- .../autocomplete/AutocompleteMatrixItem.kt | 7 +-- .../command/AutocompleteCommandController.kt | 4 +- .../command/AutocompleteCommandItem.kt | 8 ++-- .../group/AutocompleteGroupController.kt | 4 +- .../member/AutocompleteMemberController.kt | 4 +- .../room/AutocompleteRoomController.kt | 4 +- .../contactsbook/ContactsBookController.kt | 32 +++++++------- .../settings/KeysBackupSettingFooterItem.kt | 11 ++--- ...eysBackupSettingsRecyclerViewController.kt | 7 ++- .../devtools/RoomDevToolRootController.kt | 13 +++--- .../discovery/DiscoverySettingsController.kt | 3 +- .../features/discovery/SettingsInfoItem.kt | 7 +-- .../app/features/discovery/SettingsItem.kt | 7 +-- .../room/breadcrumbs/BreadcrumbsController.kt | 25 +++++------ .../home/room/breadcrumbs/BreadcrumbsItem.kt | 6 ++- .../action/MessageActionsEpoxyController.kt | 7 ++- .../timeline/factory/MessageItemFactory.kt | 8 ++-- .../factory/ReadReceiptsItemFactory.kt | 5 +-- .../helper/MessageItemAttributesFactory.kt | 9 ++-- .../timeline/item/AbsBaseMessageItem.kt | 10 +++-- .../detail/timeline/item/AbsMessageItem.kt | 5 ++- .../timeline/item/CallTileTimelineItem.kt | 3 +- .../timeline/item/MessageBlockCodeItem.kt | 3 +- .../detail/timeline/item/MessageFileItem.kt | 7 +-- .../timeline/item/MessageImageVideoItem.kt | 8 ++-- .../detail/timeline/item/MessageTextItem.kt | 3 +- .../detail/timeline/item/ReadReceiptsItem.kt | 8 ++-- .../timeline/item/StatusTileTimelineItem.kt | 3 +- .../timeline/item/VerificationRequestItem.kt | 44 +++++-------------- .../timeline/item/WidgetTileTimelineItem.kt | 3 +- .../detail/widget/RoomWidgetsController.kt | 11 +++-- .../home/room/list/RoomSummaryItem.kt | 6 ++- .../home/room/list/RoomSummaryItemFactory.kt | 11 ++--- .../home/room/list/SpaceChildInfoItem.kt | 13 +++--- .../RoomListQuickActionsEpoxyController.kt | 3 +- .../features/login/terms/PolicyController.kt | 4 +- .../app/features/login/terms/PolicyItem.kt | 7 +-- .../picker/RoomDirectoryPickerController.kt | 5 +-- .../detail/RoomAliasBottomSheetController.kt | 3 +- .../banned/RoomBannedMemberListController.kt | 2 +- .../members/RoomMemberListController.kt | 4 +- .../CrossSigningSettingsController.kt | 17 ++++--- .../features/settings/locale/LocaleItem.kt | 3 +- .../settings/locale/LocalePickerController.kt | 10 ++--- .../settings/threepids/ThreePidItem.kt | 2 +- .../threepids/ThreePidsSettingsController.kt | 5 +-- .../features/spaces/SpaceBetaHeaderItem.kt | 9 ++-- .../features/spaces/SpaceSummaryController.kt | 5 +-- .../explore/SpaceDirectoryController.kt | 7 ++- .../spaces/manage/AddRoomListController.kt | 5 +-- .../spaces/manage/RoomManageSelectionItem.kt | 9 ++-- .../spaces/manage/RoomSelectionItem.kt | 9 ++-- .../manage/SpaceManageRoomsController.kt | 5 +-- .../people/SpacePeopleListController.kt | 2 +- .../im/vector/app/features/terms/TermItem.kt | 7 +-- .../app/features/terms/TermsController.kt | 3 +- .../app/features/userdirectory/ActionItem.kt | 8 ++-- .../userdirectory/UserDirectoryUserItem.kt | 6 ++- .../userdirectory/UserListController.kt | 17 ++++--- 68 files changed, 245 insertions(+), 281 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/epoxy/Listener.kt b/vector/src/main/java/im/vector/app/core/epoxy/Listener.kt index e271b5abb5..b4fee0c810 100644 --- a/vector/src/main/java/im/vector/app/core/epoxy/Listener.kt +++ b/vector/src/main/java/im/vector/app/core/epoxy/Listener.kt @@ -19,10 +19,10 @@ package im.vector.app.core.epoxy import android.view.View /** - * Generally we do not care about the View parameter in [View.OnClickListener.onClick()], so create facility to remove it. + * View.OnClickListener lambda */ -typealias ClickListener = () -> Unit +typealias ClickListener = (View) -> Unit fun View.onClick(listener: ClickListener?) { - setOnClickListener { listener?.invoke() } + setOnClickListener { listener?.invoke(it) } } diff --git a/vector/src/main/java/im/vector/app/core/epoxy/bottomsheet/BottomSheetActionItem.kt b/vector/src/main/java/im/vector/app/core/epoxy/bottomsheet/BottomSheetActionItem.kt index 80792648f6..cd845d5e17 100644 --- a/vector/src/main/java/im/vector/app/core/epoxy/bottomsheet/BottomSheetActionItem.kt +++ b/vector/src/main/java/im/vector/app/core/epoxy/bottomsheet/BottomSheetActionItem.kt @@ -30,8 +30,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.features.themes.ThemeUtils /** @@ -70,13 +72,11 @@ abstract class BottomSheetActionItem : VectorEpoxyModel : VectorEpoxy @EpoxyAttribute var userEncryptionTrustLevel: RoomEncryptionTrustLevel? = null - @EpoxyAttribute var clickListener: View.OnClickListener? = null + @EpoxyAttribute var clickListener: ClickListener? = null @CallSuper override fun bind(holder: T) { @@ -43,7 +44,7 @@ abstract class BaseProfileMatrixItem : VectorEpoxy .takeIf { it != bestName } // Special case for ThreePid fake matrix item .takeIf { it != "@" } - holder.view.setOnClickListener(clickListener?.takeIf { editable }) + holder.view.onClick(clickListener?.takeIf { editable }) holder.titleView.text = bestName holder.subtitleView.setTextOrHide(matrixId) holder.editableView.isVisible = editable diff --git a/vector/src/main/java/im/vector/app/core/ui/bottomsheet/BottomSheetGenericController.kt b/vector/src/main/java/im/vector/app/core/ui/bottomsheet/BottomSheetGenericController.kt index 5edaa3400b..ab1480b635 100644 --- a/vector/src/main/java/im/vector/app/core/ui/bottomsheet/BottomSheetGenericController.kt +++ b/vector/src/main/java/im/vector/app/core/ui/bottomsheet/BottomSheetGenericController.kt @@ -15,7 +15,6 @@ */ package im.vector.app.core.ui.bottomsheet -import android.view.View import com.airbnb.epoxy.TypedEpoxyController /** @@ -51,7 +50,7 @@ abstract class BottomSheetGenericController action.toRadioBottomSheetItem() - .listener(View.OnClickListener { listener?.didSelectAction(action) }) + .listener { listener?.didSelectAction(action) } .addTo(this) } } diff --git a/vector/src/main/java/im/vector/app/core/ui/list/GenericButtonItem.kt b/vector/src/main/java/im/vector/app/core/ui/list/GenericButtonItem.kt index d1df785381..ba7d3b00ff 100644 --- a/vector/src/main/java/im/vector/app/core/ui/list/GenericButtonItem.kt +++ b/vector/src/main/java/im/vector/app/core/ui/list/GenericButtonItem.kt @@ -15,15 +15,16 @@ */ package im.vector.app.core.ui.list -import android.view.View import androidx.annotation.ColorInt import androidx.annotation.DrawableRes 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.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 /** @@ -36,7 +37,7 @@ abstract class GenericButtonItem : VectorEpoxyModel() var text: String? = null @EpoxyAttribute - var buttonClickAction: View.OnClickListener? = null + var buttonClickAction: ClickListener? = null @EpoxyAttribute @ColorInt @@ -57,7 +58,7 @@ abstract class GenericButtonItem : VectorEpoxyModel() holder.button.icon = null } - buttonClickAction?.let { holder.button.setOnClickListener(it) } + holder.button.onClick(buttonClickAction) } class Holder : VectorEpoxyHolder() { diff --git a/vector/src/main/java/im/vector/app/core/ui/list/GenericPositiveButtonItem.kt b/vector/src/main/java/im/vector/app/core/ui/list/GenericPositiveButtonItem.kt index d18adde4ba..efb053fde3 100644 --- a/vector/src/main/java/im/vector/app/core/ui/list/GenericPositiveButtonItem.kt +++ b/vector/src/main/java/im/vector/app/core/ui/list/GenericPositiveButtonItem.kt @@ -15,15 +15,16 @@ */ package im.vector.app.core.ui.list -import android.view.View import androidx.annotation.ColorInt import androidx.annotation.DrawableRes 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.ClickListener import im.vector.app.core.epoxy.VectorEpoxyHolder import im.vector.app.core.epoxy.VectorEpoxyModel +import im.vector.app.core.epoxy.onClick /** * A generic button list item. @@ -35,7 +36,7 @@ abstract class GenericPositiveButtonItem : VectorEpoxyModel, avatarRenderer: AvatarRenderer, clickListener: OnClickListener) { - setOnClickListener(clickListener) + fun render(readReceipts: List, avatarRenderer: AvatarRenderer) { if (readReceipts.isNotEmpty()) { isVisible = true for (index in 0 until MAX_RECEIPT_DISPLAYED) { diff --git a/vector/src/main/java/im/vector/app/features/autocomplete/AutocompleteMatrixItem.kt b/vector/src/main/java/im/vector/app/features/autocomplete/AutocompleteMatrixItem.kt index 28ea5234a7..ad1acc4fc2 100644 --- a/vector/src/main/java/im/vector/app/features/autocomplete/AutocompleteMatrixItem.kt +++ b/vector/src/main/java/im/vector/app/features/autocomplete/AutocompleteMatrixItem.kt @@ -16,14 +16,15 @@ package im.vector.app.features.autocomplete -import android.view.View import android.widget.ImageView 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.home.AvatarRenderer import org.matrix.android.sdk.api.util.MatrixItem @@ -34,11 +35,11 @@ abstract class AutocompleteMatrixItem : VectorEpoxyModel - host.listener?.onItemClick(command) - } + clickListener { host.listener?.onItemClick(command) } } } } diff --git a/vector/src/main/java/im/vector/app/features/autocomplete/command/AutocompleteCommandItem.kt b/vector/src/main/java/im/vector/app/features/autocomplete/command/AutocompleteCommandItem.kt index 0f24b866bf..65123bbc2f 100644 --- a/vector/src/main/java/im/vector/app/features/autocomplete/command/AutocompleteCommandItem.kt +++ b/vector/src/main/java/im/vector/app/features/autocomplete/command/AutocompleteCommandItem.kt @@ -16,13 +16,14 @@ package im.vector.app.features.autocomplete.command -import android.view.View 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 @EpoxyModelClass(layout = R.layout.item_autocomplete_command) abstract class AutocompleteCommandItem : VectorEpoxyModel() { @@ -37,12 +38,11 @@ abstract class AutocompleteCommandItem : VectorEpoxyModel - host.listener?.onItemClick(groupSummary) - } + clickListener { host.listener?.onItemClick(groupSummary) } } } } diff --git a/vector/src/main/java/im/vector/app/features/autocomplete/member/AutocompleteMemberController.kt b/vector/src/main/java/im/vector/app/features/autocomplete/member/AutocompleteMemberController.kt index 66c6705d14..9b4bd78504 100644 --- a/vector/src/main/java/im/vector/app/features/autocomplete/member/AutocompleteMemberController.kt +++ b/vector/src/main/java/im/vector/app/features/autocomplete/member/AutocompleteMemberController.kt @@ -40,9 +40,7 @@ class AutocompleteMemberController @Inject constructor() : TypedEpoxyController< id(user.userId) matrixItem(user.toMatrixItem()) avatarRenderer(host.avatarRenderer) - clickListener { _ -> - host.listener?.onItemClick(user) - } + clickListener { host.listener?.onItemClick(user) } } } } diff --git a/vector/src/main/java/im/vector/app/features/autocomplete/room/AutocompleteRoomController.kt b/vector/src/main/java/im/vector/app/features/autocomplete/room/AutocompleteRoomController.kt index 309c194272..cdc30938e7 100644 --- a/vector/src/main/java/im/vector/app/features/autocomplete/room/AutocompleteRoomController.kt +++ b/vector/src/main/java/im/vector/app/features/autocomplete/room/AutocompleteRoomController.kt @@ -39,9 +39,7 @@ class AutocompleteRoomController @Inject constructor(private val avatarRenderer: matrixItem(roomSummary.toMatrixItem()) subName(roomSummary.canonicalAlias) avatarRenderer(host.avatarRenderer) - clickListener { _ -> - host.listener?.onItemClick(roomSummary) - } + clickListener { host.listener?.onItemClick(roomSummary) } } } } diff --git a/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookController.kt b/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookController.kt index 5da66661fd..05a2bf641b 100644 --- a/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookController.kt +++ b/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookController.kt @@ -95,35 +95,35 @@ class ContactsBookController @Inject constructor( avatarRenderer(host.avatarRenderer) } mappedContact.emails - .forEachIndexed { index, it -> - if (onlyBoundContacts && it.matrixId == null) return@forEachIndexed + .forEachIndexed { index, email -> + if (onlyBoundContacts && email.matrixId == null) return@forEachIndexed contactDetailItem { - id("${mappedContact.id}-e-$index-${it.email}") - threePid(it.email) - matrixId(it.matrixId) + id("${mappedContact.id}-e-$index-${email.email}") + threePid(email.email) + matrixId(email.matrixId) clickListener { - if (it.matrixId != null) { - host.callback?.onMatrixIdClick(it.matrixId) + if (email.matrixId != null) { + host.callback?.onMatrixIdClick(email.matrixId) } else { - host.callback?.onThreePidClick(ThreePid.Email(it.email)) + host.callback?.onThreePidClick(ThreePid.Email(email.email)) } } } } mappedContact.msisdns - .forEachIndexed { index, it -> - if (onlyBoundContacts && it.matrixId == null) return@forEachIndexed + .forEachIndexed { index, msisdn -> + if (onlyBoundContacts && msisdn.matrixId == null) return@forEachIndexed contactDetailItem { - id("${mappedContact.id}-m-$index-${it.phoneNumber}") - threePid(it.phoneNumber) - matrixId(it.matrixId) + id("${mappedContact.id}-m-$index-${msisdn.phoneNumber}") + threePid(msisdn.phoneNumber) + matrixId(msisdn.matrixId) clickListener { - if (it.matrixId != null) { - host.callback?.onMatrixIdClick(it.matrixId) + if (msisdn.matrixId != null) { + host.callback?.onMatrixIdClick(msisdn.matrixId) } else { - host.callback?.onThreePidClick(ThreePid.Msisdn(it.phoneNumber)) + host.callback?.onThreePidClick(ThreePid.Msisdn(msisdn.phoneNumber)) } } } diff --git a/vector/src/main/java/im/vector/app/features/crypto/keysbackup/settings/KeysBackupSettingFooterItem.kt b/vector/src/main/java/im/vector/app/features/crypto/keysbackup/settings/KeysBackupSettingFooterItem.kt index 0489f18abe..78ca2b3de8 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/keysbackup/settings/KeysBackupSettingFooterItem.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/keysbackup/settings/KeysBackupSettingFooterItem.kt @@ -16,14 +16,15 @@ package im.vector.app.features.crypto.keysbackup.settings -import android.view.View import android.widget.Button 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 @EpoxyModelClass(layout = R.layout.item_keys_backup_settings_button_footer) @@ -33,21 +34,21 @@ abstract class KeysBackupSettingFooterItem : VectorEpoxyModel( var helperTextResId: Int? = null @EpoxyAttribute - var itemClickListener: View.OnClickListener? = null + var itemClickListener: ClickListener? = null @EpoxyAttribute @DrawableRes @@ -55,7 +56,7 @@ abstract class SettingsInfoItem : EpoxyModelWithHolder( holder.text.setTextOrHide(helperText) } - holder.view.setOnClickListener(itemClickListener) + holder.view.onClick(itemClickListener) if (showCompoundDrawable) { holder.text.setCompoundDrawablesWithIntrinsicBounds(compoundDrawable, 0, 0, 0) diff --git a/vector/src/main/java/im/vector/app/features/discovery/SettingsItem.kt b/vector/src/main/java/im/vector/app/features/discovery/SettingsItem.kt index 3471a3ab56..e7cb97a5b3 100644 --- a/vector/src/main/java/im/vector/app/features/discovery/SettingsItem.kt +++ b/vector/src/main/java/im/vector/app/features/discovery/SettingsItem.kt @@ -15,7 +15,6 @@ */ package im.vector.app.features.discovery -import android.view.View import android.widget.TextView import androidx.annotation.StringRes import androidx.core.view.isVisible @@ -24,7 +23,9 @@ import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelWithHolder import com.google.android.material.switchmaterial.SwitchMaterial 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 @EpoxyModelClass(layout = R.layout.item_settings_simple_item) @@ -45,7 +46,7 @@ abstract class SettingsItem : EpoxyModelWithHolder() { var description: CharSequence? = null @EpoxyAttribute - var itemClickListener: View.OnClickListener? = null + var itemClickListener: ClickListener? = null override fun bind(holder: Holder) { super.bind(holder) @@ -63,7 +64,7 @@ abstract class SettingsItem : EpoxyModelWithHolder() { holder.switchButton.isVisible = false - holder.view.setOnClickListener(itemClickListener) + holder.view.onClick(itemClickListener) } class Holder : VectorEpoxyHolder() { diff --git a/vector/src/main/java/im/vector/app/features/home/room/breadcrumbs/BreadcrumbsController.kt b/vector/src/main/java/im/vector/app/features/home/room/breadcrumbs/BreadcrumbsController.kt index 655b3dced6..50d5478ba1 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/breadcrumbs/BreadcrumbsController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/breadcrumbs/BreadcrumbsController.kt @@ -18,7 +18,6 @@ package im.vector.app.features.home.room.breadcrumbs import com.airbnb.epoxy.EpoxyController import im.vector.app.core.epoxy.zeroItem -import im.vector.app.core.utils.DebouncedClickListener import im.vector.app.features.home.AvatarRenderer import org.matrix.android.sdk.api.util.toMatrixItem import javax.inject.Inject @@ -53,21 +52,19 @@ class BreadcrumbsController @Inject constructor( // An empty breadcrumbs list can only be temporary because when entering in a room, // this one is added to the breadcrumbs safeViewState.asyncBreadcrumbs.invoke() - ?.forEach { + ?.forEach { roomSummary -> breadcrumbsItem { - id(it.roomId) - hasTypingUsers(it.typingUsers.isNotEmpty()) + id(roomSummary.roomId) + hasTypingUsers(roomSummary.typingUsers.isNotEmpty()) avatarRenderer(host.avatarRenderer) - matrixItem(it.toMatrixItem()) - unreadNotificationCount(it.notificationCount) - showHighlighted(it.highlightCount > 0) - hasUnreadMessage(it.hasUnreadMessages) - hasDraft(it.userDrafts.isNotEmpty()) - itemClickListener( - DebouncedClickListener({ _ -> - host.listener?.onBreadcrumbClicked(it.roomId) - }) - ) + matrixItem(roomSummary.toMatrixItem()) + unreadNotificationCount(roomSummary.notificationCount) + showHighlighted(roomSummary.highlightCount > 0) + hasUnreadMessage(roomSummary.hasUnreadMessages) + hasDraft(roomSummary.userDrafts.isNotEmpty()) + itemClickListener { + host.listener?.onBreadcrumbClicked(roomSummary.roomId) + } } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/breadcrumbs/BreadcrumbsItem.kt b/vector/src/main/java/im/vector/app/features/home/room/breadcrumbs/BreadcrumbsItem.kt index f39b7b6d0a..cfb8cd0aab 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/breadcrumbs/BreadcrumbsItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/breadcrumbs/BreadcrumbsItem.kt @@ -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.features.home.AvatarRenderer import im.vector.app.features.home.room.list.UnreadCounterBadgeView import org.matrix.android.sdk.api.util.MatrixItem @@ -39,11 +41,11 @@ abstract class BreadcrumbsItem : VectorEpoxyModel() { @EpoxyAttribute var showHighlighted: Boolean = false @EpoxyAttribute var hasUnreadMessage: Boolean = false @EpoxyAttribute var hasDraft: Boolean = false - @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var itemClickListener: View.OnClickListener? = null + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var itemClickListener: ClickListener? = null override fun bind(holder: Holder) { super.bind(holder) - holder.rootView.setOnClickListener(itemClickListener) + holder.rootView.onClick(itemClickListener) holder.unreadIndentIndicator.isVisible = hasUnreadMessage avatarRenderer.render(matrixItem, holder.avatarImageView) holder.avatarImageView.contentDescription = matrixItem.getBestName() diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsEpoxyController.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsEpoxyController.kt index e7c48739fc..303850c33f 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsEpoxyController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsEpoxyController.kt @@ -15,7 +15,6 @@ */ package im.vector.app.features.home.room.detail.timeline.action -import android.view.View import com.airbnb.epoxy.TypedEpoxyController import com.airbnb.mvrx.Success import im.vector.app.EmojiCompatFontProvider @@ -107,7 +106,7 @@ class MessageActionsEpoxyController @Inject constructor( } when (state.informationData.e2eDecoration) { - E2EDecoration.WARN_IN_CLEAR -> { + E2EDecoration.WARN_IN_CLEAR -> { bottomSheetSendStateItem { id("e2e_clear") showProgress(false) @@ -169,7 +168,7 @@ class MessageActionsEpoxyController @Inject constructor( textRes(action.titleRes) showExpand(action is EventSharedAction.ReportContent) expanded(state.expendedReportContentMenu) - listener(View.OnClickListener { host.listener?.didSelectMenuAction(action) }) + listener { host.listener?.didSelectMenuAction(action) } destructive(action.destructive) } @@ -185,7 +184,7 @@ class MessageActionsEpoxyController @Inject constructor( subMenuItem(true) iconRes(actionReport.iconResId) textRes(actionReport.titleRes) - listener(View.OnClickListener { host.listener?.didSelectMenuAction(actionReport) }) + listener { host.listener?.didSelectMenuAction(actionReport) } } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt index 7b9601ad33..c2ab7addd0 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -29,7 +29,6 @@ import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.files.LocalFilesHelper import im.vector.app.core.resources.ColorProvider import im.vector.app.core.resources.StringProvider -import im.vector.app.core.utils.DebouncedClickListener import im.vector.app.core.utils.DimensionConverter import im.vector.app.core.utils.containsOnlyEmojis import im.vector.app.features.home.room.detail.timeline.TimelineEventController @@ -322,10 +321,9 @@ class MessageItemFactory @Inject constructor( if (messageContent.msgType == MessageType.MSGTYPE_STICKER_LOCAL) { mode(ImageContentRenderer.Mode.STICKER) } else { - clickListener( - DebouncedClickListener({ view -> - callback?.onImageMessageClicked(messageContent, data, view) - })) + clickListener { view -> + callback?.onImageMessageClicked(messageContent, data, view) + } } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/ReadReceiptsItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/ReadReceiptsItemFactory.kt index 1d015d1bca..8a74a6d207 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/ReadReceiptsItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/ReadReceiptsItemFactory.kt @@ -16,7 +16,6 @@ package im.vector.app.features.home.room.detail.timeline.factory -import im.vector.app.core.utils.DebouncedClickListener import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.TimelineEventController import im.vector.app.features.home.room.detail.timeline.item.ReadReceiptData @@ -42,8 +41,8 @@ class ReadReceiptsItemFactory @Inject constructor(private val avatarRenderer: Av .eventId(eventId) .readReceipts(readReceiptsData) .avatarRenderer(avatarRenderer) - .clickListener(DebouncedClickListener({ _ -> + .clickListener { callback?.onReadReceiptsClicked(readReceiptsData) - })) + } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt index 043fd9e896..679613d262 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt @@ -16,7 +16,6 @@ package im.vector.app.features.home.room.detail.timeline.helper import im.vector.app.EmojiCompatFontProvider -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 @@ -41,12 +40,12 @@ class MessageItemAttributesFactory @Inject constructor( itemLongClickListener = { view -> callback?.onEventLongClicked(informationData, messageContent, view) ?: false }, - itemClickListener = DebouncedClickListener({ view -> + itemClickListener = { view -> callback?.onEventCellClicked(informationData, messageContent, view) - }), - memberClickListener = DebouncedClickListener({ + }, + memberClickListener = { callback?.onMemberNameClicked(informationData) - }), + }, reactionPillCallback = callback, avatarCallback = callback, readReceiptsCallback = callback, diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt index 39c04af089..080b766258 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt @@ -23,6 +23,8 @@ import android.widget.TextView import androidx.annotation.IdRes import androidx.core.view.isVisible 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.ShieldImageView import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.MessageColorProvider @@ -94,7 +96,7 @@ abstract class AbsBaseMessageItem : BaseEventItem } } - holder.view.setOnClickListener(baseAttributes.itemClickListener) + holder.view.onClick(baseAttributes.itemClickListener) holder.view.setOnLongClickListener(baseAttributes.itemLongClickListener) } @@ -124,9 +126,9 @@ abstract class AbsBaseMessageItem : BaseEventItem val avatarRenderer: AvatarRenderer val messageColorProvider: MessageColorProvider val itemLongClickListener: View.OnLongClickListener? - val itemClickListener: View.OnClickListener? + val itemClickListener: ClickListener? - // val memberClickListener: View.OnClickListener? + // val memberClickListener: ClickListener? val reactionPillCallback: TimelineEventController.ReactionPillCallback? // val avatarCallback: TimelineEventController.AvatarCallback? @@ -139,7 +141,7 @@ abstract class AbsBaseMessageItem : BaseEventItem // override val avatarRenderer: AvatarRenderer, // override val colorProvider: ColorProvider, // override val itemLongClickListener: View.OnLongClickListener? = null, -// override val itemClickListener: View.OnClickListener? = null, +// override val itemClickListener: ClickListener? = null, // override val reactionPillCallback: TimelineEventController.ReactionPillCallback? = null, // override val readReceiptsCallback: TimelineEventController.ReadReceiptsCallback? = null // ) : Attributes diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt index ed61abcf6e..aedb92ff1b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt @@ -26,6 +26,7 @@ import androidx.core.view.isInvisible 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.ui.views.SendStateImageView import im.vector.app.core.utils.DebouncedClickListener import im.vector.app.features.home.AvatarRenderer @@ -118,8 +119,8 @@ abstract class AbsMessageItem : AbsBaseMessageItem override val avatarRenderer: AvatarRenderer, override val messageColorProvider: MessageColorProvider, override val itemLongClickListener: View.OnLongClickListener? = null, - override val itemClickListener: View.OnClickListener? = null, - val memberClickListener: View.OnClickListener? = null, + override val itemClickListener: ClickListener? = null, + val memberClickListener: ClickListener? = null, override val reactionPillCallback: TimelineEventController.ReactionPillCallback? = null, val avatarCallback: TimelineEventController.AvatarCallback? = null, override val readReceiptsCallback: TimelineEventController.ReadReceiptsCallback? = null, diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/CallTileTimelineItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/CallTileTimelineItem.kt index 2d40035df1..1919fec456 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/CallTileTimelineItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/CallTileTimelineItem.kt @@ -28,6 +28,7 @@ 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.extensions.setLeftDrawable import im.vector.app.core.extensions.setTextWithColoredPart import im.vector.app.features.home.AvatarRenderer @@ -147,7 +148,7 @@ abstract class CallTileTimelineItem : AbsBaseMessageItem() { var iconRes: Int = 0 // @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) -// var clickListener: View.OnClickListener? = null +// var clickListener: ClickListener? = null @EpoxyAttribute var izLocalFile = false @@ -81,9 +82,9 @@ abstract class MessageFileItem : AbsMessageItem() { } // holder.view.setOnClickListener(clickListener) - holder.filenameView.setOnClickListener(attributes.itemClickListener) + holder.filenameView.onClick(attributes.itemClickListener) holder.filenameView.setOnLongClickListener(attributes.itemLongClickListener) - holder.fileImageWrapper.setOnClickListener(attributes.itemClickListener) + holder.fileImageWrapper.onClick(attributes.itemClickListener) holder.fileImageWrapper.setOnLongClickListener(attributes.itemLongClickListener) holder.filenameView.paintFlags = (holder.filenameView.paintFlags or Paint.UNDERLINE_TEXT_FLAG) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt index 2c0d1fcfbd..3ae91db97c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt @@ -24,6 +24,8 @@ 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.files.LocalFilesHelper import im.vector.app.core.glide.GlideApp import im.vector.app.features.home.room.detail.timeline.helper.ContentUploadStateTrackerBinder @@ -42,7 +44,7 @@ abstract class MessageImageVideoItem : AbsMessageItem() { holder.messageView.movementMethod = movementMethod renderSendState(holder.messageView, holder.messageView) - holder.messageView.setOnClickListener(attributes.itemClickListener) + holder.messageView.onClick(attributes.itemClickListener) holder.messageView.setOnLongClickListener(attributes.itemLongClickListener) if (canUseTextFuture) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/ReadReceiptsItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/ReadReceiptsItem.kt index b88afb0598..650c804cfa 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/ReadReceiptsItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/ReadReceiptsItem.kt @@ -16,12 +16,13 @@ package im.vector.app.features.home.room.detail.timeline.item -import android.view.View 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.ui.views.ReadReceiptsView import im.vector.app.features.home.AvatarRenderer @@ -31,7 +32,7 @@ abstract class ReadReceiptsItem : EpoxyModelWithHolder( @EpoxyAttribute lateinit var eventId: String @EpoxyAttribute lateinit var readReceipts: List @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) lateinit var avatarRenderer: AvatarRenderer - @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) lateinit var clickListener: View.OnClickListener + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) lateinit var clickListener: ClickListener override fun canAppendReadMarker(): Boolean = false @@ -39,7 +40,8 @@ abstract class ReadReceiptsItem : EpoxyModelWithHolder( override fun bind(holder: Holder) { super.bind(holder) - holder.readReceiptsView.render(readReceipts, avatarRenderer, clickListener) + holder.readReceiptsView.onClick(clickListener) + holder.readReceiptsView.render(readReceipts, avatarRenderer) } override fun unbind(holder: Holder) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/StatusTileTimelineItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/StatusTileTimelineItem.kt index c9eb14db66..c76e2b230a 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/StatusTileTimelineItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/StatusTileTimelineItem.kt @@ -26,6 +26,7 @@ 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.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.MessageColorProvider import im.vector.app.features.home.room.detail.timeline.TimelineEventController @@ -88,7 +89,7 @@ abstract class StatusTileTimelineItem : AbsBaseMessageItem(R.id.itemVerificationTitleTextView) val descriptionView by bind(R.id.itemVerificationDetailTextView) val buttonBar by bind(R.id.itemVerificationButtonBar) val statusTextView by bind(R.id.itemVerificationStatusText) val endGuideline by bind(R.id.messageEndGuideline) - private val declineButton by bind