0
0
mirror of https://github.com/thunderbird/thunderbird-android.git synced 2024-09-20 20:13:04 +02:00

Ignore page change events to an item that is no longer in the adapter

This commit is contained in:
cketti 2022-10-25 18:10:18 +02:00
parent ed71ad4c30
commit e91e1e49bf

View File

@ -145,20 +145,19 @@ class MessageViewContainerFragment : Fragment() {
}
private fun setActiveMessage(position: Int) {
// If the position of current message changes (e.g. because messages were added or removed from the list), we
// keep track of the new position but otherwise ignore the event.
val newMessageReference = adapter.getMessageReference(position)
val newMessageReference = adapter.getMessageReference(position) ?: return
if (newMessageReference == activeMessageReference) {
// If the position of current message changes (e.g. because messages were added or removed from the list),
// we keep track of the new position but otherwise ignore the event.
currentPosition = position
return
}
rememberNavigationDirection(position)
messageReference = adapter.getMessageReference(position)
activeMessageReference = messageReference
fragmentListener.setActiveMessage(messageReference)
messageReference = newMessageReference
activeMessageReference = newMessageReference
fragmentListener.setActiveMessage(newMessageReference)
}
private fun rememberNavigationDirection(newPosition: Int) {
@ -261,10 +260,8 @@ class MessageViewContainerFragment : Fragment() {
return MessageViewFragment.newInstance(messageReference)
}
fun getMessageReference(position: Int): MessageReference {
check(position in messageList.indices)
return messageList[position].messageReference
fun getMessageReference(position: Int): MessageReference? {
return messageList.getOrNull(position)?.messageReference
}
fun getPosition(messageReference: MessageReference): Int {