Makes sure bind and unbind are calling super in items

This commit is contained in:
ganfra 2020-06-22 11:19:53 +02:00
parent 10d78a3102
commit f762c4c7a2
52 changed files with 58 additions and 4 deletions

View File

@ -1,6 +1,9 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<option name="RIGHT_MARGIN" value="160" />
<AndroidXmlCodeStyleSettings>
<option name="ARRANGEMENT_SETTINGS_MIGRATED_TO_191" value="true" />
</AndroidXmlCodeStyleSettings>
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>

View File

@ -29,6 +29,7 @@ abstract class DividerItem : VectorEpoxyModel<DividerItem.Holder>() {
@EpoxyAttribute var color: Int = -1
override fun bind(holder: Holder) {
super.bind(holder)
if (color != -1) {
holder.view.setBackgroundColor(color)
}

View File

@ -33,6 +33,7 @@ abstract class ErrorWithRetryItem : VectorEpoxyModel<ErrorWithRetryItem.Holder>(
var listener: (() -> Unit)? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.textView.text = text
holder.buttonView.isVisible = listener != null
holder.buttonView.setOnClickListener { listener?.invoke() }

View File

@ -28,6 +28,7 @@ abstract class HelpFooterItem : VectorEpoxyModel<HelpFooterItem.Holder>() {
var text: String? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.textView.text = text
}

View File

@ -28,6 +28,7 @@ abstract class NoResultItem : VectorEpoxyModel<NoResultItem.Holder>() {
var text: String? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.textView.text = text
}

View File

@ -16,6 +16,7 @@
package im.vector.riotx.core.epoxy
import androidx.annotation.CallSuper
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
@ -38,11 +39,13 @@ abstract class VectorEpoxyModel<H : VectorEpoxyHolder> : EpoxyModelWithHolder<H>
private var onModelVisibilityStateChangedListener: OnVisibilityStateChangedListener? = null
@CallSuper
override fun bind(holder: H) {
super.bind(holder)
lifecycleRegistry.currentState = Lifecycle.State.STARTED
}
@CallSuper
override fun unbind(holder: H) {
lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
coroutineScope.coroutineContext.cancelChildren()

View File

@ -58,6 +58,7 @@ abstract class BottomSheetActionItem : VectorEpoxyModel<BottomSheetActionItem.Ho
lateinit var listener: View.OnClickListener
override fun bind(holder: Holder) {
super.bind(holder)
holder.view.setOnClickListener {
listener.onClick(it)
}

View File

@ -49,6 +49,7 @@ abstract class BottomSheetMessagePreviewItem : VectorEpoxyModel<BottomSheetMessa
var userClicked: (() -> Unit)? = null
override fun bind(holder: Holder) {
super.bind(holder)
avatarRenderer.render(matrixItem, holder.avatar)
holder.avatar.setOnClickListener { userClicked?.invoke() }
holder.sender.setTextOrHide(matrixItem.displayName)

View File

@ -41,6 +41,7 @@ abstract class BottomSheetQuickReactionsItem : VectorEpoxyModel<BottomSheetQuick
var listener: Listener? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.textViews.forEachIndexed { index, textView ->
textView.typeface = fontProvider.typeface ?: Typeface.DEFAULT
textView.text = texts[index]

View File

@ -49,6 +49,7 @@ abstract class BottomSheetRoomPreviewItem : VectorEpoxyModel<BottomSheetRoomPrev
@EpoxyAttribute var favoriteClickListener: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
avatarRenderer.render(matrixItem, holder.avatar)
holder.avatar.onClick(settingsClickListener)
holder.roomName.setTextOrHide(matrixItem.displayName)

View File

@ -41,6 +41,7 @@ abstract class BottomSheetSendStateItem : VectorEpoxyModel<BottomSheetSendStateI
var drawableStart: Int = 0
override fun bind(holder: Holder) {
super.bind(holder)
holder.progress.isVisible = showProgress
holder.text.setCompoundDrawablesWithIntrinsicBounds(drawableStart, 0, 0, 0)
holder.text.text = text

View File

@ -40,6 +40,7 @@ abstract class ProfileMatrixItem : VectorEpoxyModel<ProfileMatrixItem.Holder>()
@EpoxyAttribute var clickListener: View.OnClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
val bestName = matrixItem.getBestName()
val matrixId = matrixItem.id.takeIf { it != bestName }
holder.view.setOnClickListener(clickListener)

View File

@ -47,6 +47,7 @@ abstract class GenericButtonItem : VectorEpoxyModel<GenericButtonItem.Holder>()
var iconRes: Int? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.button.text = text
val textColor = textColor ?: ThemeUtils.getColor(holder.view.context, R.attr.riotx_text_primary)
holder.button.setTextColor(textColor)

View File

@ -52,6 +52,7 @@ abstract class GenericFooterItem : VectorEpoxyModel<GenericFooterItem.Holder>()
var textColor: Int? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.text.setTextOrHide(text)
when (style) {
GenericItem.STYLE.BIG_TEXT -> holder.text.textSize = 18f

View File

@ -74,6 +74,7 @@ abstract class GenericItem : VectorEpoxyModel<GenericItem.Holder>() {
var itemClickAction: Action? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.titleText.setTextOrHide(title)
if (titleIconResourceId != -1) {

View File

@ -33,6 +33,7 @@ abstract class GenericItemHeader : VectorEpoxyModel<GenericItemHeader.Holder>()
var text: String? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.text.setTextOrHide(text)
}

View File

@ -57,6 +57,7 @@ abstract class GenericItemWithValue : VectorEpoxyModel<GenericItemWithValue.Hold
var itemClickAction: View.OnClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.titleText.setTextOrHide(title)
if (titleIconResourceId != -1) {

View File

@ -13,7 +13,9 @@ abstract class GenericLoaderItem : VectorEpoxyModel<GenericLoaderItem.Holder>()
// Maybe/Later add some style configuration, SMALL/BIG ?
override fun bind(holder: Holder) {}
override fun bind(holder: Holder) {
super.bind(holder)
}
class Holder : VectorEpoxyHolder()
}

View File

@ -33,6 +33,7 @@ abstract class AttachmentPreviewItem<H : AttachmentPreviewItem.Holder> : VectorE
abstract val attachment: ContentAttachmentData
override fun bind(holder: H) {
super.bind(holder)
if (attachment.type == ContentAttachmentData.Type.VIDEO || attachment.type == ContentAttachmentData.Type.IMAGE) {
Glide.with(holder.view.context)
.asBitmap()

View File

@ -37,6 +37,7 @@ abstract class AutocompleteMatrixItem : VectorEpoxyModel<AutocompleteMatrixItem.
@EpoxyAttribute var clickListener: View.OnClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.view.setOnClickListener(clickListener)
holder.nameView.text = matrixItem.getBestName()
holder.subNameView.setTextOrHide(subName)

View File

@ -37,6 +37,7 @@ abstract class AutocompleteCommandItem : VectorEpoxyModel<AutocompleteCommandIte
var clickListener: View.OnClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.view.setOnClickListener(clickListener)
holder.nameView.text = name

View File

@ -40,6 +40,7 @@ abstract class AutocompleteEmojiItem : VectorEpoxyModel<AutocompleteEmojiItem.Ho
var onClickListener: ReactionClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.emojiText.text = emojiItem.emoji
holder.emojiText.typeface = emojiTypeFace ?: Typeface.DEFAULT
holder.emojiNameText.text = emojiItem.name

View File

@ -42,6 +42,7 @@ abstract class KeysBackupSettingFooterItem : VectorEpoxyModel<KeysBackupSettingF
var clickOnButton2: View.OnClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.button1.setTextOrHide(textButton1)
holder.button1.setOnClickListener(clickOnButton1)

View File

@ -51,6 +51,7 @@ abstract class BottomSheetVerificationActionItem : VectorEpoxyModel<BottomSheetV
lateinit var listener: () -> Unit
override fun bind(holder: Holder) {
super.bind(holder)
holder.view.setOnClickListener {
listener.invoke()
}

View File

@ -37,6 +37,7 @@ abstract class BottomSheetVerificationBigImageItem : VectorEpoxyModel<BottomShee
var contentDescription: String? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.image.setImageResource(imageRes)
if (contentDescription == null) {

View File

@ -33,6 +33,7 @@ abstract class BottomSheetVerificationDecimalCodeItem : VectorEpoxyModel<BottomS
var code: CharSequence = ""
override fun bind(holder: Holder) {
super.bind(holder)
holder.code.text = code
}

View File

@ -47,6 +47,7 @@ abstract class BottomSheetVerificationEmojisItem : VectorEpoxyModel<BottomSheetV
@EpoxyAttribute lateinit var emojiRepresentation6: EmojiRepresentation
override fun bind(holder: Holder) {
super.bind(holder)
bindEmojiView(holder.emoji0View, emojiRepresentation0)
bindEmojiView(holder.emoji1View, emojiRepresentation1)
bindEmojiView(holder.emoji2View, emojiRepresentation2)

View File

@ -33,6 +33,7 @@ abstract class BottomSheetVerificationNoticeItem : VectorEpoxyModel<BottomSheetV
var notice: CharSequence = ""
override fun bind(holder: Holder) {
super.bind(holder)
holder.notice.text = notice
}

View File

@ -36,6 +36,7 @@ abstract class BottomSheetVerificationQrCodeItem : VectorEpoxyModel<BottomSheetV
var animate = false
override fun bind(holder: Holder) {
super.bind(holder)
holder.qsrCodeImage.setData(data, animate)
}

View File

@ -33,6 +33,7 @@ abstract class BottomSheetVerificationWaitingItem : VectorEpoxyModel<BottomSheet
var title: CharSequence = ""
override fun bind(holder: Holder) {
super.bind(holder)
holder.title.text = title
}

View File

@ -48,6 +48,7 @@ abstract class SettingsItem : EpoxyModelWithHolder<SettingsItem.Holder>() {
var itemClickListener: View.OnClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
if (titleResId != null) {
holder.titleText.setText(titleResId!!)
} else {

View File

@ -48,6 +48,7 @@ abstract class FormEditTextItem : VectorEpoxyModel<FormEditTextItem.Holder>() {
}
override fun bind(holder: Holder) {
super.bind(holder)
holder.textInputLayout.isEnabled = enabled
holder.textInputLayout.hint = hint

View File

@ -44,6 +44,7 @@ abstract class FormSwitchItem : VectorEpoxyModel<FormSwitchItem.Holder>() {
var summary: String? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.view.setOnClickListener {
if (enabled) {
holder.switchView.toggle()

View File

@ -36,6 +36,7 @@ abstract class DisplayReadReceiptItem : EpoxyModelWithHolder<DisplayReadReceiptI
@EpoxyAttribute var userClicked: (() -> Unit)? = null
override fun bind(holder: Holder) {
super.bind(holder)
avatarRenderer.render(matrixItem, holder.avatarView)
holder.displayNameView.text = matrixItem.getBestName()
timestamp?.let {

View File

@ -29,6 +29,7 @@ abstract class DaySeparatorItem : EpoxyModelWithHolder<DaySeparatorItem.Holder>(
@EpoxyAttribute lateinit var formattedDay: CharSequence
override fun bind(holder: Holder) {
super.bind(holder)
holder.dayTextView.text = formattedDay
}

View File

@ -30,6 +30,7 @@ abstract class RoomCreateItem : VectorEpoxyModel<RoomCreateItem.Holder>() {
@EpoxyAttribute lateinit var text: CharSequence
override fun bind(holder: Holder) {
super.bind(holder)
holder.description.movementMethod = BetterLinkMovementMethod.getInstance()
holder.description.text = text
}

View File

@ -24,8 +24,6 @@ import im.vector.riotx.core.epoxy.VectorEpoxyModel
@EpoxyModelClass(layout = R.layout.item_timeline_read_marker)
abstract class TimelineReadMarkerItem : VectorEpoxyModel<TimelineReadMarkerItem.Holder>() {
override fun bind(holder: Holder) {
}
class Holder : VectorEpoxyHolder()
}

View File

@ -40,6 +40,7 @@ abstract class ReactionInfoSimpleItem : EpoxyModelWithHolder<ReactionInfoSimpleI
var userClicked: (() -> Unit)? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.emojiReactionView.text = reactionKey
holder.displayNameView.text = authorDisplayName
timeStamp?.let {

View File

@ -33,6 +33,7 @@ abstract class RoomWidgetItem : EpoxyModelWithHolder<RoomWidgetItem.Holder>() {
@EpoxyAttribute var widgetClicked: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.widgetName.text = widget.name
holder.view.onClick(widgetClicked)
}

View File

@ -34,6 +34,7 @@ abstract class FilteredRoomFooterItem : VectorEpoxyModel<FilteredRoomFooterItem.
var currentFilter: String = ""
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) }

View File

@ -37,6 +37,7 @@ abstract class RoomCategoryItem : VectorEpoxyModel<RoomCategoryItem.Holder>() {
@EpoxyAttribute var listener: (() -> Unit)? = null
override fun bind(holder: Holder) {
super.bind(holder)
val tintColor = ThemeUtils.getColor(holder.rootView.context, R.attr.riotx_text_secondary)
val expandedArrowDrawableRes = if (expanded) R.drawable.ic_expand_more_white else R.drawable.ic_expand_less_white
val expandedArrowDrawable = ContextCompat.getDrawable(holder.rootView.context, expandedArrowDrawableRes)?.also {

View File

@ -44,6 +44,7 @@ abstract class PolicyItem : EpoxyModelWithHolder<PolicyItem.Holder>() {
var clickListener: View.OnClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.let {
it.checkbox.isChecked = checked
it.checkbox.setOnCheckedChangeListener(checkChangeListener)

View File

@ -57,6 +57,7 @@ abstract class PublicRoomItem : VectorEpoxyModel<PublicRoomItem.Holder>() {
var joinListener: (() -> Unit)? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.rootView.setOnClickListener { globalListener?.invoke() }
avatarRenderer.render(matrixItem, holder.avatarView)

View File

@ -46,6 +46,7 @@ abstract class RoomDirectoryItem : VectorEpoxyModel<RoomDirectoryItem.Holder>()
var globalListener: (() -> Unit)? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.rootView.setOnClickListener { globalListener?.invoke() }
// Avatar

View File

@ -73,6 +73,7 @@ abstract class DeviceItem : VectorEpoxyModel<DeviceItem.Holder>() {
var dimensionConverter: DimensionConverter? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.root.setOnClickListener { itemClickAction?.invoke() }
val shield = TrustUtils.shieldForTrust(

View File

@ -43,6 +43,7 @@ abstract class UserItem : VectorEpoxyModel<UserItem.Holder>() {
var itemClickAction: (() -> Unit)? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.root.setOnClickListener { itemClickAction?.invoke() }
avatarRenderer.render(matrixItem, holder.avatarImage)

View File

@ -31,6 +31,7 @@ abstract class PushGatewayItem : EpoxyModelWithHolder<PushGatewayItem.Holder>()
lateinit var pusher: Pusher
override fun bind(holder: Holder) {
super.bind(holder)
holder.kind.text = when (pusher.kind) {
// TODO Create const
"http" -> "Http Pusher"

View File

@ -41,6 +41,7 @@ abstract class PushRuleItem : EpoxyModelWithHolder<PushRuleItem.Holder>() {
// TODO i18n
@SuppressLint("SetTextI18n")
override fun bind(holder: Holder) {
super.bind(holder)
val context = holder.view.context
if (pushRule.enabled) {
holder.view.setBackgroundColor(Color.TRANSPARENT)

View File

@ -34,6 +34,7 @@ abstract class LoginErrorWithRetryItem : VectorEpoxyModel<LoginErrorWithRetryIte
var listener: (() -> Unit)? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.textView.text = text
holder.buttonView.setOnClickListener { listener?.invoke() }
}

View File

@ -45,6 +45,7 @@ abstract class TermItem : EpoxyModelWithHolder<TermItem.Holder>() {
var clickListener: View.OnClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.checkbox.isChecked = checked
holder.title.text = name
holder.description.text = description

View File

@ -29,6 +29,7 @@ abstract class UserDirectoryLetterHeaderItem : VectorEpoxyModel<UserDirectoryLet
@EpoxyAttribute var letter: String = ""
override fun bind(holder: Holder) {
super.bind(holder)
holder.letterView.text = letter
}

View File

@ -38,6 +38,7 @@ abstract class UserDirectoryUserItem : VectorEpoxyModel<UserDirectoryUserItem.Ho
@EpoxyAttribute var selected: Boolean = false
override fun bind(holder: Holder) {
super.bind(holder)
holder.view.setOnClickListener(clickListener)
// If name is empty, use userId as name and force it being centered
if (matrixItem.displayName.isNullOrEmpty()) {