mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-21 17:05:39 +03:00
Timeline : scroll to show new message
This commit is contained in:
parent
eda88030a3
commit
0b50ee0974
3 changed files with 40 additions and 1 deletions
|
@ -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 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()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 a new issue