From 33252c3b65bc075d19a0a66245650a2eeab38d95 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 12 Jul 2019 10:16:43 +0200 Subject: [PATCH 1/3] Green text color during encrypting --- .../timeline/factory/EncryptedItemFactory.kt | 1 + .../timeline/factory/MessageItemFactory.kt | 8 ++++ .../helper/ContentUploadStateTrackerBinder.kt | 16 ++++++-- .../detail/timeline/item/AbsMessageItem.kt | 11 ++++-- .../detail/timeline/item/MessageFileItem.kt | 2 +- .../timeline/item/MessageImageVideoItem.kt | 3 +- .../detail/timeline/item/MessageTextItem.kt | 2 +- .../riotx/features/ui/ColorProviderExt.kt | 37 +++++++++++++++++++ vector/src/main/res/values/theme_dark.xml | 2 +- vector/src/main/res/values/theme_light.xml | 2 +- 10 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 vector/src/main/java/im/vector/riotx/features/ui/ColorProviderExt.kt diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/EncryptedItemFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/EncryptedItemFactory.kt index 2a4a0c0f..080565cd 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/EncryptedItemFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/EncryptedItemFactory.kt @@ -68,6 +68,7 @@ class EncryptedItemFactory @Inject constructor(private val messageInformationDat return MessageTextItem_() .message(spannableStr) .avatarRenderer(avatarRenderer) + .colorProvider(colorProvider) .informationData(informationData) .highlighted(highlight) .avatarCallback(callback) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt index d8f1c602..02e3e43b 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -117,6 +117,7 @@ class MessageItemFactory @Inject constructor( callback: TimelineEventController.Callback?): MessageFileItem? { return MessageFileItem_() .avatarRenderer(avatarRenderer) + .colorProvider(colorProvider) .informationData(informationData) .highlighted(highlight) .avatarCallback(callback) @@ -144,6 +145,7 @@ class MessageItemFactory @Inject constructor( callback: TimelineEventController.Callback?): MessageFileItem? { return MessageFileItem_() .avatarRenderer(avatarRenderer) + .colorProvider(colorProvider) .informationData(informationData) .highlighted(highlight) .avatarCallback(callback) @@ -195,6 +197,7 @@ class MessageItemFactory @Inject constructor( ) return MessageImageVideoItem_() .avatarRenderer(avatarRenderer) + .colorProvider(colorProvider) .imageContentRenderer(imageContentRenderer) .contentUploadStateTrackerBinder(contentUploadStateTrackerBinder) .playable(messageContent.info?.mimeType == "image/gif") @@ -246,6 +249,7 @@ class MessageItemFactory @Inject constructor( .imageContentRenderer(imageContentRenderer) .contentUploadStateTrackerBinder(contentUploadStateTrackerBinder) .avatarRenderer(avatarRenderer) + .colorProvider(colorProvider) .playable(true) .informationData(informationData) .highlighted(highlight) @@ -288,6 +292,7 @@ class MessageItemFactory @Inject constructor( } .avatarRenderer(avatarRenderer) .informationData(informationData) + .colorProvider(colorProvider) .highlighted(highlight) .avatarCallback(callback) .urlClickCallback(callback) @@ -353,6 +358,7 @@ class MessageItemFactory @Inject constructor( return MessageTextItem_() .avatarRenderer(avatarRenderer) .message(message) + .colorProvider(colorProvider) .informationData(informationData) .highlighted(highlight) .avatarCallback(callback) @@ -393,6 +399,7 @@ class MessageItemFactory @Inject constructor( } } .avatarRenderer(avatarRenderer) + .colorProvider(colorProvider) .informationData(informationData) .highlighted(highlight) .avatarCallback(callback) @@ -414,6 +421,7 @@ class MessageItemFactory @Inject constructor( callback: TimelineEventController.Callback?): RedactedMessageItem? { return RedactedMessageItem_() .avatarRenderer(avatarRenderer) + .colorProvider(colorProvider) .informationData(informationData) .highlighted(highlight) .avatarCallback(callback) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt index 688cac3d..ca796667 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt @@ -23,12 +23,16 @@ import android.widget.ProgressBar import android.widget.TextView import androidx.core.view.isVisible import im.vector.matrix.android.api.session.content.ContentUploadStateTracker +import im.vector.matrix.android.api.session.room.send.SendState import im.vector.riotx.R import im.vector.riotx.core.di.ActiveSessionHolder +import im.vector.riotx.core.resources.ColorProvider import im.vector.riotx.features.media.ImageContentRenderer +import im.vector.riotx.features.ui.getMessageTextColor import javax.inject.Inject -class ContentUploadStateTrackerBinder @Inject constructor(private val activeSessionHolder: ActiveSessionHolder) { +class ContentUploadStateTrackerBinder @Inject constructor(private val activeSessionHolder: ActiveSessionHolder, + private val colorProvider: ColorProvider) { private val updateListeners = mutableMapOf() @@ -38,7 +42,7 @@ class ContentUploadStateTrackerBinder @Inject constructor(private val activeSess activeSessionHolder.getActiveSession().also { session -> val uploadStateTracker = session.contentUploadProgressTracker() - val updateListener = ContentMediaProgressUpdater(progressLayout, mediaData) + val updateListener = ContentMediaProgressUpdater(progressLayout, mediaData, colorProvider) updateListeners[eventId] = updateListener uploadStateTracker.track(eventId, updateListener) } @@ -56,7 +60,8 @@ class ContentUploadStateTrackerBinder @Inject constructor(private val activeSess } private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, - private val mediaData: ImageContentRenderer.Data) : ContentUploadStateTracker.UpdateListener { + private val mediaData: ImageContentRenderer.Data, + private val colorProvider: ColorProvider) : ContentUploadStateTracker.UpdateListener { override fun onUpdate(state: ContentUploadStateTracker.State) { when (state) { @@ -79,6 +84,7 @@ private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, progressBar?.isIndeterminate = true progressBar?.progress = 0 progressTextView?.text = progressLayout.context.getString(R.string.send_file_step_idle) + progressTextView?.setTextColor(colorProvider.getMessageTextColor(SendState.UNSENT)) } else { progressLayout.isVisible = false } @@ -106,6 +112,7 @@ private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, val progressTextView = progressLayout.findViewById(R.id.mediaProgressTextView) progressBar?.isIndeterminate = true progressTextView?.text = progressLayout.context.getString(resId) + progressTextView?.setTextColor(colorProvider.getMessageTextColor(SendState.ENCRYPTING)) } private fun doHandleProgress(resId: Int, current: Long, total: Long) { @@ -119,6 +126,7 @@ private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, progressTextView?.text = progressLayout.context.getString(resId, Formatter.formatShortFileSize(progressLayout.context, current), Formatter.formatShortFileSize(progressLayout.context, total)) + progressTextView?.setTextColor(colorProvider.getMessageTextColor(SendState.SENDING)) } private fun handleFailure(state: ContentUploadStateTracker.State.Failure) { @@ -126,8 +134,8 @@ private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, val progressBar = progressLayout.findViewById(R.id.mediaProgressBar) val progressTextView = progressLayout.findViewById(R.id.mediaProgressTextView) progressBar?.isVisible = false - // TODO Red text progressTextView?.text = state.throwable.localizedMessage + progressTextView?.setTextColor(colorProvider.getMessageTextColor(SendState.UNDELIVERED)) } private fun handleSuccess(state: ContentUploadStateTracker.State.Success) { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt index 7a66c6ad..f76601cd 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt @@ -29,11 +29,13 @@ import androidx.core.view.isGone import androidx.core.view.isVisible import com.airbnb.epoxy.EpoxyAttribute import im.vector.riotx.R +import im.vector.riotx.core.resources.ColorProvider import im.vector.riotx.core.utils.DebouncedClickListener import im.vector.riotx.core.utils.DimensionUtils.dpToPx import im.vector.riotx.features.home.AvatarRenderer import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController import im.vector.riotx.features.reactions.widget.ReactionButton +import im.vector.riotx.features.ui.getMessageTextColor abstract class AbsMessageItem : BaseEventItem() { @@ -42,6 +44,9 @@ abstract class AbsMessageItem : BaseEventItem() { abstract val avatarRenderer: AvatarRenderer + @EpoxyAttribute + lateinit var colorProvider: ColorProvider + @EpoxyAttribute var longClickListener: View.OnLongClickListener? = null @@ -153,9 +158,9 @@ abstract class AbsMessageItem : BaseEventItem() { return true } - protected fun View.renderSendState() { - isClickable = informationData.sendState.isSent() - alpha = if (informationData.sendState.isSent()) 1f else 0.5f + protected fun renderSendState(root: View, textView: TextView?) { + root.isClickable = informationData.sendState.isSent() + textView?.setTextColor(colorProvider.getMessageTextColor(informationData.sendState)) } abstract class Holder : BaseHolder() { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt index 66b368df..3d5fb452 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt @@ -44,7 +44,7 @@ abstract class MessageFileItem : AbsMessageItem() { override fun bind(holder: Holder) { super.bind(holder) - holder.fileLayout.renderSendState() + renderSendState(holder.fileLayout, holder.filenameView) holder.filenameView.text = filename holder.fileImageView.setImageResource(iconRes) holder.filenameView.setOnClickListener(clickListener) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageImageVideoItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageImageVideoItem.kt index 67f0ed7b..bc47be74 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageImageVideoItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageImageVideoItem.kt @@ -52,7 +52,8 @@ abstract class MessageImageVideoItem : AbsMessageItem() { null) holder.messageView.setTextFuture(textFuture) - holder.messageView.renderSendState() + renderSendState(holder.messageView, holder.messageView) holder.messageView.setOnClickListener(cellClickListener) holder.messageView.setOnLongClickListener(longClickListener) findPillsAndProcess { it.bind(holder.messageView) } diff --git a/vector/src/main/java/im/vector/riotx/features/ui/ColorProviderExt.kt b/vector/src/main/java/im/vector/riotx/features/ui/ColorProviderExt.kt new file mode 100644 index 00000000..a53ed921 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/ui/ColorProviderExt.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2019 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.riotx.features.ui + +import androidx.annotation.ColorInt +import im.vector.matrix.android.api.session.room.send.SendState +import im.vector.riotx.R +import im.vector.riotx.core.resources.ColorProvider + +@ColorInt +fun ColorProvider.getMessageTextColor(sendState: SendState): Int { + return when (sendState) { + // SendStates, in the classical order they will occur + SendState.UNKNOWN, + SendState.UNSENT -> getColorFromAttribute(R.attr.vctr_sending_message_text_color) + SendState.ENCRYPTING -> getColorFromAttribute(R.attr.vctr_encrypting_message_text_color) + SendState.SENDING -> getColorFromAttribute(R.attr.vctr_sending_message_text_color) + SendState.SENT, + SendState.SYNCED -> getColorFromAttribute(R.attr.vctr_message_text_color) + SendState.UNDELIVERED, + SendState.FAILED_UNKNOWN_DEVICES -> getColorFromAttribute(R.attr.vctr_unsent_message_text_color) + } +} diff --git a/vector/src/main/res/values/theme_dark.xml b/vector/src/main/res/values/theme_dark.xml index 76cd365e..826ab5f1 100644 --- a/vector/src/main/res/values/theme_dark.xml +++ b/vector/src/main/res/values/theme_dark.xml @@ -93,7 +93,7 @@ @android:color/white @color/riot_primary_text_color_dark @color/accent_color_dark - ?android:textColorSecondary + @color/riotx_text_secondary_dark @color/vector_fuchsia_color @color/primary_color_light #CCC3C3C3 diff --git a/vector/src/main/res/values/theme_light.xml b/vector/src/main/res/values/theme_light.xml index f7f9a260..d55148e7 100644 --- a/vector/src/main/res/values/theme_light.xml +++ b/vector/src/main/res/values/theme_light.xml @@ -93,7 +93,7 @@ @color/riot_primary_text_color_light #FF61708b @color/accent_color_light - ?android:textColorSecondary + @color/riotx_text_secondary_light @color/vector_fuchsia_color @color/primary_color_light #333C3C3C From bd009caaf13c878e7a1a2075054d96896d59ef65 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 12 Jul 2019 10:22:58 +0200 Subject: [PATCH 2/3] Code cleanup --- .../home/room/detail/timeline/item/AbsMessageItem.kt | 6 ++++-- .../home/room/detail/timeline/item/MessageFileItem.kt | 5 ----- .../room/detail/timeline/item/MessageImageVideoItem.kt | 5 ----- .../home/room/detail/timeline/item/MessageTextItem.kt | 5 ----- .../home/room/detail/timeline/item/RedactedMessageItem.kt | 7 ------- 5 files changed, 4 insertions(+), 24 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt index f76601cd..cdcfceef 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt @@ -40,9 +40,11 @@ import im.vector.riotx.features.ui.getMessageTextColor abstract class AbsMessageItem : BaseEventItem() { - abstract val informationData: MessageInformationData + @EpoxyAttribute + lateinit var informationData: MessageInformationData - abstract val avatarRenderer: AvatarRenderer + @EpoxyAttribute + lateinit var avatarRenderer: AvatarRenderer @EpoxyAttribute lateinit var colorProvider: ColorProvider diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt index 3d5fb452..e63881e2 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt @@ -25,7 +25,6 @@ import androidx.annotation.DrawableRes import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass import im.vector.riotx.R -import im.vector.riotx.features.home.AvatarRenderer @EpoxyModelClass(layout = R.layout.item_timeline_event_base) abstract class MessageFileItem : AbsMessageItem() { @@ -36,10 +35,6 @@ abstract class MessageFileItem : AbsMessageItem() { @DrawableRes var iconRes: Int = 0 @EpoxyAttribute - override lateinit var informationData: MessageInformationData - @EpoxyAttribute - override lateinit var avatarRenderer: AvatarRenderer - @EpoxyAttribute var clickListener: View.OnClickListener? = null override fun bind(holder: Holder) { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageImageVideoItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageImageVideoItem.kt index bc47be74..b3cbaab0 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageImageVideoItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageImageVideoItem.kt @@ -22,7 +22,6 @@ import android.widget.ImageView import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass import im.vector.riotx.R -import im.vector.riotx.features.home.AvatarRenderer import im.vector.riotx.features.home.room.detail.timeline.helper.ContentUploadStateTrackerBinder import im.vector.riotx.features.media.ImageContentRenderer @@ -32,10 +31,6 @@ abstract class MessageImageVideoItem : AbsMessageItem() { @EpoxyAttribute var message: CharSequence? = null @EpoxyAttribute - override lateinit var avatarRenderer: AvatarRenderer - @EpoxyAttribute - override lateinit var informationData: MessageInformationData - @EpoxyAttribute var urlClickCallback: TimelineEventController.UrlClickCallback? = null private val mvmtMethod = BetterLinkMovementMethod.newInstance().also { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/RedactedMessageItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/RedactedMessageItem.kt index 05967f00..f3979c54 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/RedactedMessageItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/RedactedMessageItem.kt @@ -16,19 +16,12 @@ package im.vector.riotx.features.home.room.detail.timeline.item -import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass import im.vector.riotx.R -import im.vector.riotx.features.home.AvatarRenderer @EpoxyModelClass(layout = R.layout.item_timeline_event_base) abstract class RedactedMessageItem : AbsMessageItem() { - @EpoxyAttribute - override lateinit var informationData: MessageInformationData - @EpoxyAttribute - override lateinit var avatarRenderer: AvatarRenderer - override fun getStubType(): Int = STUB_ID override fun shouldShowReactionAtBottom() = false From 41465450d8475d073aaf24bc37edd748deed6fec Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 12 Jul 2019 10:45:08 +0200 Subject: [PATCH 3/3] Code cleanup --- .../detail/timeline/item/AbsMessageItem.kt | 4 ++-- .../detail/timeline/item/BaseEventItem.kt | 20 +++++-------------- .../room/detail/timeline/item/DefaultItem.kt | 6 ++---- .../detail/timeline/item/MergedHeaderItem.kt | 7 +++---- .../detail/timeline/item/MessageFileItem.kt | 9 +++------ .../timeline/item/MessageImageVideoItem.kt | 12 +++-------- .../detail/timeline/item/MessageTextItem.kt | 9 +++++---- .../room/detail/timeline/item/NoticeItem.kt | 5 ++--- .../timeline/item/RedactedMessageItem.kt | 10 ++++------ 9 files changed, 29 insertions(+), 53 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt index cdcfceef..88697db4 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt @@ -23,6 +23,7 @@ import android.view.ViewGroup import android.view.ViewStub import android.widget.ImageView import android.widget.TextView +import androidx.annotation.IdRes import androidx.constraintlayout.helper.widget.Flow import androidx.core.view.children import androidx.core.view.isGone @@ -165,8 +166,7 @@ abstract class AbsMessageItem : BaseEventItem() { textView?.setTextColor(colorProvider.getMessageTextColor(informationData.sendState)) } - abstract class Holder : BaseHolder() { - + abstract class Holder(@IdRes stubId: Int) : BaseHolder(stubId) { val avatarImageView by bind(R.id.messageAvatarImageView) val memberNameView by bind(R.id.messageMemberNameView) val timeView by bind(R.id.messageTimeView) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/BaseEventItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/BaseEventItem.kt index 3a7d09e2..843f52b3 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/BaseEventItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/BaseEventItem.kt @@ -26,6 +26,9 @@ import im.vector.riotx.core.epoxy.VectorEpoxyModel import im.vector.riotx.core.platform.CheckableView import im.vector.riotx.core.utils.DimensionUtils.dpToPx +/** + * Children must override getViewType() + */ abstract class BaseEventItem : VectorEpoxyModel() { var avatarStyle: AvatarStyle = AvatarStyle.SMALL @@ -43,31 +46,18 @@ abstract class BaseEventItem : VectorEpoxyModel holder.checkableBackground.isChecked = highlighted } - - override fun getViewType(): Int { - return getStubType() - } - - abstract fun getStubType(): Int - - - abstract class BaseHolder : VectorEpoxyHolder() { - + abstract class BaseHolder(@IdRes val stubId: Int) : VectorEpoxyHolder() { val leftGuideline by bind(R.id.messageStartGuideline) val checkableBackground by bind(R.id.messageSelectedBackground) - @IdRes - abstract fun getStubId(): Int - override fun bindView(itemView: View) { super.bindView(itemView) inflateStub() } private fun inflateStub() { - view.findViewById(getStubId()).inflate() + view.findViewById(stubId).inflate() } - } companion object { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/DefaultItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/DefaultItem.kt index cc50493a..0b30facf 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/DefaultItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/DefaultItem.kt @@ -31,11 +31,9 @@ abstract class DefaultItem : BaseEventItem() { holder.messageView.text = text } - override fun getStubType(): Int = STUB_ID - - class Holder : BaseHolder() { - override fun getStubId(): Int = STUB_ID + override fun getViewType() = STUB_ID + class Holder : BaseHolder(STUB_ID) { val messageView by bind(R.id.stateMessageView) } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MergedHeaderItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MergedHeaderItem.kt index 0ad13fcf..4f26f9bb 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MergedHeaderItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MergedHeaderItem.kt @@ -46,7 +46,7 @@ data class MergedHeaderItem(private val isCollapsed: Boolean, return Holder() } - override fun getStubType(): Int = STUB_ID + override fun getViewType() = STUB_ID override fun bind(holder: Holder) { super.bind(holder) @@ -84,8 +84,7 @@ data class MergedHeaderItem(private val isCollapsed: Boolean, val avatarUrl: String? ) - class Holder : BaseHolder() { - override fun getStubId(): Int = STUB_ID + class Holder : BaseHolder(STUB_ID) { val expandView by bind(R.id.itemMergedExpandTextView) val summaryView by bind(R.id.itemMergedSummaryTextView) @@ -95,6 +94,6 @@ data class MergedHeaderItem(private val isCollapsed: Boolean, } companion object { - private val STUB_ID = R.id.messageContentMergedheaderStub + private const val STUB_ID = R.id.messageContentMergedheaderStub } } \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt index e63881e2..45e57b59 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt @@ -46,19 +46,16 @@ abstract class MessageFileItem : AbsMessageItem() { holder.filenameView.paintFlags = (holder.filenameView.paintFlags or Paint.UNDERLINE_TEXT_FLAG) } - override fun getStubType(): Int = STUB_ID - - class Holder : AbsMessageItem.Holder() { - override fun getStubId(): Int = STUB_ID + override fun getViewType() = STUB_ID + class Holder : AbsMessageItem.Holder(STUB_ID) { val fileLayout by bind(R.id.messageFileLayout) val fileImageView by bind(R.id.messageFileImageView) val filenameView by bind(R.id.messageFilenameView) - } companion object { - private val STUB_ID = R.id.messageContentFileStub + private const val STUB_ID = R.id.messageContentFileStub } } \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageImageVideoItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageImageVideoItem.kt index b3cbaab0..d551e44c 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageImageVideoItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageImageVideoItem.kt @@ -57,23 +57,17 @@ abstract class MessageImageVideoItem : AbsMessageItem(R.id.messageMediaUploadProgressLayout) val imageView by bind(R.id.messageThumbnailView) val playContentView by bind(R.id.messageMediaPlayView) val mediaContentView by bind(R.id.messageContentMedia) - } - companion object { - private val STUB_ID = R.id.messageContentMediaStub + private const val STUB_ID = R.id.messageContentMediaStub } - } \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt index 7b7d3cbf..b5074882 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt @@ -85,12 +85,13 @@ abstract class MessageTextItem : AbsMessageItem() { } } - override fun getStubType(): Int = R.id.messageContentTextStub + override fun getViewType() = STUB_ID - class Holder : AbsMessageItem.Holder() { + class Holder : AbsMessageItem.Holder(STUB_ID) { val messageView by bind(R.id.messageTextView) - override fun getStubId(): Int = R.id.messageContentTextStub - } + companion object { + private const val STUB_ID = R.id.messageContentTextStub + } } \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/NoticeItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/NoticeItem.kt index 08645357..2879073f 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/NoticeItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/NoticeItem.kt @@ -57,10 +57,9 @@ abstract class NoticeItem : BaseEventItem() { holder.view.setOnLongClickListener(longClickListener) } - override fun getStubType(): Int = STUB_ID + override fun getViewType() = STUB_ID - class Holder : BaseHolder() { - override fun getStubId(): Int = STUB_ID + class Holder : BaseHolder(STUB_ID) { val avatarImageView by bind(R.id.itemNoticeAvatarView) val noticeTextView by bind(R.id.itemNoticeTextView) } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/RedactedMessageItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/RedactedMessageItem.kt index f3979c54..88e2be2b 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/RedactedMessageItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/RedactedMessageItem.kt @@ -22,15 +22,13 @@ import im.vector.riotx.R @EpoxyModelClass(layout = R.layout.item_timeline_event_base) abstract class RedactedMessageItem : AbsMessageItem() { - override fun getStubType(): Int = STUB_ID + override fun getViewType() = STUB_ID override fun shouldShowReactionAtBottom() = false - class Holder : AbsMessageItem.Holder() { - override fun getStubId(): Int = STUB_ID - } + class Holder : AbsMessageItem.Holder(STUB_ID) companion object { - private val STUB_ID = R.id.messageContentRedactedStub + private const val STUB_ID = R.id.messageContentRedactedStub } -} \ No newline at end of file +}