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() filteredEvents = nonFilteredEvents.where()
.filterEventsWithSettings() .filterEventsWithSettings()
.findAll() .findAll()
filteredEvents.addChangeListener(eventsChangeListener) nonFilteredEvents.addChangeListener(eventsChangeListener)
handleInitialLoad() handleInitialLoad()
if (settings.shouldHandleHiddenReadReceipts()) { if (settings.shouldHandleHiddenReadReceipts()) {
hiddenReadReceipts.start(realm, filteredEvents, nonFilteredEvents, this) hiddenReadReceipts.start(realm, filteredEvents, nonFilteredEvents, this)

View file

@ -16,7 +16,9 @@
package im.vector.riotx.core.epoxy package im.vector.riotx.core.epoxy
import android.widget.ProgressBar
import android.widget.TextView import android.widget.TextView
import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelClass
import im.vector.riotx.R import im.vector.riotx.R
@ -26,14 +28,16 @@ import im.vector.riotx.core.extensions.setTextOrHide
abstract class LoadingItem : VectorEpoxyModel<LoadingItem.Holder>() { abstract class LoadingItem : VectorEpoxyModel<LoadingItem.Holder>() {
@EpoxyAttribute var loadingText: String? = null @EpoxyAttribute var loadingText: String? = null
@EpoxyAttribute var showLoader: Boolean = true
override fun bind(holder: Holder) { override fun bind(holder: Holder) {
super.bind(holder) super.bind(holder)
holder.progressBar.isVisible = showLoader
holder.textView.setTextOrHide(loadingText) holder.textView.setTextOrHide(loadingText)
} }
class Holder : VectorEpoxyHolder() { class Holder : VectorEpoxyHolder() {
val textView by bind<TextView>(R.id.loadingText) 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 onEncryptedMessageClicked(informationData: MessageInformationData, view: View)
fun onImageMessageClicked(messageImageContent: MessageImageInfoContent, mediaData: ImageContentRenderer.Data, view: View) fun onImageMessageClicked(messageImageContent: MessageImageInfoContent, mediaData: ImageContentRenderer.Data, view: View)
fun onVideoMessageClicked(messageVideoContent: MessageVideoContent, mediaData: VideoContentRenderer.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 onAudioMessageClicked(messageAudioContent: MessageAudioContent)
fun onEditedDecorationClicked(informationData: MessageInformationData) fun onEditedDecorationClicked(informationData: MessageInformationData)
@ -107,7 +108,6 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
fun onUrlLongClicked(url: String): Boolean fun onUrlLongClicked(url: String): Boolean
} }
private var showingForwardLoader = false
// Map eventId to adapter position // Map eventId to adapter position
private val adapterPositionMapping = HashMap<String, Int>() private val adapterPositionMapping = HashMap<String, Int>()
private val modelCache = arrayListOf<CacheItemData?>() private val modelCache = arrayListOf<CacheItemData?>()
@ -233,7 +233,8 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
override fun buildModels() { override fun buildModels() {
val timestamp = System.currentTimeMillis() val timestamp = System.currentTimeMillis()
showingForwardLoader = LoadingItem_()
val showingForwardLoader = LoadingItem_()
.id("forward_loading_item_$timestamp") .id("forward_loading_item_$timestamp")
.setVisibilityStateChangedListener(Timeline.Direction.FORWARDS) .setVisibilityStateChangedListener(Timeline.Direction.FORWARDS)
.addWhenLoading(Timeline.Direction.FORWARDS) .addWhenLoading(Timeline.Direction.FORWARDS)
@ -242,12 +243,13 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
add(timelineModels) add(timelineModels)
// Avoid displaying two loaders if there is no elements between them // Avoid displaying two loaders if there is no elements between them
if (!showingForwardLoader || timelineModels.isNotEmpty()) { val showBackwardsLoader = !showingForwardLoader || timelineModels.isNotEmpty()
LoadingItem_() // We can hide the loader but still add the item to controller so it can trigger backwards pagination
.id("backward_loading_item_$timestamp") LoadingItem_()
.setVisibilityStateChangedListener(Timeline.Direction.BACKWARDS) .id("backward_loading_item_$timestamp")
.addWhenLoading(Timeline.Direction.BACKWARDS) .setVisibilityStateChangedListener(Timeline.Direction.BACKWARDS)
} .showLoader(showBackwardsLoader)
.addWhenLoading(Timeline.Direction.BACKWARDS)
} }
// Timeline.LISTENER *************************************************************************** // Timeline.LISTENER ***************************************************************************

View file

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