fix conversation position handling while grouping enabled

This commit is contained in:
kosyak 2024-06-02 20:21:34 +02:00
parent 018120cfe6
commit 3f43dc6d5f
2 changed files with 22 additions and 3 deletions

View file

@ -140,8 +140,9 @@ public class ConversationsOverviewFragment extends XmppFragment {
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
pendingActionHelper.execute(); pendingActionHelper.execute();
int position = viewHolder.getLayoutPosition(); int position = viewHolder.getLayoutPosition();
try { try {
swipedConversation.push(conversations.get(position)); swipedConversation.push(conversationsAdapter.getConversation(position));
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
return; return;
} }
@ -346,7 +347,7 @@ public class ConversationsOverviewFragment extends XmppFragment {
if (menuInfo == null) return; if (menuInfo == null) return;
int pos = ((AdapterView.AdapterContextMenuInfo) menuInfo).position; int pos = ((AdapterView.AdapterContextMenuInfo) menuInfo).position;
if (pos < 0) return; if (pos < 0) return;
Conversation conversation = conversations.get(pos); Conversation conversation = conversationsAdapter.getConversation(pos);
if (conversation != null) { if (conversation != null) {
if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getMode() == Conversation.MODE_MULTI) {
menuContactDetails.setVisible(false); menuContactDetails.setVisible(false);
@ -379,7 +380,11 @@ public class ConversationsOverviewFragment extends XmppFragment {
@Override @Override
public boolean onContextItemSelected(MenuItem item) { 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(); ConversationFragment fragment = new ConversationFragment();
fragment.setHasOptionsMenu(false); fragment.setHasOptionsMenu(false);
fragment.onAttach(activity); fragment.onAttach(activity);

View file

@ -197,6 +197,20 @@ public class ConversationAdapter
return groupingEnabled; 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) { public void setGroupingEnabled(boolean groupingEnabled) {
if (groupingEnabled != this.groupingEnabled) { if (groupingEnabled != this.groupingEnabled) {
this.groupingEnabled = groupingEnabled; this.groupingEnabled = groupingEnabled;