Skip to content

Commit

Permalink
Show recent groups in Add to Groups screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-signal committed Jun 9, 2020
1 parent dc46d88 commit 2822042
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Expand Up @@ -116,6 +116,7 @@ private List<Cursor> getUnfilteredResults() {
ArrayList<Cursor> cursorList = new ArrayList<>();

if (groupsOnly(mode)) {
addRecentGroupsSection(cursorList);
addGroupsSection(cursorList);
} else {
addRecentsSection(cursorList);
Expand Down Expand Up @@ -158,6 +159,19 @@ private void addContactsSection(@NonNull List<Cursor> cursorList) {
}
}

private void addRecentGroupsSection(@NonNull List<Cursor> 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<Cursor> cursorList) {
if (!groupsEnabled(mode)) {
return;
Expand All @@ -167,7 +181,7 @@ private void addGroupsSection(@NonNull List<Cursor> cursorList) {

if (groups.getCount() > 0) {
cursorList.add(getGroupsHeaderCursor());
cursorList.add(getGroupsCursor());
cursorList.add(groups);
}
}

Expand Down Expand Up @@ -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) {
Expand Down
Expand Up @@ -442,9 +442,18 @@ public Cursor getFilteredConversationList(@Nullable List<RecipientId> 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);
}

Expand Down
Expand Up @@ -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);

Expand Down

0 comments on commit 2822042

Please sign in to comment.