From 4971abab5fb12c436c4386a480dbf9615156f320 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 30 Sep 2024 09:45:09 -0500 Subject: [PATCH] Show only unread chats option --- .../res/drawable/chat_unread_24dp.xml | 10 +++++ .../ui/ConversationsActivity.java | 37 ++++++++++++------- 2 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 src/cheogram/res/drawable/chat_unread_24dp.xml diff --git a/src/cheogram/res/drawable/chat_unread_24dp.xml b/src/cheogram/res/drawable/chat_unread_24dp.xml new file mode 100644 index 0000000000000000000000000000000000000000..bff199eff17be408a7eaac3e8276851294fbd269 --- /dev/null +++ b/src/cheogram/res/drawable/chat_unread_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java index cbd51b49995dce4a4358a29334626b29de7af3bd..c018a3460b12795a8ba4f4ce56bad3e11bbe9dd6 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java @@ -146,17 +146,18 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio public static final int REQUEST_DOWNLOAD_STICKERS = 0xbf8702; public static final long DRAWER_ALL_CHATS = 1; - public static final long DRAWER_DIRECT_MESSAGES = 2; - public static final long DRAWER_MANAGE_ACCOUNT = 3; - public static final long DRAWER_MANAGE_PHONE_ACCOUNTS = 4; - public static final long DRAWER_CHANNELS = 5; - public static final long DRAWER_SETTINGS = 6; - public static final long DRAWER_START_CHAT = 7; - public static final long DRAWER_START_CHAT_CONTACT = 8; - public static final long DRAWER_START_CHAT_NEW = 9; - public static final long DRAWER_START_CHAT_GROUP = 10; - public static final long DRAWER_START_CHAT_PUBLIC = 11; - public static final long DRAWER_START_CHAT_DISCOVER = 12; + public static final long DRAWER_UNREAD_CHATS = 2; + public static final long DRAWER_DIRECT_MESSAGES = 3; + public static final long DRAWER_MANAGE_ACCOUNT = 4; + public static final long DRAWER_MANAGE_PHONE_ACCOUNTS = 5; + public static final long DRAWER_CHANNELS = 6; + public static final long DRAWER_SETTINGS = 7; + public static final long DRAWER_START_CHAT = 8; + public static final long DRAWER_START_CHAT_CONTACT = 9; + public static final long DRAWER_START_CHAT_NEW = 10; + public static final long DRAWER_START_CHAT_GROUP = 11; + public static final long DRAWER_START_CHAT_PUBLIC = 12; + public static final long DRAWER_START_CHAT_DISCOVER = 13; //secondary fragment (when holding the conversation, must be initialized before refreshing the overview fragment private static final @IdRes @@ -296,11 +297,11 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio final var color = MaterialColors.getColor(binding.drawer, com.google.android.material.R.attr.colorPrimaryContainer); final var textColor = MaterialColors.getColor(binding.drawer, com.google.android.material.R.attr.colorOnPrimaryContainer); item.setBadgeStyle(new com.mikepenz.materialdrawer.holder.BadgeStyle(com.mikepenz.materialdrawer.R.drawable.material_drawer_badge, color, color, textColor)); - binding.drawer.getItemAdapter().add(binding.drawer.getItemAdapter().getGlobalPosition(4), item); + binding.drawer.getItemAdapter().add(binding.drawer.getItemAdapter().getGlobalPosition(5), item); } } - items.subList(4, 4 + tags.size()).sort((x, y) -> x.getTag() == null ? -1 : ((Comparable) x.getTag()).compareTo(y.getTag())); + items.subList(5, 5 + tags.size()).sort((x, y) -> x.getTag() == null ? -1 : ((Comparable) x.getTag()).compareTo(y.getTag())); binding.drawer.getItemAdapter().getFastAdapter().notifyDataSetChanged(); return kotlin.Unit.INSTANCE; }); @@ -359,6 +360,11 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio com.mikepenz.materialdrawer.model.interfaces.NameableKt.setNameText(allChats, "All Chats"); com.mikepenz.materialdrawer.model.interfaces.IconableKt.setIconRes(allChats, R.drawable.ic_chat_24dp); + final var unreadChats = new com.mikepenz.materialdrawer.model.PrimaryDrawerItem(); + unreadChats.setIdentifier(DRAWER_UNREAD_CHATS); + com.mikepenz.materialdrawer.model.interfaces.NameableKt.setNameText(unreadChats, "Unread Chats"); + com.mikepenz.materialdrawer.model.interfaces.IconableKt.setIconRes(unreadChats, R.drawable.chat_unread_24dp); + final var directMessages = new com.mikepenz.materialdrawer.model.PrimaryDrawerItem(); directMessages.setIdentifier(DRAWER_DIRECT_MESSAGES); com.mikepenz.materialdrawer.model.interfaces.NameableKt.setNameText(directMessages, "Direct Messages"); @@ -371,6 +377,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio binding.drawer.getItemAdapter().add( allChats, + unreadChats, directMessages, channels, new com.mikepenz.materialdrawer.model.DividerDrawerItem() @@ -412,7 +419,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio launchStartConversation(R.id.create_public_channel); } else if (id == DRAWER_START_CHAT_DISCOVER) { launchStartConversation(R.id.discover_public_channels); - } else if (id == DRAWER_ALL_CHATS || id == DRAWER_DIRECT_MESSAGES || id == DRAWER_CHANNELS) { + } else if (id == DRAWER_ALL_CHATS || id == DRAWER_UNREAD_CHATS || id == DRAWER_DIRECT_MESSAGES || id == DRAWER_CHANNELS) { selectedTag = null; mainFilter = id; binding.drawer.getSelectExtension().deselect(); @@ -526,6 +533,8 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio list.remove(c); } else if (mainFilter == DRAWER_DIRECT_MESSAGES && c.getMode() == Conversation.MODE_MULTI) { list.remove(c); + } else if (mainFilter == DRAWER_UNREAD_CHATS && c.unreadCount() < 1) { + 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)) {