Code cleanup

This commit is contained in:
Benoit Marty 2019-07-12 10:45:08 +02:00
parent bd009caaf1
commit 41465450d8
9 changed files with 29 additions and 53 deletions

View file

@ -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<H : AbsMessageItem.Holder> : BaseEventItem<H>() {
textView?.setTextColor(colorProvider.getMessageTextColor(informationData.sendState))
}
abstract class Holder : BaseHolder() {
abstract class Holder(@IdRes stubId: Int) : BaseHolder(stubId) {
val avatarImageView by bind<ImageView>(R.id.messageAvatarImageView)
val memberNameView by bind<TextView>(R.id.messageMemberNameView)
val timeView by bind<TextView>(R.id.messageTimeView)

View file

@ -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<H : BaseEventItem.BaseHolder> : VectorEpoxyModel<H>() {
var avatarStyle: AvatarStyle = AvatarStyle.SMALL
@ -43,31 +46,18 @@ abstract class BaseEventItem<H : BaseEventItem.BaseHolder> : VectorEpoxyModel<H>
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<Guideline>(R.id.messageStartGuideline)
val checkableBackground by bind<CheckableView>(R.id.messageSelectedBackground)
@IdRes
abstract fun getStubId(): Int
override fun bindView(itemView: View) {
super.bindView(itemView)
inflateStub()
}
private fun inflateStub() {
view.findViewById<ViewStub>(getStubId()).inflate()
view.findViewById<ViewStub>(stubId).inflate()
}
}
companion object {

View file

@ -31,11 +31,9 @@ abstract class DefaultItem : BaseEventItem<DefaultItem.Holder>() {
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<TextView>(R.id.stateMessageView)
}

View file

@ -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<TextView>(R.id.itemMergedExpandTextView)
val summaryView by bind<TextView>(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
}
}

View file

@ -46,19 +46,16 @@ abstract class MessageFileItem : AbsMessageItem<MessageFileItem.Holder>() {
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<ViewGroup>(R.id.messageFileLayout)
val fileImageView by bind<ImageView>(R.id.messageFileImageView)
val filenameView by bind<TextView>(R.id.messageFilenameView)
}
companion object {
private val STUB_ID = R.id.messageContentFileStub
private const val STUB_ID = R.id.messageContentFileStub
}
}

View file

@ -57,23 +57,17 @@ abstract class MessageImageVideoItem : AbsMessageItem<MessageImageVideoItem.Hold
super.unbind(holder)
}
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 progressLayout by bind<ViewGroup>(R.id.messageMediaUploadProgressLayout)
val imageView by bind<ImageView>(R.id.messageThumbnailView)
val playContentView by bind<ImageView>(R.id.messageMediaPlayView)
val mediaContentView by bind<ViewGroup>(R.id.messageContentMedia)
}
companion object {
private val STUB_ID = R.id.messageContentMediaStub
private const val STUB_ID = R.id.messageContentMediaStub
}
}

View file

@ -85,12 +85,13 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
}
}
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<AppCompatTextView>(R.id.messageTextView)
override fun getStubId(): Int = R.id.messageContentTextStub
}
companion object {
private const val STUB_ID = R.id.messageContentTextStub
}
}

View file

@ -57,10 +57,9 @@ abstract class NoticeItem : BaseEventItem<NoticeItem.Holder>() {
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<ImageView>(R.id.itemNoticeAvatarView)
val noticeTextView by bind<TextView>(R.id.itemNoticeTextView)
}

View file

@ -22,15 +22,13 @@ import im.vector.riotx.R
@EpoxyModelClass(layout = R.layout.item_timeline_event_base)
abstract class RedactedMessageItem : AbsMessageItem<RedactedMessageItem.Holder>() {
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
}
}
}