Use new UI/DB interfaces for forums.

This commit is contained in:
akwizgran
2015-12-16 16:24:40 +00:00
parent 412f7b994a
commit f72b3d6294
7 changed files with 47 additions and 38 deletions

View File

@@ -12,7 +12,6 @@ import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.ListLoadingProgressBar; import org.briarproject.android.util.ListLoadingProgressBar;
import org.briarproject.api.contact.Contact; import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.NoSuchSubscriptionException; import org.briarproject.api.db.NoSuchSubscriptionException;
import org.briarproject.api.event.Event; import org.briarproject.api.event.Event;
@@ -21,6 +20,7 @@ import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.RemoteSubscriptionsUpdatedEvent; import org.briarproject.api.event.RemoteSubscriptionsUpdatedEvent;
import org.briarproject.api.event.SubscriptionAddedEvent; import org.briarproject.api.event.SubscriptionAddedEvent;
import org.briarproject.api.event.SubscriptionRemovedEvent; import org.briarproject.api.event.SubscriptionRemovedEvent;
import org.briarproject.api.forum.ForumManager;
import org.briarproject.api.sync.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
@@ -46,7 +46,7 @@ implements EventListener, OnItemClickListener {
private ListLoadingProgressBar loading = null; private ListLoadingProgressBar loading = null;
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject private volatile DatabaseComponent db; @Inject private volatile ForumManager forumManager;
@Inject private volatile EventBus eventBus; @Inject private volatile EventBus eventBus;
@Override @Override
@@ -78,10 +78,11 @@ implements EventListener, OnItemClickListener {
Collection<ForumContacts> available = Collection<ForumContacts> available =
new ArrayList<ForumContacts>(); new ArrayList<ForumContacts>();
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
for (Group g : db.getAvailableGroups()) { for (Group g : forumManager.getAvailableGroups()) {
try { try {
GroupId id = g.getId(); GroupId id = g.getId();
Collection<Contact> c = db.getSubscribers(id); Collection<Contact> c =
forumManager.getSubscribers(id);
available.add(new ForumContacts(g, c)); available.add(new ForumContacts(g, c));
} catch (NoSuchSubscriptionException e) { } catch (NoSuchSubscriptionException e) {
// Continue // Continue
@@ -151,8 +152,8 @@ implements EventListener, OnItemClickListener {
runOnDbThread(new Runnable() { runOnDbThread(new Runnable() {
public void run() { public void run() {
try { try {
db.addGroup(g); forumManager.addGroup(g);
db.setVisibility(g.getId(), visible); forumManager.setVisibility(g.getId(), visible);
} catch (DbException e) { } catch (DbException e) {
if (LOG.isLoggable(WARNING)) if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e); LOG.log(WARNING, e.toString(), e);

View File

@@ -16,8 +16,8 @@ import android.widget.Toast;
import org.briarproject.R; import org.briarproject.R;
import org.briarproject.android.BriarActivity; import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.LayoutUtils; import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.forum.ForumManager;
import org.briarproject.api.sync.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupFactory; import org.briarproject.api.sync.GroupFactory;
import org.briarproject.util.StringUtils; import org.briarproject.util.StringUtils;
@@ -53,7 +53,7 @@ implements OnEditorActionListener, OnClickListener {
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject private volatile GroupFactory groupFactory; @Inject private volatile GroupFactory groupFactory;
@Inject private volatile DatabaseComponent db; @Inject private volatile ForumManager forumManager;
@Override @Override
public void onCreate(Bundle state) { public void onCreate(Bundle state) {
@@ -140,7 +140,7 @@ implements OnEditorActionListener, OnClickListener {
try { try {
Group g = groupFactory.createGroup(name); Group g = groupFactory.createGroup(name);
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
db.addGroup(g); forumManager.addGroup(g);
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Storing forum took " + duration + " ms"); LOG.info("Storing forum took " + duration + " ms");

View File

@@ -18,7 +18,6 @@ import org.briarproject.android.util.ElasticHorizontalSpace;
import org.briarproject.android.util.HorizontalBorder; import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.ListLoadingProgressBar; import org.briarproject.android.util.ListLoadingProgressBar;
import org.briarproject.api.android.AndroidNotificationManager; import org.briarproject.api.android.AndroidNotificationManager;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.NoSuchMessageException; import org.briarproject.api.db.NoSuchMessageException;
import org.briarproject.api.db.NoSuchSubscriptionException; import org.briarproject.api.db.NoSuchSubscriptionException;
@@ -27,6 +26,7 @@ import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener; import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.MessageAddedEvent; import org.briarproject.api.event.MessageAddedEvent;
import org.briarproject.api.event.SubscriptionRemovedEvent; import org.briarproject.api.event.SubscriptionRemovedEvent;
import org.briarproject.api.forum.ForumManager;
import org.briarproject.api.identity.Author; import org.briarproject.api.identity.Author;
import org.briarproject.api.sync.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
@@ -71,7 +71,7 @@ OnClickListener, OnItemClickListener {
private ImageButton composeButton = null, shareButton = null; private ImageButton composeButton = null, shareButton = null;
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject private volatile DatabaseComponent db; @Inject private volatile ForumManager forumManager;
@Inject private volatile EventBus eventBus; @Inject private volatile EventBus eventBus;
private volatile GroupId groupId = null; private volatile GroupId groupId = null;
private volatile Group group = null; private volatile Group group = null;
@@ -152,7 +152,7 @@ OnClickListener, OnItemClickListener {
public void run() { public void run() {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
group = db.getGroup(groupId); group = forumManager.getGroup(groupId);
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Loading group " + duration + " ms"); LOG.info("Loading group " + duration + " ms");
@@ -181,7 +181,7 @@ OnClickListener, OnItemClickListener {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
Collection<MessageHeader> headers = Collection<MessageHeader> headers =
db.getMessageHeaders(groupId); forumManager.getMessageHeaders(groupId);
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Load took " + duration + " ms"); LOG.info("Load took " + duration + " ms");
@@ -228,7 +228,7 @@ OnClickListener, OnItemClickListener {
public void run() { public void run() {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
byte[] body = db.getMessageBody(h.getId()); byte[] body = forumManager.getMessageBody(h.getId());
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Loading message took " + duration + " ms"); LOG.info("Loading message took " + duration + " ms");
@@ -298,7 +298,8 @@ OnClickListener, OnItemClickListener {
public void run() { public void run() {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
for (MessageId m : unread) db.setReadFlag(m, true); for (MessageId m : unread)
forumManager.setReadFlag(m, true);
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Marking read took " + duration + " ms"); LOG.info("Marking read took " + duration + " ms");

View File

@@ -23,7 +23,6 @@ import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.HorizontalBorder; import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.LayoutUtils; import org.briarproject.android.util.LayoutUtils;
import org.briarproject.android.util.ListLoadingProgressBar; import org.briarproject.android.util.ListLoadingProgressBar;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.NoSuchSubscriptionException; import org.briarproject.api.db.NoSuchSubscriptionException;
import org.briarproject.api.event.Event; import org.briarproject.api.event.Event;
@@ -33,6 +32,7 @@ import org.briarproject.api.event.MessageAddedEvent;
import org.briarproject.api.event.RemoteSubscriptionsUpdatedEvent; import org.briarproject.api.event.RemoteSubscriptionsUpdatedEvent;
import org.briarproject.api.event.SubscriptionAddedEvent; import org.briarproject.api.event.SubscriptionAddedEvent;
import org.briarproject.api.event.SubscriptionRemovedEvent; import org.briarproject.api.event.SubscriptionRemovedEvent;
import org.briarproject.api.forum.ForumManager;
import org.briarproject.api.sync.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageHeader; import org.briarproject.api.sync.MessageHeader;
@@ -77,7 +77,7 @@ OnCreateContextMenuListener {
private ImageButton newForumButton = null; private ImageButton newForumButton = null;
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject private volatile DatabaseComponent db; @Inject private volatile ForumManager forumManager;
@Inject private volatile EventBus eventBus; @Inject private volatile EventBus eventBus;
@Override @Override
@@ -153,14 +153,16 @@ OnCreateContextMenuListener {
public void run() { public void run() {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
for (Group g : db.getGroups()) { for (Group g : forumManager.getGroups()) {
try { try {
displayHeaders(g, db.getMessageHeaders(g.getId())); Collection<MessageHeader> headers =
forumManager.getMessageHeaders(g.getId());
displayHeaders(g, headers);
} catch (NoSuchSubscriptionException e) { } catch (NoSuchSubscriptionException e) {
// Continue // Continue
} }
} }
int available = db.getAvailableGroups().size(); int available = forumManager.getAvailableGroups().size();
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Full load took " + duration + " ms"); LOG.info("Full load took " + duration + " ms");
@@ -279,7 +281,7 @@ OnCreateContextMenuListener {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
Collection<MessageHeader> headers = Collection<MessageHeader> headers =
db.getMessageHeaders(g.getId()); forumManager.getMessageHeaders(g.getId());
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Partial load took " + duration + " ms"); LOG.info("Partial load took " + duration + " ms");
@@ -318,7 +320,7 @@ OnCreateContextMenuListener {
public void run() { public void run() {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
int available = db.getAvailableGroups().size(); int available = forumManager.getAvailableGroups().size();
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Loading available took " + duration + " ms"); LOG.info("Loading available took " + duration + " ms");
@@ -373,7 +375,7 @@ OnCreateContextMenuListener {
public void run() { public void run() {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
db.removeGroup(g); forumManager.removeGroup(g);
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Removing group took " + duration + " ms"); LOG.info("Removing group took " + duration + " ms");

View File

@@ -17,9 +17,9 @@ import org.briarproject.android.util.AuthorView;
import org.briarproject.android.util.ElasticHorizontalSpace; import org.briarproject.android.util.ElasticHorizontalSpace;
import org.briarproject.android.util.HorizontalBorder; import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.LayoutUtils; import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.NoSuchMessageException; import org.briarproject.api.db.NoSuchMessageException;
import org.briarproject.api.forum.ForumManager;
import org.briarproject.api.identity.Author; import org.briarproject.api.identity.Author;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId; import org.briarproject.api.sync.MessageId;
@@ -57,7 +57,7 @@ implements OnClickListener {
private int position = -1; private int position = -1;
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject private volatile DatabaseComponent db; @Inject private volatile ForumManager forumManager;
private volatile MessageId messageId = null; private volatile MessageId messageId = null;
@Override @Override
@@ -169,7 +169,7 @@ implements OnClickListener {
public void run() { public void run() {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
db.setReadFlag(messageId, true); forumManager.setReadFlag(messageId, true);
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Marking read took " + duration + " ms"); LOG.info("Marking read took " + duration + " ms");
@@ -186,7 +186,7 @@ implements OnClickListener {
public void run() { public void run() {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
byte[] body = db.getMessageBody(messageId); byte[] body = forumManager.getMessageBody(messageId);
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Loading message took " + duration + " ms"); LOG.info("Loading message took " + duration + " ms");

View File

@@ -17,8 +17,9 @@ import org.briarproject.android.invitation.AddContactActivity;
import org.briarproject.android.util.LayoutUtils; import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.contact.Contact; import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.contact.ContactManager;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.forum.ForumManager;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import java.util.Collection; import java.util.Collection;
@@ -50,7 +51,8 @@ SelectContactsDialog.Listener {
private boolean changed = false; private boolean changed = false;
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject private volatile DatabaseComponent db; @Inject private volatile ContactManager contactManager;
@Inject private volatile ForumManager forumManager;
private volatile GroupId groupId = null; private volatile GroupId groupId = null;
private volatile Collection<Contact> contacts = null; private volatile Collection<Contact> contacts = null;
private volatile Collection<ContactId> selected = null; private volatile Collection<ContactId> selected = null;
@@ -136,8 +138,8 @@ SelectContactsDialog.Listener {
public void run() { public void run() {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
contacts = db.getContacts(); contacts = contactManager.getContacts();
selected = db.getVisibility(groupId); selected = forumManager.getVisibility(groupId);
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Load took " + duration + " ms"); LOG.info("Load took " + duration + " ms");
@@ -173,8 +175,8 @@ SelectContactsDialog.Listener {
public void run() { public void run() {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
db.setVisibleToAll(groupId, all); forumManager.setVisibleToAll(groupId, all);
if (!all) db.setVisibility(groupId, selected); if (!all) forumManager.setVisibility(groupId, selected);
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Update took " + duration + " ms"); LOG.info("Update took " + duration + " ms");

View File

@@ -27,9 +27,10 @@ import org.briarproject.api.crypto.CryptoComponent;
import org.briarproject.api.crypto.CryptoExecutor; import org.briarproject.api.crypto.CryptoExecutor;
import org.briarproject.api.crypto.KeyParser; import org.briarproject.api.crypto.KeyParser;
import org.briarproject.api.crypto.PrivateKey; import org.briarproject.api.crypto.PrivateKey;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.forum.ForumManager;
import org.briarproject.api.identity.AuthorId; import org.briarproject.api.identity.AuthorId;
import org.briarproject.api.identity.IdentityManager;
import org.briarproject.api.identity.LocalAuthor; import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.sync.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
@@ -75,7 +76,8 @@ implements OnItemSelectedListener, OnClickListener {
private GroupId groupId = null; private GroupId groupId = null;
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject private volatile DatabaseComponent db; @Inject private volatile IdentityManager identityManager;
@Inject private volatile ForumManager forumManager;
@Inject private volatile CryptoComponent crypto; @Inject private volatile CryptoComponent crypto;
@Inject private volatile MessageFactory messageFactory; @Inject private volatile MessageFactory messageFactory;
private volatile MessageId parentId = null; private volatile MessageId parentId = null;
@@ -166,8 +168,9 @@ implements OnItemSelectedListener, OnClickListener {
public void run() { public void run() {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
Collection<LocalAuthor> localAuthors = db.getLocalAuthors(); Collection<LocalAuthor> localAuthors =
group = db.getGroup(groupId); identityManager.getLocalAuthors();
group = forumManager.getGroup(groupId);
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Load took " + duration + " ms"); LOG.info("Load took " + duration + " ms");
@@ -292,7 +295,7 @@ implements OnItemSelectedListener, OnClickListener {
public void run() { public void run() {
try { try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
db.addLocalMessage(m); forumManager.addLocalMessage(m);
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Storing message took " + duration + " ms"); LOG.info("Storing message took " + duration + " ms");