Scroll message list to active message

This commit is contained in:
cketti 2022-08-03 21:44:35 +02:00
parent 6992cc732f
commit 8b546cadd6

View file

@ -1563,6 +1563,28 @@ class MessageListFragment :
if (::adapter.isInitialized) {
adapter.activeMessage = activeMessage
adapter.notifyDataSetChanged()
if (messageReference != null) {
scrollToMessage(messageReference)
}
}
}
private fun scrollToMessage(messageReference: MessageReference) {
val position = getPosition(messageReference)
val viewPosition = adapterToListViewPosition(position)
if (viewPosition != AdapterView.INVALID_POSITION &&
(viewPosition <= listView.firstVisiblePosition || viewPosition >= listView.lastVisiblePosition)
) {
listView.smoothScrollToPosition(viewPosition)
}
}
private fun getPosition(messageReference: MessageReference): Int {
return adapter.messages.indexOfFirst { messageListItem ->
messageListItem.account.uuid == messageReference.accountUuid &&
messageListItem.folderId == messageReference.folderId &&
messageListItem.messageUid == messageReference.uid
}
}