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:
parent
ed71ad4c30
commit
e91e1e49bf
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user