mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-01 19:56:47 +01:00
Fix scrolling to bottom if it's not far and it wasn't at bottom initially
Change-Id: Ifaf2395140d30b456acd9130bd058ed573888423
This commit is contained in:
parent
6399e71e25
commit
6c9c2eaef5
@ -61,6 +61,11 @@ interface Timeline {
|
||||
*/
|
||||
fun getInitialEventId(): String?
|
||||
|
||||
/**
|
||||
* Change initial event id
|
||||
*/
|
||||
fun setInitialEventId(eventId: String?)
|
||||
|
||||
/**
|
||||
* Check if the timeline can be enriched by paginating.
|
||||
* @param direction the direction to check in
|
||||
|
@ -225,6 +225,10 @@ internal class DefaultTimeline(
|
||||
return initialEventId
|
||||
}
|
||||
|
||||
override fun setInitialEventId(eventId: String?) {
|
||||
initialEventId = eventId
|
||||
}
|
||||
|
||||
override fun getTimelineEventAtIndex(index: Int): TimelineEvent? {
|
||||
return builtEvents.getOrNull(index)
|
||||
}
|
||||
|
@ -796,6 +796,7 @@ class RoomDetailFragment @Inject constructor(
|
||||
scrollOnNewMessageCallback.forceScrollOnNextUpdate()
|
||||
roomDetailViewModel.timeline.restartWithEventId(null)
|
||||
} else {
|
||||
roomDetailViewModel.timeline.setInitialEventId(null)
|
||||
layoutManager.scrollToPosition(0)
|
||||
}
|
||||
}
|
||||
|
@ -54,8 +54,16 @@ class ScrollOnNewMessageCallback(private val layoutManager: LinearLayoutManager,
|
||||
|
||||
override fun onInserted(position: Int, count: Int) {
|
||||
if (initialForceScroll) {
|
||||
timelineEventController.searchPositionOfEvent(initialForceScrollEventId)?.let {
|
||||
layoutManager.scrollToPosition(it)
|
||||
var scrollToEvent = initialForceScrollEventId
|
||||
if (initialForceScrollEventId == null) {
|
||||
scrollToEvent = timelineEventController.timeline?.getInitialEventId()
|
||||
}
|
||||
if (scrollToEvent == null) {
|
||||
layoutManager.scrollToPositionWithOffset(0, 0)
|
||||
} else {
|
||||
timelineEventController.searchPositionOfEvent(scrollToEvent)?.let {
|
||||
layoutManager.scrollToPosition(it)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -64,7 +72,7 @@ class ScrollOnNewMessageCallback(private val layoutManager: LinearLayoutManager,
|
||||
}
|
||||
if (forceScroll) {
|
||||
forceScroll = false
|
||||
layoutManager.scrollToPosition(0)
|
||||
layoutManager.scrollToPositionWithOffset(0, 0)
|
||||
return
|
||||
}
|
||||
if (layoutManager.findFirstVisibleItemPosition() > 1) {
|
||||
@ -79,8 +87,7 @@ class ScrollOnNewMessageCallback(private val layoutManager: LinearLayoutManager,
|
||||
while (newTimelineEventIds.lastOrNull() != firstNewItemIds) {
|
||||
newTimelineEventIds.removeLastOrNull()
|
||||
}
|
||||
//layoutManager.scrollToPosition(0)
|
||||
layoutManager.scrollToPositionWithOffset(0, Integer.MAX_VALUE)
|
||||
layoutManager.scrollToPositionWithOffset(0, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user