mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-08 23:08:33 +00:00
Show recent groups in Add to Groups screen.
This commit is contained in:
parent
dc46d88ddd
commit
2822042eeb
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user