From 3f43dc6d5fa8c40df18900a56fcf12cbc7b8d39a Mon Sep 17 00:00:00 2001 From: kosyak Date: Sun, 2 Jun 2024 20:21:34 +0200 Subject: [PATCH] fix conversation position handling while grouping enabled --- .../ui/ConversationsOverviewFragment.java | 11 ++++++++--- .../ui/adapter/ConversationAdapter.java | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java index 2e7f499c6..c36f839e0 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java @@ -140,8 +140,9 @@ public class ConversationsOverviewFragment extends XmppFragment { public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { pendingActionHelper.execute(); int position = viewHolder.getLayoutPosition(); + try { - swipedConversation.push(conversations.get(position)); + swipedConversation.push(conversationsAdapter.getConversation(position)); } catch (IndexOutOfBoundsException e) { return; } @@ -346,7 +347,7 @@ public class ConversationsOverviewFragment extends XmppFragment { if (menuInfo == null) return; int pos = ((AdapterView.AdapterContextMenuInfo) menuInfo).position; if (pos < 0) return; - Conversation conversation = conversations.get(pos); + Conversation conversation = conversationsAdapter.getConversation(pos); if (conversation != null) { if (conversation.getMode() == Conversation.MODE_MULTI) { menuContactDetails.setVisible(false); @@ -379,7 +380,11 @@ public class ConversationsOverviewFragment extends XmppFragment { @Override public boolean onContextItemSelected(MenuItem item) { - Conversation conversation = conversations.get(((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position); + Conversation conversation = conversationsAdapter.getConversation(((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position); + if (conversation == null) { + return false; + } + ConversationFragment fragment = new ConversationFragment(); fragment.setHasOptionsMenu(false); fragment.onAttach(activity); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java index c22546891..db35951e9 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java @@ -197,6 +197,20 @@ public class ConversationAdapter return groupingEnabled; } + @Nullable + public Conversation getConversation(int position) { + if (groupingEnabled) { + Object item = items.get(position); + if (item instanceof Conversation) { + return (Conversation) item; + } else { + return null; + } + } else { + return conversations.get(position); + } + } + public void setGroupingEnabled(boolean groupingEnabled) { if (groupingEnabled != this.groupingEnabled) { this.groupingEnabled = groupingEnabled;