UI for introducing two contacts to each other

Show system notification for successful introductions
This commit is contained in:
Torsten Grote
2016-01-19 13:28:59 -02:00
parent 7c687736df
commit 5ea7ff2857
65 changed files with 2398 additions and 271 deletions

View File

@@ -1,46 +1,105 @@
package org.briarproject.android.contact;
import org.briarproject.api.messaging.PrivateMessageHeader;
import android.content.Context;
import org.briarproject.R;
import org.briarproject.api.introduction.IntroductionMessage;
import org.briarproject.api.introduction.IntroductionRequest;
import org.briarproject.api.introduction.IntroductionResponse;
import org.briarproject.api.sync.MessageId;
// This class is not thread-safe
class ConversationItem {
public abstract class ConversationItem {
private final PrivateMessageHeader header;
private byte[] body;
private boolean sent, seen;
final static int MSG_IN = 0;
final static int MSG_IN_UNREAD = 1;
final static int MSG_OUT = 2;
final static int INTRODUCTION_IN = 3;
final static int INTRODUCTION_OUT = 4;
final static int NOTICE_IN = 5;
final static int NOTICE_OUT = 6;
ConversationItem(PrivateMessageHeader header) {
this.header = header;
body = null;
sent = header.isSent();
seen = header.isSeen();
private MessageId id;
private long time;
public ConversationItem(MessageId id, long time) {
this.id = id;
this.time = time;
}
PrivateMessageHeader getHeader() {
return header;
abstract int getType();
public MessageId getId() {
return id;
}
byte[] getBody() {
return body;
long getTime() {
return time;
}
void setBody(byte[] body) {
this.body = body;
public static ConversationItem from(IntroductionRequest ir) {
if (ir.isLocal()) {
return new ConversationIntroductionOutItem(ir);
} else {
return new ConversationIntroductionInItem(ir);
}
}
boolean isSent() {
return sent;
public static ConversationItem from(Context ctx, String contactName,
IntroductionResponse ir) {
if (ir.isLocal()) {
String text;
if (ir.wasAccepted()) {
text = ctx.getString(
R.string.introduction_response_accepted_sent,
ir.getName());
} else {
text = ctx.getString(
R.string.introduction_response_declined_sent,
ir.getName());
}
return new ConversationNoticeOutItem(ir.getMessageId(), text,
ir.getTime(), ir.isSent(), ir.isSeen());
} else {
String text;
if (ir.wasAccepted()) {
text = ctx.getString(
R.string.introduction_response_accepted_received,
contactName, ir.getName());
} else {
text = ctx.getString(
R.string.introduction_response_declined_received,
contactName, ir.getName());
}
return new ConversationNoticeInItem(ir.getMessageId(), text,
ir.getTime(), ir.isRead());
}
}
void setSent(boolean sent) {
this.sent = sent;
/** This method should not be used to get user-facing objects,
* Its purpose is to provider data for the contact list.
*/
public static ConversationItem from(IntroductionMessage im) {
if (im.isLocal())
return new ConversationNoticeOutItem(im.getMessageId(), "",
im.getTime(), false, false);
return new ConversationNoticeInItem(im.getMessageId(), "", im.getTime(),
im.isRead());
}
boolean isSeen() {
return seen;
protected interface OutgoingItem {
MessageId getId();
boolean isSent();
void setSent(boolean sent);
boolean isSeen();
void setSeen(boolean seen);
}
void setSeen(boolean seen) {
this.seen = seen;
protected interface IncomingItem {
MessageId getId();
boolean isRead();
void setRead(boolean read);
}
}