Use Inheritence for shared Forum and Blog Sharing Code

This commit is contained in:
Torsten Grote
2016-08-03 13:00:24 -03:00
parent a3b2358164
commit a4cf91fba5
29 changed files with 755 additions and 466 deletions

View File

@@ -34,15 +34,11 @@ import org.briarproject.api.event.ContactStatusChangedEvent;
import org.briarproject.api.event.Event;
import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.ForumInvitationReceivedEvent;
import org.briarproject.api.event.ForumInvitationResponseReceivedEvent;
import org.briarproject.api.event.IntroductionRequestReceivedEvent;
import org.briarproject.api.event.IntroductionResponseReceivedEvent;
import org.briarproject.api.event.InvitationReceivedEvent;
import org.briarproject.api.event.InvitationResponseReceivedEvent;
import org.briarproject.api.event.PrivateMessageReceivedEvent;
import org.briarproject.api.forum.ForumInvitationRequest;
import org.briarproject.api.forum.ForumInvitationResponse;
import org.briarproject.api.forum.ForumSharingManager;
import org.briarproject.api.identity.IdentityManager;
import org.briarproject.api.identity.LocalAuthor;
@@ -409,15 +405,19 @@ public class ContactListFragment extends BaseFragment implements EventListener {
LOG.info("Loading introduction messages took " + duration + " ms");
now = System.currentTimeMillis();
Collection<InvitationMessage> invitations =
Collection<InvitationMessage> forumInvitations =
forumSharingManager.getInvitationMessages(id);
invitations.addAll(blogSharingManager.getInvitationMessages(id));
for (InvitationMessage i : invitations) {
for (InvitationMessage i : forumInvitations) {
messages.add(ConversationItem.from(i));
}
Collection<InvitationMessage> blogInvitations =
blogSharingManager.getInvitationMessages(id);
for (InvitationMessage i : blogInvitations) {
messages.add(ConversationItem.from(i));
}
duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Loading forum invitations took " + duration + " ms");
LOG.info("Loading invitations took " + duration + " ms");
return messages;
}

View File

@@ -337,11 +337,16 @@ public class ConversationActivity extends BriarActivity
Collection<IntroductionMessage> introductions =
introductionManager
.getIntroductionMessages(contactId);
Collection<InvitationMessage> invitations =
Collection<InvitationMessage> forumInvitations =
forumSharingManager
.getInvitationMessages(contactId);
invitations.addAll(blogSharingManager
.getInvitationMessages(contactId));
Collection<InvitationMessage> blogInvitations =
blogSharingManager
.getInvitationMessages(contactId);
List<InvitationMessage> invitations = new ArrayList<>(
forumInvitations.size() + blogInvitations.size());
invitations.addAll(forumInvitations);
invitations.addAll(blogInvitations);
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Loading headers took " + duration + " ms");

View File

@@ -13,7 +13,8 @@ import android.widget.ImageView;
import android.widget.TextView;
import org.briarproject.R;
import org.briarproject.android.sharing.InvitationsActivity;
import org.briarproject.android.sharing.InvitationsBlogActivity;
import org.briarproject.android.sharing.InvitationsForumActivity;
import org.briarproject.android.util.AndroidUtils;
import org.briarproject.api.blogs.BlogInvitationRequest;
import org.briarproject.api.clients.SessionId;
@@ -42,9 +43,6 @@ import static org.briarproject.android.contact.ConversationItem.MSG_OUT;
import static org.briarproject.android.contact.ConversationItem.NOTICE_IN;
import static org.briarproject.android.contact.ConversationItem.NOTICE_OUT;
import static org.briarproject.android.contact.ConversationItem.OutgoingItem;
import static org.briarproject.android.sharing.ShareActivity.BLOG;
import static org.briarproject.android.sharing.ShareActivity.FORUM;
import static org.briarproject.android.sharing.ShareActivity.SHAREABLE;
class ConversationAdapter extends RecyclerView.Adapter {
@@ -86,7 +84,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
return new IntroductionHolder(v, type);
} else if (type == INTRODUCTION_OUT) {
v = LayoutInflater.from(viewGroup.getContext()).inflate(
R.layout.list_item_introduction_out, viewGroup, false);
R.layout.list_item_msg_notice_out, viewGroup, false);
return new IntroductionHolder(v, type);
} else if (type == NOTICE_IN) {
v = LayoutInflater.from(viewGroup.getContext()).inflate(
@@ -104,7 +102,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
} else if (type == FORUM_INVITATION_OUT ||
type == BLOG_INVITATION_OUT) {
v = LayoutInflater.from(viewGroup.getContext()).inflate(
R.layout.list_item_introduction_out, viewGroup, false);
R.layout.list_item_msg_notice_out, viewGroup, false);
return new InvitationHolder(v, type);
}
// incoming message (non-local)
@@ -338,17 +336,16 @@ class ConversationAdapter extends RecyclerView.Adapter {
ui.text.setText(ctx.getString(receivedRes, contactName, name));
if (ir.isAvailable()) {
final int type =
ir instanceof ForumInvitationRequest ? FORUM : BLOG;
final Class c = ir instanceof ForumInvitationRequest ?
InvitationsForumActivity.class :
InvitationsBlogActivity.class;
ui.showInvitationsButton.setText(ctx.getString(buttonRes));
ui.showInvitationsButton.setVisibility(VISIBLE);
ui.showInvitationsButton
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(ctx,
InvitationsActivity.class);
i.putExtra(SHAREABLE, type);
Intent i = new Intent(ctx, c);
ctx.startActivity(i);
}
});
@@ -513,7 +510,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
message = new MessageHolder(messageLayout,
type == FORUM_INVITATION_IN ? MSG_IN : MSG_OUT);
text = (TextView) v.findViewById(R.id.introductionText);
showInvitationsButton = (Button) v.findViewById(R.id.showForumsButton);
showInvitationsButton = (Button) v.findViewById(R.id.showInvitationsButton);
date = (TextView) v.findViewById(R.id.introductionTime);
if (type == FORUM_INVITATION_OUT || type == BLOG_INVITATION_OUT) {