forked from GitHub-Mirror/riotX-android
Timeline : scroll to show new message
This commit is contained in:
parent
eda88030a3
commit
0b50ee0974
@ -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
|
||||||
|
}
|
||||||
|
}
|
@ -33,6 +33,7 @@ class RoomDetailFragment : RiotFragment() {
|
|||||||
private val matrix by inject<Matrix>()
|
private val matrix by inject<Matrix>()
|
||||||
private val currentSession = matrix.currentSession
|
private val currentSession = matrix.currentSession
|
||||||
private var roomId by FragmentArgumentDelegate<String>()
|
private var roomId by FragmentArgumentDelegate<String>()
|
||||||
|
|
||||||
private lateinit var timelineEventController: TimelineEventController
|
private lateinit var timelineEventController: TimelineEventController
|
||||||
private lateinit var room: Room
|
private lateinit var room: Room
|
||||||
|
|
||||||
@ -59,8 +60,10 @@ 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)
|
||||||
recyclerView.layoutManager = layoutManager
|
recyclerView.layoutManager = layoutManager
|
||||||
timelineEventController = TimelineEventController(riotActivity)
|
timelineEventController = TimelineEventController(riotActivity)
|
||||||
|
timelineEventController.addModelBuildListener { it.dispatchTo(listUpdateCallback) }
|
||||||
recyclerView.setController(timelineEventController)
|
recyclerView.setController(timelineEventController)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,4 +85,4 @@ class RoomDetailFragment : RiotFragment() {
|
|||||||
timelineEventController.requestModelBuild()
|
timelineEventController.requestModelBuild()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user