BayernMessenger/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomSummaryItem.kt

68 lines
2.8 KiB
Kotlin
Raw Normal View History

2019-01-18 10:12:08 +00:00
/*
* Copyright 2019 New Vector Ltd
2019-01-18 10:12:08 +00:00
*
* 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
2019-01-18 10:12:08 +00:00
*
* 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.
2019-01-18 10:12:08 +00:00
*/
package im.vector.riotx.features.home.room.list
2018-10-19 12:26:38 +00:00
2019-08-28 14:31:29 +00:00
import android.view.View
import android.view.ViewGroup
2018-10-29 16:20:08 +00:00
import android.widget.ImageView
2018-10-19 12:26:38 +00:00
import android.widget.TextView
2019-08-28 14:31:29 +00:00
import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.riotx.R
import im.vector.riotx.core.epoxy.VectorEpoxyHolder
import im.vector.riotx.core.epoxy.VectorEpoxyModel
import im.vector.riotx.features.home.AvatarRenderer
2018-10-19 12:26:38 +00:00
2018-10-29 16:20:08 +00:00
@EpoxyModelClass(layout = R.layout.item_room)
2019-04-05 08:40:59 +00:00
abstract class RoomSummaryItem : VectorEpoxyModel<RoomSummaryItem.Holder>() {
@EpoxyAttribute lateinit var avatarRenderer: AvatarRenderer
@EpoxyAttribute lateinit var roomName: CharSequence
@EpoxyAttribute lateinit var roomId: String
2019-05-17 08:19:19 +00:00
@EpoxyAttribute lateinit var lastFormattedEvent: CharSequence
@EpoxyAttribute lateinit var lastEventTime: CharSequence
@EpoxyAttribute var avatarUrl: String? = null
2019-08-28 14:31:29 +00:00
@EpoxyAttribute var unreadNotificationCount: Int = 0
@EpoxyAttribute var hasUnreadMessage: Boolean = false
@EpoxyAttribute var showHighlighted: Boolean = false
@EpoxyAttribute var listener: (() -> Unit)? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.rootView.setOnClickListener { listener?.invoke() }
holder.titleView.text = roomName
2019-05-17 08:19:19 +00:00
holder.lastEventTimeView.text = lastEventTime
holder.lastEventView.text = lastFormattedEvent
2019-08-28 14:31:29 +00:00
holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted))
holder.unreadIndentIndicator.isVisible = hasUnreadMessage
avatarRenderer.render(avatarUrl, roomId, roomName.toString(), holder.avatarImageView)
2018-10-19 12:26:38 +00:00
}
2019-04-05 08:40:59 +00:00
class Holder : VectorEpoxyHolder() {
val titleView by bind<TextView>(R.id.roomNameView)
2019-05-17 15:07:02 +00:00
val unreadCounterBadgeView by bind<UnreadCounterBadgeView>(R.id.roomUnreadCounterBadgeView)
2019-08-28 14:31:29 +00:00
val unreadIndentIndicator by bind<View>(R.id.roomUnreadIndicator)
2019-05-17 08:19:19 +00:00
val lastEventView by bind<TextView>(R.id.roomLastEventView)
val lastEventTimeView by bind<TextView>(R.id.roomLastEventTimeView)
val avatarImageView by bind<ImageView>(R.id.roomAvatarImageView)
val rootView by bind<ViewGroup>(R.id.itemRoomLayout)
}
2018-10-19 12:26:38 +00:00
}