Timeline : try to fix scroll issues...

This commit is contained in:
ganfra 2018-11-25 16:17:13 +01:00
parent 6fc0d884b2
commit e4c23b757e
3 changed files with 10 additions and 7 deletions

View file

@ -40,6 +40,7 @@ class RoomDetailFragment : RiotFragment() {
private var eventId: String? by FragmentArgumentDelegate()
private val timelineEventController by inject<TimelineEventController>(parameters = { ParameterList(roomId) })
private lateinit var room: Room
private lateinit var scrollOnNewMessageCallback: ScrollOnNewMessageCallback
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_room_detail, container, false)
@ -71,9 +72,9 @@ class RoomDetailFragment : RiotFragment() {
private fun setupRecyclerView() {
val layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)
val listUpdateCallback = ScrollOnNewMessageCallback(layoutManager)
scrollOnNewMessageCallback = ScrollOnNewMessageCallback(layoutManager)
recyclerView.layoutManager = layoutManager
timelineEventController.addModelBuildListener { it.dispatchTo(listUpdateCallback) }
timelineEventController.addModelBuildListener { it.dispatchTo(scrollOnNewMessageCallback) }
recyclerView.setController(timelineEventController)
}
@ -91,6 +92,7 @@ class RoomDetailFragment : RiotFragment() {
}
private fun renderEvents(events: PagedList<EnrichedEvent>?) {
scrollOnNewMessageCallback.hasBeenUpdated.set(true)
timelineEventController.timeline = events
}

View file

@ -2,11 +2,14 @@ package im.vector.riotredesign.features.home.room.detail
import android.support.v7.widget.LinearLayoutManager
import im.vector.riotredesign.core.platform.DefaultListUpdateCallback
import java.util.concurrent.atomic.AtomicBoolean
class ScrollOnNewMessageCallback(private val layoutManager: LinearLayoutManager) : DefaultListUpdateCallback {
val hasBeenUpdated = AtomicBoolean(false)
override fun onInserted(position: Int, count: Int) {
if (position == 0 && layoutManager.findFirstVisibleItemPosition() == 0) {
if (hasBeenUpdated.compareAndSet(true, false) && position == 0 && layoutManager.findFirstVisibleItemPosition() == 0) {
layoutManager.scrollToPosition(0)
}
}

View file

@ -16,7 +16,7 @@ import im.vector.matrix.android.internal.session.events.interceptor.MessageEvent
import io.realm.Realm
import io.realm.RealmQuery
private const val PAGE_SIZE = 60
private const val PAGE_SIZE = 30
internal class DefaultTimelineHolder(private val roomId: String,
private val monarchy: Monarchy,
@ -26,7 +26,7 @@ internal class DefaultTimelineHolder(private val roomId: String,
private val eventInterceptors = ArrayList<EnrichedEventInterceptor>()
init {
boundaryCallback.limit = PAGE_SIZE / 2
boundaryCallback.limit = 30
eventInterceptors.add(MessageEventInterceptor(monarchy, roomId))
}
@ -54,8 +54,6 @@ internal class DefaultTimelineHolder(private val roomId: String,
val pagedListConfig = PagedList.Config.Builder()
.setEnablePlaceholders(false)
.setPageSize(PAGE_SIZE)
.setInitialLoadSizeHint(PAGE_SIZE)
.setPrefetchDistance(PAGE_SIZE / 2)
.build()
val livePagedListBuilder = LivePagedListBuilder(domainSourceFactory, pagedListConfig).setBoundaryCallback(boundaryCallback)