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

View File

@ -19,6 +19,8 @@ class TimelineBoundaryCallback(private val roomId: String,
private val helper = PagingRequestHelper(ioExecutor) private val helper = PagingRequestHelper(ioExecutor)
var limit = 10
override fun onZeroItemsLoaded() { override fun onZeroItemsLoaded() {
// actually, it's not possible // actually, it's not possible
} }
@ -30,7 +32,7 @@ class TimelineBoundaryCallback(private val roomId: String,
return@doWithRealm return@doWithRealm
} }
val chunkEntity = ChunkEntity.findAllIncludingEvents(realm, Collections.singletonList(itemAtEnd.root.eventId)).firstOrNull() 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 return@doWithRealm
} }
val chunkEntity = ChunkEntity.findAllIncludingEvents(realm, Collections.singletonList(itemAtFront.root.eventId)).firstOrNull() 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))
} }
} }
} }