mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 03:48:12 +03:00
Timeline : try to fix scroll issues...
This commit is contained in:
parent
6fc0d884b2
commit
e4c23b757e
3 changed files with 10 additions and 7 deletions
|
@ -40,6 +40,7 @@ class RoomDetailFragment : RiotFragment() {
|
||||||
private var eventId: String? by FragmentArgumentDelegate()
|
private var eventId: String? by FragmentArgumentDelegate()
|
||||||
private val timelineEventController by inject<TimelineEventController>(parameters = { ParameterList(roomId) })
|
private val timelineEventController by inject<TimelineEventController>(parameters = { ParameterList(roomId) })
|
||||||
private lateinit var room: Room
|
private lateinit var room: Room
|
||||||
|
private lateinit var scrollOnNewMessageCallback: ScrollOnNewMessageCallback
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
return inflater.inflate(R.layout.fragment_room_detail, container, false)
|
return inflater.inflate(R.layout.fragment_room_detail, container, false)
|
||||||
|
@ -71,9 +72,9 @@ class RoomDetailFragment : RiotFragment() {
|
||||||
|
|
||||||
private fun setupRecyclerView() {
|
private fun setupRecyclerView() {
|
||||||
val layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)
|
val layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)
|
||||||
val listUpdateCallback = ScrollOnNewMessageCallback(layoutManager)
|
scrollOnNewMessageCallback = ScrollOnNewMessageCallback(layoutManager)
|
||||||
recyclerView.layoutManager = layoutManager
|
recyclerView.layoutManager = layoutManager
|
||||||
timelineEventController.addModelBuildListener { it.dispatchTo(listUpdateCallback) }
|
timelineEventController.addModelBuildListener { it.dispatchTo(scrollOnNewMessageCallback) }
|
||||||
recyclerView.setController(timelineEventController)
|
recyclerView.setController(timelineEventController)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +92,7 @@ class RoomDetailFragment : RiotFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderEvents(events: PagedList<EnrichedEvent>?) {
|
private fun renderEvents(events: PagedList<EnrichedEvent>?) {
|
||||||
|
scrollOnNewMessageCallback.hasBeenUpdated.set(true)
|
||||||
timelineEventController.timeline = events
|
timelineEventController.timeline = events
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,14 @@ package im.vector.riotredesign.features.home.room.detail
|
||||||
|
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
import im.vector.riotredesign.core.platform.DefaultListUpdateCallback
|
import im.vector.riotredesign.core.platform.DefaultListUpdateCallback
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
class ScrollOnNewMessageCallback(private val layoutManager: LinearLayoutManager) : DefaultListUpdateCallback {
|
class ScrollOnNewMessageCallback(private val layoutManager: LinearLayoutManager) : DefaultListUpdateCallback {
|
||||||
|
|
||||||
|
val hasBeenUpdated = AtomicBoolean(false)
|
||||||
|
|
||||||
override fun onInserted(position: Int, count: Int) {
|
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)
|
layoutManager.scrollToPosition(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ import im.vector.matrix.android.internal.session.events.interceptor.MessageEvent
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import io.realm.RealmQuery
|
import io.realm.RealmQuery
|
||||||
|
|
||||||
private const val PAGE_SIZE = 60
|
private const val PAGE_SIZE = 30
|
||||||
|
|
||||||
internal class DefaultTimelineHolder(private val roomId: String,
|
internal class DefaultTimelineHolder(private val roomId: String,
|
||||||
private val monarchy: Monarchy,
|
private val monarchy: Monarchy,
|
||||||
|
@ -26,7 +26,7 @@ internal class DefaultTimelineHolder(private val roomId: String,
|
||||||
private val eventInterceptors = ArrayList<EnrichedEventInterceptor>()
|
private val eventInterceptors = ArrayList<EnrichedEventInterceptor>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
boundaryCallback.limit = PAGE_SIZE / 2
|
boundaryCallback.limit = 30
|
||||||
eventInterceptors.add(MessageEventInterceptor(monarchy, roomId))
|
eventInterceptors.add(MessageEventInterceptor(monarchy, roomId))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,8 +54,6 @@ internal class DefaultTimelineHolder(private val roomId: String,
|
||||||
val pagedListConfig = PagedList.Config.Builder()
|
val pagedListConfig = PagedList.Config.Builder()
|
||||||
.setEnablePlaceholders(false)
|
.setEnablePlaceholders(false)
|
||||||
.setPageSize(PAGE_SIZE)
|
.setPageSize(PAGE_SIZE)
|
||||||
.setInitialLoadSizeHint(PAGE_SIZE)
|
|
||||||
.setPrefetchDistance(PAGE_SIZE / 2)
|
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val livePagedListBuilder = LivePagedListBuilder(domainSourceFactory, pagedListConfig).setBoundaryCallback(boundaryCallback)
|
val livePagedListBuilder = LivePagedListBuilder(domainSourceFactory, pagedListConfig).setBoundaryCallback(boundaryCallback)
|
||||||
|
|
Loading…
Reference in a new issue