Show recent groups in Add to Groups screen.

This commit is contained in:
Cody Henthorne 2020-06-09 12:13:13 -04:00 committed by GitHub
parent dc46d88ddd
commit 2822042eeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 2 deletions

View File

@ -116,6 +116,7 @@ public class ContactsCursorLoader extends CursorLoader {
ArrayList<Cursor> cursorList = new ArrayList<>();
if (groupsOnly(mode)) {
addRecentGroupsSection(cursorList);
addGroupsSection(cursorList);
} else {
addRecentsSection(cursorList);
@ -158,6 +159,19 @@ public class ContactsCursorLoader extends CursorLoader {
}
}
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;
@ -167,7 +181,7 @@ public class ContactsCursorLoader extends CursorLoader {
if (groups.getCount() > 0) {
cursorList.add(getGroupsHeaderCursor());
cursorList.add(getGroupsCursor());
cursorList.add(groups);
}
}
@ -245,10 +259,14 @@ public class ContactsCursorLoader extends CursorLoader {
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) {

View File

@ -442,9 +442,18 @@ public class ThreadDatabase extends Database {
}
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);
}

View File

@ -52,6 +52,7 @@ public final class AddToGroupsActivity extends ContactSelectionActivity {
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);