[android] Show alias for creator of private group in list of private groups

parent a51dc7e0
package org.briarproject.briar.android.privategroup.list; package org.briarproject.briar.android.privategroup.list;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.briar.api.client.MessageTracker.GroupCount; import org.briarproject.briar.api.client.MessageTracker.GroupCount;
...@@ -12,12 +13,15 @@ import org.briarproject.briar.api.privategroup.PrivateGroup; ...@@ -12,12 +13,15 @@ import org.briarproject.briar.api.privategroup.PrivateGroup;
class GroupItem { class GroupItem {
private final PrivateGroup privateGroup; private final PrivateGroup privateGroup;
private final AuthorInfo authorInfo;
private int messageCount, unreadCount; private int messageCount, unreadCount;
private long timestamp; private long timestamp;
private boolean dissolved; private boolean dissolved;
GroupItem(PrivateGroup privateGroup, GroupCount count, boolean dissolved) { GroupItem(PrivateGroup privateGroup, AuthorInfo authorInfo,
GroupCount count, boolean dissolved) {
this.privateGroup = privateGroup; this.privateGroup = privateGroup;
this.authorInfo = authorInfo;
this.messageCount = count.getMsgCount(); this.messageCount = count.getMsgCount();
this.unreadCount = count.getUnreadCount(); this.unreadCount = count.getUnreadCount();
this.timestamp = count.getLatestMsgTime(); this.timestamp = count.getLatestMsgTime();
...@@ -46,6 +50,10 @@ class GroupItem { ...@@ -46,6 +50,10 @@ class GroupItem {
return privateGroup.getCreator(); return privateGroup.getCreator();
} }
AuthorInfo getCreatorInfo() {
return authorInfo;
}
String getName() { String getName() {
return privateGroup.getName(); return privateGroup.getName();
} }
......
...@@ -2,12 +2,15 @@ package org.briarproject.briar.android.privategroup.list; ...@@ -2,12 +2,15 @@ package org.briarproject.briar.android.privategroup.list;
import android.support.annotation.CallSuper; import android.support.annotation.CallSuper;
import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.db.DatabaseExecutor; import org.briarproject.bramble.api.db.DatabaseExecutor;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.NoSuchGroupException; import org.briarproject.bramble.api.db.NoSuchGroupException;
import org.briarproject.bramble.api.event.Event; import org.briarproject.bramble.api.event.Event;
import org.briarproject.bramble.api.event.EventBus; import org.briarproject.bramble.api.event.EventBus;
import org.briarproject.bramble.api.event.EventListener; import org.briarproject.bramble.api.event.EventListener;
import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.lifecycle.LifecycleManager; import org.briarproject.bramble.api.lifecycle.LifecycleManager;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault; import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault; import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
...@@ -30,7 +33,9 @@ import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager ...@@ -30,7 +33,9 @@ import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -52,6 +57,7 @@ class GroupListControllerImpl extends DbControllerImpl ...@@ -52,6 +57,7 @@ class GroupListControllerImpl extends DbControllerImpl
private final PrivateGroupManager groupManager; private final PrivateGroupManager groupManager;
private final GroupInvitationManager groupInvitationManager; private final GroupInvitationManager groupInvitationManager;
private final ContactManager contactManager;
private final AndroidNotificationManager notificationManager; private final AndroidNotificationManager notificationManager;
private final EventBus eventBus; private final EventBus eventBus;
...@@ -61,10 +67,12 @@ class GroupListControllerImpl extends DbControllerImpl ...@@ -61,10 +67,12 @@ class GroupListControllerImpl extends DbControllerImpl
GroupListControllerImpl(@DatabaseExecutor Executor dbExecutor, GroupListControllerImpl(@DatabaseExecutor Executor dbExecutor,
LifecycleManager lifecycleManager, PrivateGroupManager groupManager, LifecycleManager lifecycleManager, PrivateGroupManager groupManager,
GroupInvitationManager groupInvitationManager, GroupInvitationManager groupInvitationManager,
ContactManager contactManager,
AndroidNotificationManager notificationManager, EventBus eventBus) { AndroidNotificationManager notificationManager, EventBus eventBus) {
super(dbExecutor, lifecycleManager); super(dbExecutor, lifecycleManager);
this.groupManager = groupManager; this.groupManager = groupManager;
this.groupInvitationManager = groupInvitationManager; this.groupInvitationManager = groupInvitationManager;
this.contactManager = contactManager;
this.notificationManager = notificationManager; this.notificationManager = notificationManager;
this.eventBus = eventBus; this.eventBus = eventBus;
} }
...@@ -153,12 +161,22 @@ class GroupListControllerImpl extends DbControllerImpl ...@@ -153,12 +161,22 @@ class GroupListControllerImpl extends DbControllerImpl
Collection<PrivateGroup> groups = Collection<PrivateGroup> groups =
groupManager.getPrivateGroups(); groupManager.getPrivateGroups();
List<GroupItem> items = new ArrayList<>(groups.size()); List<GroupItem> items = new ArrayList<>(groups.size());
Map<AuthorId, AuthorInfo> authorInfos = new HashMap<>();
for (PrivateGroup g : groups) { for (PrivateGroup g : groups) {
try { try {
GroupId id = g.getId(); GroupId id = g.getId();
AuthorId authorId = g.getCreator().getId();
AuthorInfo authorInfo;
if (authorInfos.containsKey(authorId)) {
authorInfo = authorInfos.get(authorId);
} else {
authorInfo = contactManager.getAuthorInfo(authorId);
authorInfos.put(authorId, authorInfo);
}
GroupCount count = groupManager.getGroupCount(id); GroupCount count = groupManager.getGroupCount(id);
boolean dissolved = groupManager.isDissolved(id); boolean dissolved = groupManager.isDissolved(id);
items.add(new GroupItem(g, count, dissolved)); items.add(
new GroupItem(g, authorInfo, count, dissolved));
} catch (NoSuchGroupException e) { } catch (NoSuchGroupException e) {
// Continue // Continue
} }
......
...@@ -20,6 +20,7 @@ import static android.view.View.GONE; ...@@ -20,6 +20,7 @@ import static android.view.View.GONE;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID; import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_NAME; import static org.briarproject.briar.android.activity.BriarActivity.GROUP_NAME;
import static org.briarproject.briar.android.util.UiUtils.getContactDisplayName;
@MethodsNotNullByDefault @MethodsNotNullByDefault
@ParametersNotNullByDefault @ParametersNotNullByDefault
...@@ -60,8 +61,9 @@ class GroupViewHolder extends RecyclerView.ViewHolder { ...@@ -60,8 +61,9 @@ class GroupViewHolder extends RecyclerView.ViewHolder {
name.setText(group.getName()); name.setText(group.getName());
// Creator // Creator
creator.setText(ctx.getString(R.string.groups_created_by, String creatorName = getContactDisplayName(group.getCreator(),
group.getCreator().getName())); group.getCreatorInfo().getAlias());
creator.setText(ctx.getString(R.string.groups_created_by, creatorName));
if (!group.isDissolved()) { if (!group.isDissolved()) {
// full visibility // full visibility
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment