Commit 32be148c authored by akwizgran's avatar akwizgran

Merge branch '646-shared-with-subtitle-groups' into 'master'

Add sharing information to private group ActionBar subtitle

![device-2016-12-12-114533](/uploads/b31fc37643ef6e817a80a4ddd767fe98/device-2016-12-12-114533.png)

Closes #646

See merge request !455
parents 78000375 45b50402
......@@ -6,7 +6,6 @@ import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.StringRes;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.view.Menu;
......@@ -14,6 +13,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.LocalAuthor;
......@@ -124,12 +124,6 @@ public class GroupActivity extends
@Override
protected void onNamedGroupLoaded(final PrivateGroup group) {
setTitle(group.getName());
// Created by
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setSubtitle(getString(R.string.groups_created_by,
group.getCreator().getName()));
}
controller.loadLocalAuthor(
new UiResultExceptionHandler<LocalAuthor, DbException>(this) {
@Override
......@@ -287,8 +281,13 @@ public class GroupActivity extends
}
@Override
public void onContactRelationshipRevealed(AuthorId memberId, Visibility v) {
public void onContactRelationshipRevealed(AuthorId memberId, ContactId c,
Visibility v) {
adapter.updateVisibility(memberId, v);
sharingController.add(c);
setToolbarSubTitle(sharingController.getTotalCount(),
sharingController.getOnlineCount());
}
@Override
......
......@@ -2,6 +2,7 @@ package org.briarproject.briar.android.privategroup.conversation;
import android.support.annotation.UiThread;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.LocalAuthor;
......@@ -23,7 +24,8 @@ public interface GroupController
interface GroupListener extends ThreadListListener<GroupMessageHeader> {
@UiThread
void onContactRelationshipRevealed(AuthorId memberId, Visibility v);
void onContactRelationshipRevealed(AuthorId memberId,
ContactId contactId, Visibility v);
@UiThread
void onGroupDissolved();
......
......@@ -18,6 +18,7 @@ import org.briarproject.briar.android.privategroup.conversation.GroupController.
import org.briarproject.briar.android.threaded.ThreadListControllerImpl;
import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
import org.briarproject.briar.api.privategroup.GroupMember;
import org.briarproject.briar.api.privategroup.GroupMessage;
import org.briarproject.briar.api.privategroup.GroupMessageFactory;
import org.briarproject.briar.api.privategroup.GroupMessageHeader;
......@@ -26,8 +27,11 @@ import org.briarproject.briar.api.privategroup.PrivateGroup;
import org.briarproject.briar.api.privategroup.PrivateGroupManager;
import org.briarproject.briar.api.privategroup.event.ContactRelationshipRevealedEvent;
import org.briarproject.briar.api.privategroup.event.GroupDissolvedEvent;
import org.briarproject.briar.api.privategroup.event.GroupInvitationResponseReceivedEvent;
import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent;
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
......@@ -93,7 +97,20 @@ class GroupControllerImpl extends
@Override
public void run() {
listener.onContactRelationshipRevealed(c.getMemberId(),
c.getVisibility());
c.getContactId(), c.getVisibility());
}
});
}
} else if (e instanceof GroupInvitationResponseReceivedEvent) {
GroupInvitationResponseReceivedEvent g =
(GroupInvitationResponseReceivedEvent) e;
final GroupInvitationResponse r =
(GroupInvitationResponse) g.getResponse();
if (getGroupId().equals(r.getGroupId()) && r.wasAccepted()) {
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
@Override
public void run() {
listener.onInvitationAccepted(r.getContactId());
}
});
}
......@@ -137,8 +154,26 @@ class GroupControllerImpl extends
@Override
public void loadSharingContacts(
ResultExceptionHandler<Collection<ContactId>, DbException> handler) {
// TODO
final ResultExceptionHandler<Collection<ContactId>, DbException> handler) {
runOnDbThread(new Runnable() {
@Override
public void run() {
try {
Collection<GroupMember> members =
privateGroupManager.getMembers(getGroupId());
Collection<ContactId> contactIds = new ArrayList<>();
for (GroupMember m : members) {
if (m.getContactId() != null)
contactIds.add(m.getContactId());
}
handler.onResult(contactIds);
} catch (DbException e) {
if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);
handler.onException(e);
}
}
});
}
@Override
......
package org.briarproject.briar.api.privategroup.event;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.event.Event;
import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
......@@ -14,12 +15,14 @@ public class ContactRelationshipRevealedEvent extends Event {
private final GroupId groupId;
private final AuthorId memberId;
private final ContactId contactId;
private final Visibility visibility;
public ContactRelationshipRevealedEvent(GroupId groupId, AuthorId memberId,
Visibility visibility) {
ContactId contactId, Visibility visibility) {
this.groupId = groupId;
this.memberId = memberId;
this.contactId = contactId;
this.visibility = visibility;
}
......@@ -31,6 +34,10 @@ public class ContactRelationshipRevealedEvent extends Event {
return memberId;
}
public ContactId getContactId() {
return contactId;
}
public Visibility getVisibility() {
return visibility;
}
......
......@@ -402,7 +402,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
try {
Collection<GroupMember> members = new ArrayList<GroupMember>();
Map<Author, Visibility> authors = getMembers(txn, g);
LocalAuthor la = identityManager.getLocalAuthor();
LocalAuthor la = identityManager.getLocalAuthor(txn);
PrivateGroup privateGroup = getPrivateGroup(txn, g);
for (Entry<Author, Visibility> m : authors.entrySet()) {
Author a = m.getKey();
......@@ -488,7 +488,10 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
if (!foundMember) throw new ProtocolStateException();
if (changed) {
clientHelper.mergeGroupMetadata(txn, g, meta);
txn.attach(new ContactRelationshipRevealedEvent(g, a, v));
LocalAuthor la = identityManager.getLocalAuthor(txn);
ContactId c = contactManager.getContact(txn, a, la.getId()).getId();
Event e = new ContactRelationshipRevealedEvent(g, a, c, v);
txn.attach(e);
}
}
......
......@@ -255,7 +255,7 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
GroupInvitationMessage m, ContactId c, boolean accept) {
SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes());
return new GroupInvitationResponse(m.getId(), sessionId,
m.getContactGroupId(), c, accept, m.getTimestamp(), false,
m.getPrivateGroupId(), c, accept, m.getTimestamp(), false,
false, true, false);
}
}
......@@ -380,11 +380,11 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
messages.add(parseInvitationRequest(txn, c, contactGroupId,
m, meta, status));
} else if (type == JOIN) {
messages.add(parseInvitationResponse(c, contactGroupId, m,
meta, status, true));
messages.add(
parseInvitationResponse(c, m, meta, status, true));
} else if (type == LEAVE) {
messages.add(parseInvitationResponse(c, contactGroupId, m,
meta, status, false));
messages.add(
parseInvitationResponse(c, m, meta, status, false));
}
}
db.commitTransaction(txn);
......@@ -418,13 +418,13 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
}
private GroupInvitationResponse parseInvitationResponse(ContactId c,
GroupId contactGroupId, MessageId m, MessageMetadata meta,
MessageStatus status, boolean accept)
throws DbException, FormatException {
MessageId m, MessageMetadata meta, MessageStatus status,
boolean accept) throws DbException, FormatException {
SessionId sessionId = getSessionId(meta.getPrivateGroupId());
return new GroupInvitationResponse(m, sessionId, contactGroupId, c,
accept, meta.getTimestamp(), meta.isLocal(), status.isSent(),
status.isSeen(), meta.isRead());
return new GroupInvitationResponse(m, sessionId,
meta.getPrivateGroupId(), c, accept, meta.getTimestamp(),
meta.isLocal(), status.isSent(), status.isSeen(),
meta.isRead());
}
@Override
......
......@@ -441,6 +441,9 @@ public class PrivateGroupManagerIntegrationTest
Collection<GroupMember> members2 = groupManager2.getMembers(groupId0);
assertEquals(3, members2.size());
// 1 and 2 add each other
addContacts1And2();
// assert that contact relationship is not revealed initially
for (GroupMember m : members1) {
if (m.getAuthor().equals(author2)) {
......
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