mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Address issues found in code review
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
package org.briarproject.android.privategroup.conversation;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.view.Menu;
|
||||
@@ -18,11 +19,13 @@ import org.briarproject.api.privategroup.PrivateGroup;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_BODY_LENGTH;
|
||||
|
||||
public class GroupActivity extends
|
||||
ThreadListActivity<PrivateGroup, GroupMessageItem, GroupMessageHeader, GroupMessageAdapter> {
|
||||
|
||||
@Inject
|
||||
protected GroupController controller;
|
||||
GroupController controller;
|
||||
|
||||
@Override
|
||||
public void injectActivity(ActivityComponent component) {
|
||||
@@ -37,23 +40,18 @@ public class GroupActivity extends
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
|
||||
Intent i = getIntent();
|
||||
String groupName = i.getStringExtra(GROUP_NAME);
|
||||
if (groupName != null) setTitle(groupName);
|
||||
loadNamedGroup();
|
||||
|
||||
list.setEmptyText(R.string.groups_no_messages);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @LayoutRes int getLayout() {
|
||||
return R.layout.activity_forum;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setActionBarTitle(@Nullable String title) {
|
||||
if (title != null) setTitle(title);
|
||||
loadGroupItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onGroupItemLoaded(PrivateGroup group) {
|
||||
super.onGroupItemLoaded(group);
|
||||
protected void onNamedGroupLoaded(PrivateGroup group) {
|
||||
setTitle(group.getName());
|
||||
// Created by
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
@@ -62,6 +60,12 @@ public class GroupActivity extends
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@LayoutRes
|
||||
protected int getLayout() {
|
||||
return R.layout.activity_forum;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GroupMessageAdapter createAdapter(
|
||||
LinearLayoutManager layoutManager) {
|
||||
@@ -89,11 +93,18 @@ public class GroupActivity extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxBodyLength() {
|
||||
return MAX_GROUP_POST_BODY_LENGTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
@StringRes
|
||||
protected int getItemPostedString() {
|
||||
return R.string.groups_message_sent;
|
||||
}
|
||||
|
||||
@Override
|
||||
@StringRes
|
||||
protected int getItemReceivedString() {
|
||||
return R.string.groups_message_received;
|
||||
}
|
||||
|
||||
@@ -15,10 +15,11 @@ import org.briarproject.api.privategroup.GroupMessage;
|
||||
import org.briarproject.api.privategroup.GroupMessageHeader;
|
||||
import org.briarproject.api.privategroup.PrivateGroup;
|
||||
import org.briarproject.api.privategroup.PrivateGroupManager;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -47,7 +48,7 @@ public class GroupControllerImpl
|
||||
@Override
|
||||
public void onActivityResume() {
|
||||
super.onActivityResume();
|
||||
notificationManager.clearForumPostNotification(groupId);
|
||||
notificationManager.clearForumPostNotification(getGroupId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,14 +56,14 @@ public class GroupControllerImpl
|
||||
super.eventOccurred(e);
|
||||
|
||||
if (e instanceof GroupMessageAddedEvent) {
|
||||
final GroupMessageAddedEvent pe = (GroupMessageAddedEvent) e;
|
||||
if (!pe.isLocal() && pe.getGroupId().equals(groupId)) {
|
||||
final GroupMessageAddedEvent gmae = (GroupMessageAddedEvent) e;
|
||||
if (!gmae.isLocal() && gmae.getGroupId().equals(getGroupId())) {
|
||||
LOG.info("Group message received, adding...");
|
||||
final GroupMessageHeader fph = pe.getHeader();
|
||||
final GroupMessageHeader h = gmae.getHeader();
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onHeaderReceived(fph);
|
||||
listener.onHeaderReceived(h);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -71,35 +72,39 @@ public class GroupControllerImpl
|
||||
|
||||
@Override
|
||||
protected PrivateGroup loadGroupItem() throws DbException {
|
||||
return privateGroupManager.getPrivateGroup(groupId);
|
||||
return privateGroupManager.getPrivateGroup(getGroupId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<GroupMessageHeader> loadHeaders() throws DbException {
|
||||
return privateGroupManager.getHeaders(groupId);
|
||||
return privateGroupManager.getHeaders(getGroupId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBodies(Collection<GroupMessageHeader> headers)
|
||||
protected Map<MessageId, String> loadBodies(
|
||||
Collection<GroupMessageHeader> headers)
|
||||
throws DbException {
|
||||
Map<MessageId, String> bodies = new HashMap<>();
|
||||
for (GroupMessageHeader header : headers) {
|
||||
if (!bodyCache.containsKey(header.getId())) {
|
||||
String body =
|
||||
privateGroupManager.getMessageBody(header.getId());
|
||||
bodyCache.put(header.getId(), body);
|
||||
bodies.put(header.getId(), body);
|
||||
}
|
||||
}
|
||||
return bodies;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void markRead(MessageId id) throws DbException {
|
||||
privateGroupManager.setReadFlag(groupId, id, true);
|
||||
privateGroupManager.setReadFlag(getGroupId(), id, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GroupMessage createLocalMessage(GroupId g, String body,
|
||||
protected GroupMessage createLocalMessage(String body,
|
||||
@Nullable MessageId parentId) throws DbException {
|
||||
return privateGroupManager.createLocalMessage(groupId, body, parentId);
|
||||
return privateGroupManager
|
||||
.createLocalMessage(getGroupId(), body, parentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,8 +119,9 @@ public class GroupControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GroupMessageItem buildItem(GroupMessageHeader header) {
|
||||
return new GroupMessageItem(header, bodyCache.get(header.getId()));
|
||||
protected GroupMessageItem buildItem(GroupMessageHeader header,
|
||||
String body) {
|
||||
return new GroupMessageItem(header, body);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user