Fix timeline non loading when there are lots of filtered events

This commit is contained in:
ganfra 2020-07-28 11:49:45 +02:00
parent 984ffc4fb9
commit 833f64fcec
4 changed files with 18 additions and 11 deletions

View file

@ -169,7 +169,7 @@ internal class DefaultTimeline(
filteredEvents = nonFilteredEvents.where()
.filterEventsWithSettings()
.findAll()
filteredEvents.addChangeListener(eventsChangeListener)
nonFilteredEvents.addChangeListener(eventsChangeListener)
handleInitialLoad()
if (settings.shouldHandleHiddenReadReceipts()) {
hiddenReadReceipts.start(realm, filteredEvents, nonFilteredEvents, this)

View file

@ -16,7 +16,9 @@
package im.vector.riotx.core.epoxy
import android.widget.ProgressBar
import android.widget.TextView
import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.riotx.R
@ -26,14 +28,16 @@ import im.vector.riotx.core.extensions.setTextOrHide
abstract class LoadingItem : VectorEpoxyModel<LoadingItem.Holder>() {
@EpoxyAttribute var loadingText: String? = null
@EpoxyAttribute var showLoader: Boolean = true
override fun bind(holder: Holder) {
super.bind(holder)
holder.progressBar.isVisible = showLoader
holder.textView.setTextOrHide(loadingText)
}
class Holder : VectorEpoxyHolder() {
val textView by bind<TextView>(R.id.loadingText)
val progressBar by bind<ProgressBar>(R.id.loadingProgress)
}
}

View file

@ -74,7 +74,8 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
fun onEncryptedMessageClicked(informationData: MessageInformationData, view: View)
fun onImageMessageClicked(messageImageContent: MessageImageInfoContent, mediaData: ImageContentRenderer.Data, view: View)
fun onVideoMessageClicked(messageVideoContent: MessageVideoContent, mediaData: VideoContentRenderer.Data, view: View)
// fun onFileMessageClicked(eventId: String, messageFileContent: MessageFileContent)
// fun onFileMessageClicked(eventId: String, messageFileContent: MessageFileContent)
// fun onAudioMessageClicked(messageAudioContent: MessageAudioContent)
fun onEditedDecorationClicked(informationData: MessageInformationData)
@ -107,7 +108,6 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
fun onUrlLongClicked(url: String): Boolean
}
private var showingForwardLoader = false
// Map eventId to adapter position
private val adapterPositionMapping = HashMap<String, Int>()
private val modelCache = arrayListOf<CacheItemData?>()
@ -233,7 +233,8 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
override fun buildModels() {
val timestamp = System.currentTimeMillis()
showingForwardLoader = LoadingItem_()
val showingForwardLoader = LoadingItem_()
.id("forward_loading_item_$timestamp")
.setVisibilityStateChangedListener(Timeline.Direction.FORWARDS)
.addWhenLoading(Timeline.Direction.FORWARDS)
@ -242,13 +243,14 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
add(timelineModels)
// Avoid displaying two loaders if there is no elements between them
if (!showingForwardLoader || timelineModels.isNotEmpty()) {
val showBackwardsLoader = !showingForwardLoader || timelineModels.isNotEmpty()
// We can hide the loader but still add the item to controller so it can trigger backwards pagination
LoadingItem_()
.id("backward_loading_item_$timestamp")
.setVisibilityStateChangedListener(Timeline.Direction.BACKWARDS)
.showLoader(showBackwardsLoader)
.addWhenLoading(Timeline.Direction.BACKWARDS)
}
}
// Timeline.LISTENER ***************************************************************************

View file

@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="1dp"
android:background="?riotx_background"
android:orientation="vertical">