diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java index 3a2ee4ec3bc82accf12f3bac52c79439dfefcf1d..415aa08f226bd83395200a7df08928f64735b038 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java @@ -173,7 +173,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio private int mRequestCode = -1; private com.mikepenz.materialdrawer.widget.AccountHeaderView accountHeader; private Bundle savedState = null; - private Tag selectedTag = null; + private HashSet selectedTag = new HashSet<>(); private long mainFilter = DRAWER_ALL_CHATS; private boolean refreshAccounts = true; @@ -445,14 +445,14 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio if (useSavedState != null) { mainFilter = useSavedState.getLong("mainFilter", DRAWER_ALL_CHATS); - selectedTag = (Tag) useSavedState.getSerializable("selectedTag"); + selectedTag = (HashSet) useSavedState.getSerializable("selectedTag"); } refreshUiReal(); if (useSavedState != null) binding.drawer.setSavedInstance(useSavedState); accountHeader.attachToSliderView(binding.drawer); if (useSavedState != null) accountHeader.withSavedInstance(useSavedState); - if (mainFilter == DRAWER_ALL_CHATS && selectedTag == null) { + if (mainFilter == DRAWER_ALL_CHATS && selectedTag.isEmpty()) { binding.drawer.setSelectedItemIdentifier(DRAWER_ALL_CHATS); } @@ -473,11 +473,14 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio } else if (id == DRAWER_START_CHAT_DISCOVER) { launchStartConversation(R.id.discover_public_channels); } else if (id == DRAWER_ALL_CHATS || id == DRAWER_UNREAD_CHATS || id == DRAWER_DIRECT_MESSAGES || id == DRAWER_CHANNELS) { - selectedTag = null; + selectedTag.clear(); mainFilter = id; binding.drawer.getSelectExtension().deselect(); } else if (id >= 1000) { - selectedTag = (Tag) drawerItem.getTag(); + selectedTag.clear(); + selectedTag.add((Tag) drawerItem.getTag()); + binding.drawer.getSelectExtension().deselect(); + binding.drawer.getSelectExtension().select(pos, false, true); } binding.drawer.getSelectExtension().selectByIdentifier(mainFilter, false, true); @@ -494,6 +497,28 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio return false; }); + binding.drawer.setOnDrawerItemLongClickListener((v, drawerItem, pos) -> { + final var id = drawerItem.getIdentifier(); + if (id == DRAWER_ALL_CHATS || id == DRAWER_UNREAD_CHATS || id == DRAWER_DIRECT_MESSAGES || id == DRAWER_CHANNELS) { + selectedTag.clear(); + mainFilter = id; + binding.drawer.getSelectExtension().deselect(); + } else if (id >= 1000) { + final var tag = (Tag) drawerItem.getTag(); + if (selectedTag.contains(tag)) { + selectedTag.remove(tag); + binding.drawer.getSelectExtension().deselect(pos); + } else { + selectedTag.add(tag); + binding.drawer.getSelectExtension().select(pos, false, true); + } + } + binding.drawer.getSelectExtension().selectByIdentifier(mainFilter, false, true); + + refreshUi(); + return true; + }); + accountHeader.setOnAccountHeaderListener((v, profile, isCurrent) -> { final var id = profile.getIdentifier(); if (isCurrent) return false; // Ignore switching to already selected profile @@ -590,8 +615,10 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio list.remove(c); } else if (selectedAccount != null && !selectedAccount.equals(c.getAccount().getUuid())) { list.remove(c); - } else if (selectedTag != null && tagFilter && !c.getTags(this).contains(selectedTag)) { - list.remove(c); + } else if (!selectedTag.isEmpty() && tagFilter) { + final var tags = new HashSet<>(c.getTags(this)); + tags.retainAll(selectedTag); + if (tags.isEmpty()) list.remove(c); } } } @@ -602,7 +629,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio } public void launchStartConversation(int goTo) { - StartConversationActivity.launch(this, (Account) accountHeader.getActiveProfile().getTag(), selectedTag == null ? null : selectedTag.getName(), goTo); + StartConversationActivity.launch(this, (Account) accountHeader.getActiveProfile().getTag(), selectedTag.stream().map(tag -> tag.getName()).collect(Collectors.joining(", ")), goTo); } private boolean performRedirectIfNecessary(boolean noAnimation) {