Timeline : change page size

This commit is contained in:
ganfra 2018-10-31 16:23:02 +01:00
parent 900217b90e
commit 536d7c33fe
2 changed files with 9 additions and 3 deletions

View File

@ -14,6 +14,8 @@ import im.vector.matrix.android.internal.database.query.where
import im.vector.matrix.android.internal.session.events.interceptor.MessageEventInterceptor
import io.realm.Sort
private const val PAGE_SIZE = 30
class DefaultTimelineHolder(private val roomId: String,
private val monarchy: Monarchy,
private val boundaryCallback: TimelineBoundaryCallback
@ -22,6 +24,7 @@ class DefaultTimelineHolder(private val roomId: String,
private val eventInterceptors = ArrayList<EnrichedEventInterceptor>()
init {
boundaryCallback.limit = PAGE_SIZE
eventInterceptors.add(MessageEventInterceptor(monarchy))
}
@ -37,6 +40,7 @@ class DefaultTimelineHolder(private val roomId: String,
val domainSourceFactory = realmDataSourceFactory
.map { it.asDomain() }
.map { event ->
val enrichedEvent = EnrichedEvent(event)
eventInterceptors
.filter {
@ -49,7 +53,7 @@ class DefaultTimelineHolder(private val roomId: String,
val pagedListConfig = PagedList.Config.Builder()
.setEnablePlaceholders(false)
.setPageSize(10)
.setPageSize(PAGE_SIZE)
.setPrefetchDistance(10)
.build()

View File

@ -19,6 +19,8 @@ class TimelineBoundaryCallback(private val roomId: String,
private val helper = PagingRequestHelper(ioExecutor)
var limit = 10
override fun onZeroItemsLoaded() {
// actually, it's not possible
}
@ -30,7 +32,7 @@ class TimelineBoundaryCallback(private val roomId: String,
return@doWithRealm
}
val chunkEntity = ChunkEntity.findAllIncludingEvents(realm, Collections.singletonList(itemAtEnd.root.eventId)).firstOrNull()
paginationRequest.execute(roomId, chunkEntity?.prevToken, PaginationDirection.BACKWARDS, callback = createCallback(it))
paginationRequest.execute(roomId, chunkEntity?.prevToken, PaginationDirection.BACKWARDS, limit, callback = createCallback(it))
}
}
}
@ -42,7 +44,7 @@ class TimelineBoundaryCallback(private val roomId: String,
return@doWithRealm
}
val chunkEntity = ChunkEntity.findAllIncludingEvents(realm, Collections.singletonList(itemAtFront.root.eventId)).firstOrNull()
paginationRequest.execute(roomId, chunkEntity?.nextToken, PaginationDirection.FORWARDS, callback = createCallback(it))
paginationRequest.execute(roomId, chunkEntity?.nextToken, PaginationDirection.FORWARDS, limit, callback = createCallback(it))
}
}
}