Timeline : scroll to show new message

This commit is contained in:
ganfra 2018-11-02 10:17:37 +01:00
parent eda88030a3
commit 0b50ee0974
3 changed files with 40 additions and 1 deletions

View file

@ -0,0 +1,22 @@
package im.vector.riotredesign.core.platform
import android.support.v7.util.ListUpdateCallback
interface DefaultListUpdateCallback : ListUpdateCallback {
override fun onChanged(position: Int, count: Int, tag: Any?) {
//no-op
}
override fun onMoved(position: Int, count: Int) {
//no-op
}
override fun onInserted(position: Int, count: Int) {
//no-op
}
override fun onRemoved(position: Int, count: Int) {
//no-op
}
}

View file

@ -33,6 +33,7 @@ class RoomDetailFragment : RiotFragment() {
private val matrix by inject<Matrix>()
private val currentSession = matrix.currentSession
private var roomId by FragmentArgumentDelegate<String>()
private lateinit var timelineEventController: TimelineEventController
private lateinit var room: Room
@ -59,8 +60,10 @@ class RoomDetailFragment : RiotFragment() {
private fun setupRecyclerView() {
val layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)
val listUpdateCallback = ScrollOnNewMessageCallback(layoutManager)
recyclerView.layoutManager = layoutManager
timelineEventController = TimelineEventController(riotActivity)
timelineEventController.addModelBuildListener { it.dispatchTo(listUpdateCallback) }
recyclerView.setController(timelineEventController)
}
@ -82,4 +85,4 @@ class RoomDetailFragment : RiotFragment() {
timelineEventController.requestModelBuild()
}
}
}

View file

@ -0,0 +1,14 @@
package im.vector.riotredesign.features.home.room.detail
import android.support.v7.widget.LinearLayoutManager
import im.vector.riotredesign.core.platform.DefaultListUpdateCallback
class ScrollOnNewMessageCallback(private val layoutManager: LinearLayoutManager) : DefaultListUpdateCallback {
override fun onInserted(position: Int, count: Int) {
if (layoutManager.findFirstVisibleItemPosition() == 0) {
layoutManager.scrollToPosition(0)
}
}
}