mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-16 12:00:03 +03:00
Timeline : improve scrolling performances
This commit is contained in:
parent
281c25e66d
commit
d288fb7c9c
5 changed files with 24 additions and 16 deletions
|
@ -75,6 +75,8 @@ class RoomDetailFragment : RiotFragment(), TimelineEventController.Callback {
|
|||
//scrollOnNewMessageCallback = ScrollOnNewMessageCallback(layoutManager)
|
||||
recyclerView.layoutManager = layoutManager
|
||||
//timelineEventController.addModelBuildListener { it.dispatchTo(scrollOnNewMessageCallback) }
|
||||
recyclerView.setHasFixedSize(true)
|
||||
recyclerView.setItemViewCacheSize(20)
|
||||
recyclerView.setController(timelineEventController)
|
||||
timelineEventController.callback = this
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package im.vector.riotredesign.features.home.room.detail.timeline
|
||||
|
||||
import android.text.util.Linkify
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import im.vector.matrix.android.api.permalinks.MatrixLinkify
|
||||
import im.vector.matrix.android.api.permalinks.MatrixPermalinkSpan
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.epoxy.KotlinModel
|
||||
import im.vector.riotredesign.features.home.AvatarRenderer
|
||||
|
@ -15,8 +13,7 @@ data class MessageItem(
|
|||
val time: CharSequence? = null,
|
||||
val avatarUrl: String?,
|
||||
val memberName: CharSequence? = null,
|
||||
val showInformation: Boolean = true,
|
||||
val onUrlClickedListener: ((url: String) -> Unit)? = null
|
||||
val showInformation: Boolean = true
|
||||
) : KotlinModel(R.layout.item_event_message) {
|
||||
|
||||
private val avatarImageView by bind<ImageView>(R.id.messageAvatarImageView)
|
||||
|
@ -26,12 +23,7 @@ data class MessageItem(
|
|||
|
||||
override fun bind() {
|
||||
messageView.text = message
|
||||
MatrixLinkify.addLinks(messageView, object : MatrixPermalinkSpan.Callback {
|
||||
override fun onUrlClicked(url: String) {
|
||||
onUrlClickedListener?.invoke(url)
|
||||
}
|
||||
})
|
||||
Linkify.addLinks(messageView, Linkify.ALL)
|
||||
MatrixLinkify.addLinkMovementMethod(messageView)
|
||||
if (showInformation) {
|
||||
avatarImageView.visibility = View.VISIBLE
|
||||
memberNameView.visibility = View.VISIBLE
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package im.vector.riotredesign.features.home.room.detail.timeline
|
||||
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.util.Linkify
|
||||
import im.vector.matrix.android.api.permalinks.MatrixLinkify
|
||||
import im.vector.matrix.android.api.permalinks.MatrixPermalinkSpan
|
||||
import im.vector.matrix.android.api.session.events.model.EnrichedEvent
|
||||
import im.vector.matrix.android.api.session.events.model.toModel
|
||||
import im.vector.matrix.android.api.session.room.model.MessageContent
|
||||
|
@ -25,14 +29,24 @@ class MessageItemFactory(private val timelineDateFormatter: TimelineDateFormatte
|
|||
if (addDaySeparator || nextRoomMember != roomMember) {
|
||||
messagesDisplayedWithInformation.add(event.root.eventId)
|
||||
}
|
||||
|
||||
val message = messageContent.body?.let {
|
||||
val spannable = SpannableStringBuilder(it)
|
||||
MatrixLinkify.addLinks(spannable, object : MatrixPermalinkSpan.Callback {
|
||||
override fun onUrlClicked(url: String) {
|
||||
callback?.onUrlClicked(url)
|
||||
}
|
||||
})
|
||||
Linkify.addLinks(spannable, Linkify.ALL)
|
||||
spannable
|
||||
}
|
||||
val showInformation = messagesDisplayedWithInformation.contains(event.root.eventId)
|
||||
return MessageItem(
|
||||
message = messageContent.body,
|
||||
message = message,
|
||||
avatarUrl = roomMember.avatarUrl,
|
||||
showInformation = showInformation,
|
||||
time = timelineDateFormatter.formatMessageHour(date),
|
||||
memberName = roomMember.displayName ?: event.root.sender,
|
||||
onUrlClickedListener = { callback?.onUrlClicked(it) }
|
||||
memberName = roomMember.displayName ?: event.root.sender
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ object MatrixLinkify {
|
|||
}
|
||||
|
||||
|
||||
private fun addLinkMovementMethod(textView: TextView) {
|
||||
fun addLinkMovementMethod(textView: TextView) {
|
||||
val movementMethod = textView.movementMethod
|
||||
if (movementMethod == null || movementMethod !is LinkMovementMethod) {
|
||||
if (textView.linksClickable) {
|
||||
|
|
|
@ -15,7 +15,7 @@ import im.vector.matrix.android.internal.database.query.where
|
|||
import im.vector.matrix.android.internal.session.room.members.RoomMemberExtractor
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.task.configureWith
|
||||
import im.vector.matrix.android.internal.util.tryTransactionSync
|
||||
import im.vector.matrix.android.internal.util.tryTransactionAsync
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
|
||||
|
@ -55,7 +55,7 @@ internal class DefaultTimelineHolder(private val roomId: String,
|
|||
}
|
||||
|
||||
private fun clearUnlinkedEvents() {
|
||||
monarchy.tryTransactionSync { realm ->
|
||||
monarchy.tryTransactionAsync { realm ->
|
||||
val unlinkedEvents = EventEntity
|
||||
.where(realm, roomId = roomId)
|
||||
.equalTo(EventEntityFields.IS_UNLINKED, true)
|
||||
|
|
Loading…
Add table
Reference in a new issue