mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 03:16:02 +03:00
Timeline : fix 4959
This commit is contained in:
parent
576931c21a
commit
cc89a8fc77
2 changed files with 15 additions and 2 deletions
1
changelog.d/4959.bugfix
Normal file
1
changelog.d/4959.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Prevent crash in Timeline and add more logs.
|
|
@ -72,6 +72,7 @@ import org.matrix.android.sdk.api.session.room.timeline.Timeline
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import kotlin.math.min
|
||||||
import kotlin.system.measureTimeMillis
|
import kotlin.system.measureTimeMillis
|
||||||
|
|
||||||
class TimelineEventController @Inject constructor(private val dateFormatter: VectorDateFormatter,
|
class TimelineEventController @Inject constructor(private val dateFormatter: VectorDateFormatter,
|
||||||
|
@ -185,6 +186,8 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
|
||||||
override fun onChanged(position: Int, count: Int, payload: Any?) {
|
override fun onChanged(position: Int, count: Int, payload: Any?) {
|
||||||
synchronized(modelCache) {
|
synchronized(modelCache) {
|
||||||
assertUpdateCallbacksAllowed()
|
assertUpdateCallbacksAllowed()
|
||||||
|
Timber.v("listUpdateCallback.onChanged(position: $position, count: $count). " +
|
||||||
|
"\ncurrentSnapshot has size of ${currentSnapshot.size} items")
|
||||||
(position until position + count).forEach {
|
(position until position + count).forEach {
|
||||||
// Invalidate cache
|
// Invalidate cache
|
||||||
modelCache[it] = null
|
modelCache[it] = null
|
||||||
|
@ -192,10 +195,12 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
|
||||||
// Also invalidate the first previous displayable event if
|
// Also invalidate the first previous displayable event if
|
||||||
// it's sent by the same user so we are sure we have up to date information.
|
// it's sent by the same user so we are sure we have up to date information.
|
||||||
val invalidatedSenderId: String? = currentSnapshot.getOrNull(position)?.senderInfo?.userId
|
val invalidatedSenderId: String? = currentSnapshot.getOrNull(position)?.senderInfo?.userId
|
||||||
val prevDisplayableEventIndex = currentSnapshot.subList(0, position).indexOfLast {
|
// In some cases onChanged will be called before onRemoved and onInserted so position will be smaller than currentSnapshot.size.
|
||||||
|
val prevList = currentSnapshot.subList(0, min(position, currentSnapshot.size))
|
||||||
|
val prevDisplayableEventIndex = prevList.indexOfLast {
|
||||||
timelineEventVisibilityHelper.shouldShowEvent(it, partialState.highlightedEventId)
|
timelineEventVisibilityHelper.shouldShowEvent(it, partialState.highlightedEventId)
|
||||||
}
|
}
|
||||||
if (prevDisplayableEventIndex != -1 && currentSnapshot[prevDisplayableEventIndex].senderInfo.userId == invalidatedSenderId) {
|
if (prevDisplayableEventIndex != -1 && currentSnapshot.getOrNull(prevDisplayableEventIndex)?.senderInfo?.userId == invalidatedSenderId) {
|
||||||
modelCache[prevDisplayableEventIndex] = null
|
modelCache[prevDisplayableEventIndex] = null
|
||||||
}
|
}
|
||||||
requestModelBuild()
|
requestModelBuild()
|
||||||
|
@ -205,6 +210,8 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
|
||||||
override fun onMoved(fromPosition: Int, toPosition: Int) {
|
override fun onMoved(fromPosition: Int, toPosition: Int) {
|
||||||
synchronized(modelCache) {
|
synchronized(modelCache) {
|
||||||
assertUpdateCallbacksAllowed()
|
assertUpdateCallbacksAllowed()
|
||||||
|
Timber.v("listUpdateCallback.onMoved(fromPosition: $fromPosition, toPosition: $toPosition). " +
|
||||||
|
"\ncurrentSnapshot has size of ${currentSnapshot.size} items")
|
||||||
val model = modelCache.removeAt(fromPosition)
|
val model = modelCache.removeAt(fromPosition)
|
||||||
modelCache.add(toPosition, model)
|
modelCache.add(toPosition, model)
|
||||||
requestModelBuild()
|
requestModelBuild()
|
||||||
|
@ -214,6 +221,8 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
|
||||||
override fun onInserted(position: Int, count: Int) {
|
override fun onInserted(position: Int, count: Int) {
|
||||||
synchronized(modelCache) {
|
synchronized(modelCache) {
|
||||||
assertUpdateCallbacksAllowed()
|
assertUpdateCallbacksAllowed()
|
||||||
|
Timber.v("listUpdateCallback.onInserted(position: $position, count: $count). " +
|
||||||
|
"\ncurrentSnapshot has size of ${currentSnapshot.size} items")
|
||||||
repeat(count) {
|
repeat(count) {
|
||||||
modelCache.add(position, null)
|
modelCache.add(position, null)
|
||||||
}
|
}
|
||||||
|
@ -224,6 +233,8 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
|
||||||
override fun onRemoved(position: Int, count: Int) {
|
override fun onRemoved(position: Int, count: Int) {
|
||||||
synchronized(modelCache) {
|
synchronized(modelCache) {
|
||||||
assertUpdateCallbacksAllowed()
|
assertUpdateCallbacksAllowed()
|
||||||
|
Timber.v("listUpdateCallback.onRemoved(position: $position, count: $count). " +
|
||||||
|
"\ncurrentSnapshot has size of ${currentSnapshot.size} items")
|
||||||
repeat(count) {
|
repeat(count) {
|
||||||
modelCache.removeAt(position)
|
modelCache.removeAt(position)
|
||||||
}
|
}
|
||||||
|
@ -306,6 +317,7 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
|
||||||
inSubmitList = true
|
inSubmitList = true
|
||||||
val diffCallback = TimelineEventDiffUtilCallback(currentSnapshot, newSnapshot)
|
val diffCallback = TimelineEventDiffUtilCallback(currentSnapshot, newSnapshot)
|
||||||
currentSnapshot = newSnapshot
|
currentSnapshot = newSnapshot
|
||||||
|
Timber.v("Submit a new snapshot of ${currentSnapshot.size} items.")
|
||||||
val diffResult = DiffUtil.calculateDiff(diffCallback)
|
val diffResult = DiffUtil.calculateDiff(diffCallback)
|
||||||
diffResult.dispatchUpdatesTo(listUpdateCallback)
|
diffResult.dispatchUpdatesTo(listUpdateCallback)
|
||||||
requestDelayedModelBuild(0)
|
requestDelayedModelBuild(0)
|
||||||
|
|
Loading…
Reference in a new issue