From 2822042eeb47695b530b32ff647d8cb6473722aa Mon Sep 17 00:00:00 2001 From: Cody Henthorne Date: Tue, 9 Jun 2020 12:13:13 -0400 Subject: [PATCH] Show recent groups in Add to Groups screen. --- .../contacts/ContactsCursorLoader.java | 22 +++++++++++++++++-- .../securesms/database/ThreadDatabase.java | 9 ++++++++ .../ui/addtogroup/AddToGroupsActivity.java | 1 + 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactsCursorLoader.java b/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactsCursorLoader.java index d7d7bd8aa04..ca374654c71 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactsCursorLoader.java +++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactsCursorLoader.java @@ -116,6 +116,7 @@ private List getUnfilteredResults() { ArrayList cursorList = new ArrayList<>(); if (groupsOnly(mode)) { + addRecentGroupsSection(cursorList); addGroupsSection(cursorList); } else { addRecentsSection(cursorList); @@ -158,6 +159,19 @@ private void addContactsSection(@NonNull List cursorList) { } } + private void addRecentGroupsSection(@NonNull List cursorList) { + if (!groupsEnabled(mode) || !recents) { + return; + } + + Cursor groups = getRecentConversationsCursor(true); + + if (groups.getCount() > 0) { + cursorList.add(getRecentsHeaderCursor()); + cursorList.add(groups); + } + } + private void addGroupsSection(@NonNull List cursorList) { if (!groupsEnabled(mode)) { return; @@ -167,7 +181,7 @@ private void addGroupsSection(@NonNull List cursorList) { if (groups.getCount() > 0) { cursorList.add(getGroupsHeaderCursor()); - cursorList.add(getGroupsCursor()); + cursorList.add(groups); } } @@ -245,10 +259,14 @@ private Cursor getUsernameSearchHeaderCursor() { private Cursor getRecentConversationsCursor() { + return getRecentConversationsCursor(false); + } + + private Cursor getRecentConversationsCursor(boolean groupsOnly) { ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(getContext()); MatrixCursor recentConversations = new MatrixCursor(CONTACT_PROJECTION, RECENT_CONVERSATION_MAX); - try (Cursor rawConversations = threadDatabase.getRecentConversationList(RECENT_CONVERSATION_MAX, flagSet(mode, DisplayMode.FLAG_INACTIVE_GROUPS))) { + try (Cursor rawConversations = threadDatabase.getRecentConversationList(RECENT_CONVERSATION_MAX, flagSet(mode, DisplayMode.FLAG_INACTIVE_GROUPS), groupsOnly)) { ThreadDatabase.Reader reader = threadDatabase.readerFor(rawConversations); ThreadRecord threadRecord; while ((threadRecord = reader.getNext()) != null) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java index c74c64eb775..a62cb98b5f2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -442,9 +442,18 @@ public Cursor getFilteredConversationList(@Nullable List filter) { } public Cursor getRecentConversationList(int limit, boolean includeInactiveGroups) { + return getRecentConversationList(limit, includeInactiveGroups, false); + } + + public Cursor getRecentConversationList(int limit, boolean includeInactiveGroups, boolean groupsOnly) { SQLiteDatabase db = databaseHelper.getReadableDatabase(); String query = !includeInactiveGroups ? MESSAGE_COUNT + " != 0 AND (" + GroupDatabase.TABLE_NAME + "." + GroupDatabase.ACTIVE + " IS NULL OR " + GroupDatabase.TABLE_NAME + "." + GroupDatabase.ACTIVE + " = 1)" : MESSAGE_COUNT + " != 0"; + + if (groupsOnly) { + query += " AND " + RecipientDatabase.TABLE_NAME + "." + RecipientDatabase.GROUP_ID + " NOT NULL"; + } + return db.rawQuery(createQuery(query, limit), null); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/ui/addtogroup/AddToGroupsActivity.java b/app/src/main/java/org/thoughtcrime/securesms/groups/ui/addtogroup/AddToGroupsActivity.java index 8de88a1721c..1203dfde4c1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/ui/addtogroup/AddToGroupsActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/ui/addtogroup/AddToGroupsActivity.java @@ -52,6 +52,7 @@ public static Intent newIntent(@NonNull Context context, intent.putExtra(ContactSelectionListFragment.MULTI_SELECT, false); intent.putExtra(ContactSelectionListFragment.REFRESHABLE, false); + intent.putExtra(ContactSelectionListFragment.RECENTS, true); intent.putExtra(ContactSelectionActivity.EXTRA_LAYOUT_RES_ID, R.layout.add_to_group_activity); intent.putExtra(EXTRA_RECIPIENT_ID, recipientId);