mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
[android] refactor conversation items and view holders
This is a preparation for image support.
This commit is contained in:
@@ -388,8 +388,8 @@ public class ConversationActivity extends BriarActivity
|
||||
private void displayMessageText(MessageId m, String text) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
textCache.put(m, text);
|
||||
SparseArray<ConversationItem> messages =
|
||||
adapter.getPrivateMessages();
|
||||
SparseArray<ConversationMessageItem> messages =
|
||||
adapter.getMessageItems();
|
||||
for (int i = 0; i < messages.size(); i++) {
|
||||
ConversationItem item = messages.valueAt(i);
|
||||
if (item.getId().equals(m)) {
|
||||
@@ -472,10 +472,9 @@ public class ConversationActivity extends BriarActivity
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
adapter.incrementRevision();
|
||||
Set<MessageId> messages = new HashSet<>(messageIds);
|
||||
SparseArray<ConversationOutItem> list =
|
||||
adapter.getOutgoingMessages();
|
||||
SparseArray<ConversationItem> list = adapter.getOutgoingMessages();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ConversationOutItem item = list.valueAt(i);
|
||||
ConversationItem item = list.valueAt(i);
|
||||
if (messages.contains(item.getId())) {
|
||||
item.setSent(sent);
|
||||
item.setSeen(seen);
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.briarproject.briar.android.util.BriarAdapter;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@NotNullByDefault
|
||||
class ConversationAdapter
|
||||
extends BriarAdapter<ConversationItem, ConversationItemViewHolder> {
|
||||
|
||||
@@ -38,15 +39,15 @@ class ConversationAdapter
|
||||
type, viewGroup, false);
|
||||
switch (type) {
|
||||
case R.layout.list_item_conversation_msg_in:
|
||||
return new ConversationItemViewHolder(v);
|
||||
return new ConversationMessageViewHolder(v, true);
|
||||
case R.layout.list_item_conversation_msg_out:
|
||||
return new ConversationMessageOutViewHolder(v);
|
||||
return new ConversationMessageViewHolder(v, false);
|
||||
case R.layout.list_item_conversation_notice_in:
|
||||
return new ConversationNoticeInViewHolder(v);
|
||||
return new ConversationNoticeViewHolder(v, true);
|
||||
case R.layout.list_item_conversation_notice_out:
|
||||
return new ConversationNoticeOutViewHolder(v);
|
||||
return new ConversationNoticeViewHolder(v, false);
|
||||
case R.layout.list_item_conversation_request:
|
||||
return new ConversationRequestViewHolder(v);
|
||||
return new ConversationRequestViewHolder(v, true);
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown ConversationItem");
|
||||
}
|
||||
@@ -56,21 +57,18 @@ class ConversationAdapter
|
||||
public void onBindViewHolder(ConversationItemViewHolder ui, int position) {
|
||||
ConversationItem item = items.get(position);
|
||||
if (item instanceof ConversationRequestItem) {
|
||||
((ConversationRequestViewHolder) ui).bind(item, listener);
|
||||
((ConversationRequestViewHolder) ui)
|
||||
.bind((ConversationRequestItem) item, listener);
|
||||
} else {
|
||||
//noinspection unchecked
|
||||
ui.bind(item);
|
||||
}
|
||||
listener.onItemVisible(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(ConversationItem c1,
|
||||
ConversationItem c2) {
|
||||
long time1 = c1.getTime();
|
||||
long time2 = c2.getTime();
|
||||
if (time1 < time2) return -1;
|
||||
if (time1 > time2) return 1;
|
||||
return 0;
|
||||
public int compare(ConversationItem c1, ConversationItem c2) {
|
||||
return Long.compare(c1.getTime(), c2.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,39 +92,25 @@ class ConversationAdapter
|
||||
}
|
||||
}
|
||||
|
||||
SparseArray<ConversationItem> getIncomingMessages() {
|
||||
SparseArray<ConversationItem> getOutgoingMessages() {
|
||||
SparseArray<ConversationItem> messages = new SparseArray<>();
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
ConversationItem item = items.get(i);
|
||||
if (item.isIncoming()) {
|
||||
if (!item.isIncoming()) {
|
||||
messages.put(i, item);
|
||||
}
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
SparseArray<ConversationOutItem> getOutgoingMessages() {
|
||||
SparseArray<ConversationOutItem> messages = new SparseArray<>();
|
||||
SparseArray<ConversationMessageItem> getMessageItems() {
|
||||
SparseArray<ConversationMessageItem> messages = new SparseArray<>();
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
ConversationItem item = items.get(i);
|
||||
if (item instanceof ConversationOutItem) {
|
||||
messages.put(i, (ConversationOutItem) item);
|
||||
}
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
SparseArray<ConversationItem> getPrivateMessages() {
|
||||
SparseArray<ConversationItem> messages = new SparseArray<>();
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
ConversationItem item = items.get(i);
|
||||
if (item instanceof ConversationMessageInItem) {
|
||||
messages.put(i, item);
|
||||
} else if (item instanceof ConversationMessageOutItem) {
|
||||
messages.put(i, item);
|
||||
if (item instanceof ConversationMessageItem) {
|
||||
messages.put(i, (ConversationMessageItem) item);
|
||||
}
|
||||
}
|
||||
return messages;
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.support.annotation.LayoutRes;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
@@ -13,20 +14,31 @@ import javax.annotation.concurrent.NotThreadSafe;
|
||||
@NotNullByDefault
|
||||
abstract class ConversationItem {
|
||||
|
||||
@LayoutRes
|
||||
private final int layoutRes;
|
||||
@Nullable
|
||||
protected String text;
|
||||
private final MessageId id;
|
||||
private final GroupId groupId;
|
||||
private final long time;
|
||||
private boolean read;
|
||||
private final boolean isIncoming;
|
||||
private boolean read, sent, seen;
|
||||
|
||||
ConversationItem(MessageId id, GroupId groupId, @Nullable String text,
|
||||
long time, boolean read) {
|
||||
this.id = id;
|
||||
this.groupId = groupId;
|
||||
this.text = text;
|
||||
this.time = time;
|
||||
this.read = read;
|
||||
ConversationItem(@LayoutRes int layoutRes, ConversationMessageHeader h) {
|
||||
this.layoutRes = layoutRes;
|
||||
this.text = null;
|
||||
this.id = h.getId();
|
||||
this.groupId = h.getGroupId();
|
||||
this.time = h.getTimestamp();
|
||||
this.read = h.isRead();
|
||||
this.sent = h.isSent();
|
||||
this.seen = h.isSeen();
|
||||
this.isIncoming = !h.isLocal();
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
public int getLayout() {
|
||||
return layoutRes;
|
||||
}
|
||||
|
||||
MessageId getId() {
|
||||
@@ -50,12 +62,43 @@ abstract class ConversationItem {
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only useful for incoming messages.
|
||||
*/
|
||||
public boolean isRead() {
|
||||
return read;
|
||||
}
|
||||
|
||||
abstract public boolean isIncoming();
|
||||
/**
|
||||
* Only useful for outgoing messages.
|
||||
*/
|
||||
boolean isSent() {
|
||||
return sent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only useful for outgoing messages.
|
||||
*/
|
||||
void setSent(boolean sent) {
|
||||
this.sent = sent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only useful for outgoing messages.
|
||||
*/
|
||||
boolean isSeen() {
|
||||
return seen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only useful for outgoing messages.
|
||||
*/
|
||||
void setSeen(boolean seen) {
|
||||
this.seen = seen;
|
||||
}
|
||||
|
||||
public boolean isIncoming() {
|
||||
return isIncoming;
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
abstract public int getLayout();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.support.v7.widget.RecyclerView.ViewHolder;
|
||||
import android.view.View;
|
||||
@@ -8,35 +9,46 @@ import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.util.UiUtils;
|
||||
|
||||
import static org.briarproject.bramble.util.StringUtils.trim;
|
||||
import static org.briarproject.briar.android.util.UiUtils.formatDate;
|
||||
|
||||
@UiThread
|
||||
@NotNullByDefault
|
||||
class ConversationItemViewHolder extends ViewHolder {
|
||||
abstract class ConversationItemViewHolder<T extends ConversationItem>
|
||||
extends ViewHolder {
|
||||
|
||||
protected final ViewGroup layout;
|
||||
@Nullable
|
||||
private final OutItemViewHolder outViewHolder;
|
||||
private final TextView text;
|
||||
private final TextView time;
|
||||
|
||||
ConversationItemViewHolder(View v) {
|
||||
ConversationItemViewHolder(View v, boolean isIncoming) {
|
||||
super(v);
|
||||
this.outViewHolder = isIncoming ? null : new OutItemViewHolder(v);
|
||||
layout = v.findViewById(R.id.layout);
|
||||
text = v.findViewById(R.id.text);
|
||||
time = v.findViewById(R.id.time);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
void bind(ConversationItem item) {
|
||||
void bind(T item) {
|
||||
if (item.getText() == null) {
|
||||
text.setText("\u2026");
|
||||
} else {
|
||||
text.setText(StringUtils.trim(item.getText()));
|
||||
text.setText(trim(item.getText()));
|
||||
}
|
||||
|
||||
long timestamp = item.getTime();
|
||||
time.setText(UiUtils.formatDate(time.getContext(), timestamp));
|
||||
time.setText(formatDate(time.getContext(), timestamp));
|
||||
|
||||
if (outViewHolder != null) outViewHolder.bind(item);
|
||||
}
|
||||
|
||||
protected boolean isIncoming() {
|
||||
return outViewHolder == null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.support.annotation.LayoutRes;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
|
||||
@NotThreadSafe
|
||||
@NotNullByDefault
|
||||
class ConversationMessageInItem extends ConversationItem {
|
||||
|
||||
ConversationMessageInItem(PrivateMessageHeader h) {
|
||||
super(h.getId(), h.getGroupId(), null, h.getTimestamp(), h.isRead());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncoming() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
@Override
|
||||
public int getLayout() {
|
||||
return R.layout.list_item_conversation_msg_in;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.support.annotation.LayoutRes;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.api.messaging.AttachmentHeader;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
|
||||
@NotThreadSafe
|
||||
@NotNullByDefault
|
||||
class ConversationMessageItem extends ConversationItem {
|
||||
|
||||
private final List<AttachmentHeader> attachments;
|
||||
|
||||
ConversationMessageItem(@LayoutRes int layoutRes, PrivateMessageHeader h) {
|
||||
super(layoutRes, h);
|
||||
this.attachments = h.getAttachmentHeaders();
|
||||
}
|
||||
|
||||
List<AttachmentHeader> getAttachments() {
|
||||
return attachments;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.support.annotation.LayoutRes;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
|
||||
@NotThreadSafe
|
||||
@NotNullByDefault
|
||||
class ConversationMessageOutItem extends ConversationOutItem {
|
||||
|
||||
ConversationMessageOutItem(PrivateMessageHeader h) {
|
||||
super(h.getId(), h.getGroupId(), null, h.getTimestamp(), h.isSent(),
|
||||
h.isSeen());
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
@Override
|
||||
public int getLayout() {
|
||||
return R.layout.list_item_conversation_msg_out;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
class ConversationMessageOutViewHolder extends ConversationOutItemViewHolder {
|
||||
|
||||
ConversationMessageOutViewHolder(View v) {
|
||||
super(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasDarkBackground() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.support.annotation.UiThread;
|
||||
import android.view.View;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
@UiThread
|
||||
@NotNullByDefault
|
||||
class ConversationMessageViewHolder
|
||||
extends ConversationItemViewHolder<ConversationMessageItem> {
|
||||
|
||||
// image support will be added here (#1242)
|
||||
|
||||
ConversationMessageViewHolder(View v, boolean isIncoming) {
|
||||
super(v, isIncoming);
|
||||
}
|
||||
|
||||
@Override
|
||||
void bind(ConversationMessageItem item) {
|
||||
super.bind(item);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.support.annotation.LayoutRes;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.api.conversation.ConversationResponse;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
|
||||
@NotThreadSafe
|
||||
@NotNullByDefault
|
||||
class ConversationNoticeInItem extends ConversationItem {
|
||||
|
||||
@Nullable
|
||||
private final String msgText;
|
||||
|
||||
ConversationNoticeInItem(MessageId id, GroupId groupId, String text,
|
||||
@Nullable String msgText, long time, boolean read) {
|
||||
super(id, groupId, text, time, read);
|
||||
this.msgText = msgText;
|
||||
}
|
||||
|
||||
ConversationNoticeInItem(String text, ConversationResponse r) {
|
||||
super(r.getId(), r.getGroupId(), text, r.getTimestamp(), r.isRead());
|
||||
this.msgText = null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
String getMsgText() {
|
||||
return msgText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncoming() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
@Override
|
||||
public int getLayout() {
|
||||
return R.layout.list_item_conversation_notice_in;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.support.annotation.UiThread;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.R;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
|
||||
@UiThread
|
||||
@NotNullByDefault
|
||||
class ConversationNoticeInViewHolder extends ConversationItemViewHolder {
|
||||
|
||||
private final TextView msgText;
|
||||
|
||||
ConversationNoticeInViewHolder(View v) {
|
||||
super(v);
|
||||
msgText = v.findViewById(R.id.msgText);
|
||||
}
|
||||
|
||||
@Override
|
||||
void bind(ConversationItem conversationItem) {
|
||||
super.bind(conversationItem);
|
||||
|
||||
ConversationNoticeInItem item =
|
||||
(ConversationNoticeInItem) conversationItem;
|
||||
|
||||
String text = item.getMsgText();
|
||||
if (StringUtils.isNullOrEmpty(text)) {
|
||||
msgText.setVisibility(GONE);
|
||||
layout.setBackgroundResource(R.drawable.notice_in);
|
||||
} else {
|
||||
msgText.setVisibility(VISIBLE);
|
||||
msgText.setText(StringUtils.trim(text));
|
||||
layout.setBackgroundResource(R.drawable.notice_in_bottom);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package org.briarproject.briar.android.conversation;
|
||||
import android.support.annotation.LayoutRes;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.api.conversation.ConversationRequest;
|
||||
import org.briarproject.briar.api.conversation.ConversationResponse;
|
||||
|
||||
@@ -12,20 +11,22 @@ import javax.annotation.concurrent.NotThreadSafe;
|
||||
|
||||
@NotThreadSafe
|
||||
@NotNullByDefault
|
||||
class ConversationNoticeOutItem extends ConversationOutItem {
|
||||
class ConversationNoticeItem extends ConversationItem {
|
||||
|
||||
@Nullable
|
||||
private final String msgText;
|
||||
|
||||
ConversationNoticeOutItem(String text, ConversationRequest r) {
|
||||
super(r.getId(), r.getGroupId(), text, r.getTimestamp(), r.isSent(),
|
||||
r.isSeen());
|
||||
ConversationNoticeItem(@LayoutRes int layoutRes, String text,
|
||||
ConversationRequest r) {
|
||||
super(layoutRes, r);
|
||||
this.text = text;
|
||||
this.msgText = r.getText();
|
||||
}
|
||||
|
||||
ConversationNoticeOutItem(String text, ConversationResponse r) {
|
||||
super(r.getId(), r.getGroupId(), text, r.getTimestamp(), r.isSent(),
|
||||
r.isSeen());
|
||||
ConversationNoticeItem(@LayoutRes int layoutRes, String text,
|
||||
ConversationResponse r) {
|
||||
super(layoutRes, r);
|
||||
this.text = text;
|
||||
this.msgText = null;
|
||||
}
|
||||
|
||||
@@ -34,9 +35,4 @@ class ConversationNoticeOutItem extends ConversationOutItem {
|
||||
return msgText;
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
@Override
|
||||
public int getLayout() {
|
||||
return R.layout.list_item_conversation_notice_out;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.support.annotation.UiThread;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.R;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
|
||||
@UiThread
|
||||
@NotNullByDefault
|
||||
class ConversationNoticeOutViewHolder extends ConversationOutItemViewHolder {
|
||||
|
||||
private final TextView msgText;
|
||||
|
||||
ConversationNoticeOutViewHolder(View v) {
|
||||
super(v);
|
||||
msgText = v.findViewById(R.id.msgText);
|
||||
}
|
||||
|
||||
@Override
|
||||
void bind(ConversationItem conversationItem) {
|
||||
super.bind(conversationItem);
|
||||
|
||||
ConversationNoticeOutItem item =
|
||||
(ConversationNoticeOutItem) conversationItem;
|
||||
|
||||
String text = item.getMsgText();
|
||||
if (StringUtils.isNullOrEmpty(text)) {
|
||||
msgText.setVisibility(GONE);
|
||||
layout.setBackgroundResource(R.drawable.notice_out);
|
||||
} else {
|
||||
msgText.setVisibility(VISIBLE);
|
||||
msgText.setText(StringUtils.trim(text));
|
||||
layout.setBackgroundResource(R.drawable.notice_out_bottom);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasDarkBackground() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.support.annotation.UiThread;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||
import static org.briarproject.bramble.util.StringUtils.trim;
|
||||
|
||||
@UiThread
|
||||
@NotNullByDefault
|
||||
class ConversationNoticeViewHolder<T extends ConversationNoticeItem>
|
||||
extends ConversationItemViewHolder<T> {
|
||||
|
||||
private final TextView msgText;
|
||||
|
||||
ConversationNoticeViewHolder(View v, boolean isIncoming) {
|
||||
super(v, isIncoming);
|
||||
msgText = v.findViewById(R.id.msgText);
|
||||
}
|
||||
|
||||
@Override
|
||||
void bind(T item) {
|
||||
super.bind(item);
|
||||
|
||||
String text = item.getMsgText();
|
||||
if (isNullOrEmpty(text)) {
|
||||
msgText.setVisibility(GONE);
|
||||
layout.setBackgroundResource(isIncoming() ? R.drawable.notice_in :
|
||||
R.drawable.notice_out);
|
||||
} else {
|
||||
msgText.setVisibility(VISIBLE);
|
||||
msgText.setText(trim(text));
|
||||
layout.setBackgroundResource(isIncoming() ?
|
||||
R.drawable.notice_in_bottom : R.drawable.notice_out_bottom);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package org.briarproject.briar.android.conversation;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
|
||||
@NotThreadSafe
|
||||
@NotNullByDefault
|
||||
abstract class ConversationOutItem extends ConversationItem {
|
||||
|
||||
private boolean sent, seen;
|
||||
|
||||
ConversationOutItem(MessageId id, GroupId groupId, @Nullable String text,
|
||||
long time, boolean sent, boolean seen) {
|
||||
super(id, groupId, text, time, true);
|
||||
|
||||
this.sent = sent;
|
||||
this.seen = seen;
|
||||
}
|
||||
|
||||
boolean isSent() {
|
||||
return sent;
|
||||
}
|
||||
|
||||
void setSent(boolean sent) {
|
||||
this.sent = sent;
|
||||
}
|
||||
|
||||
boolean isSeen() {
|
||||
return seen;
|
||||
}
|
||||
|
||||
void setSeen(boolean seen) {
|
||||
this.seen = seen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncoming() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.support.annotation.UiThread;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
|
||||
@UiThread
|
||||
@NotNullByDefault
|
||||
abstract class ConversationOutItemViewHolder
|
||||
extends ConversationItemViewHolder {
|
||||
|
||||
private final ImageView status;
|
||||
|
||||
ConversationOutItemViewHolder(View v) {
|
||||
super(v);
|
||||
status = v.findViewById(R.id.status);
|
||||
}
|
||||
|
||||
@Override
|
||||
void bind(ConversationItem conversationItem) {
|
||||
super.bind(conversationItem);
|
||||
|
||||
ConversationOutItem item = (ConversationOutItem) conversationItem;
|
||||
|
||||
int res;
|
||||
if (item.isSeen()) {
|
||||
if (hasDarkBackground()) res = R.drawable.message_delivered_white;
|
||||
else res = R.drawable.message_delivered;
|
||||
} else if (item.isSent()) {
|
||||
if (hasDarkBackground()) res = R.drawable.message_sent_white;
|
||||
else res = R.drawable.message_sent;
|
||||
} else {
|
||||
if (hasDarkBackground()) res = R.drawable.message_stored_white;
|
||||
else res = R.drawable.message_stored;
|
||||
}
|
||||
status.setImageResource(res);
|
||||
}
|
||||
|
||||
protected abstract boolean hasDarkBackground();
|
||||
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import android.support.annotation.LayoutRes;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.conversation.ConversationRequest;
|
||||
import org.briarproject.briar.api.sharing.InvitationRequest;
|
||||
@@ -15,7 +14,7 @@ import javax.annotation.concurrent.NotThreadSafe;
|
||||
|
||||
@NotThreadSafe
|
||||
@NotNullByDefault
|
||||
class ConversationRequestItem extends ConversationNoticeInItem {
|
||||
class ConversationRequestItem extends ConversationNoticeItem {
|
||||
|
||||
enum RequestType {INTRODUCTION, FORUM, BLOG, GROUP}
|
||||
|
||||
@@ -26,9 +25,9 @@ class ConversationRequestItem extends ConversationNoticeInItem {
|
||||
private final boolean canBeOpened;
|
||||
private boolean answered;
|
||||
|
||||
ConversationRequestItem(String text, RequestType type, ConversationRequest r) {
|
||||
super(r.getId(), r.getGroupId(), text, r.getText(),
|
||||
r.getTimestamp(), r.isRead());
|
||||
ConversationRequestItem(@LayoutRes int layoutRes, String text,
|
||||
RequestType type, ConversationRequest r) {
|
||||
super(layoutRes, text, r);
|
||||
this.requestType = type;
|
||||
this.sessionId = r.getSessionId();
|
||||
this.answered = r.wasAnswered();
|
||||
@@ -66,9 +65,4 @@ class ConversationRequestItem extends ConversationNoticeInItem {
|
||||
return canBeOpened;
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
@Override
|
||||
public int getLayout() {
|
||||
return R.layout.list_item_conversation_request;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,23 +13,21 @@ import static android.view.View.VISIBLE;
|
||||
|
||||
@UiThread
|
||||
@NotNullByDefault
|
||||
class ConversationRequestViewHolder extends ConversationNoticeInViewHolder {
|
||||
class ConversationRequestViewHolder
|
||||
extends ConversationNoticeViewHolder<ConversationRequestItem> {
|
||||
|
||||
private final Button acceptButton;
|
||||
private final Button declineButton;
|
||||
|
||||
ConversationRequestViewHolder(View v) {
|
||||
super(v);
|
||||
ConversationRequestViewHolder(View v, boolean isIncoming) {
|
||||
super(v, isIncoming);
|
||||
acceptButton = v.findViewById(R.id.acceptButton);
|
||||
declineButton = v.findViewById(R.id.declineButton);
|
||||
}
|
||||
|
||||
void bind(ConversationItem conversationItem,
|
||||
void bind(ConversationRequestItem item,
|
||||
ConversationListener listener) {
|
||||
super.bind(conversationItem);
|
||||
|
||||
ConversationRequestItem item =
|
||||
(ConversationRequestItem) conversationItem;
|
||||
super.bind(item);
|
||||
|
||||
if (item.wasAnswered() && item.canBeOpened()) {
|
||||
acceptButton.setVisibility(VISIBLE);
|
||||
|
||||
@@ -45,8 +45,13 @@ class ConversationVisitor implements
|
||||
@Override
|
||||
public ConversationItem visitPrivateMessageHeader(PrivateMessageHeader h) {
|
||||
ConversationItem item;
|
||||
if (h.isLocal()) item = new ConversationMessageOutItem(h);
|
||||
else item = new ConversationMessageInItem(h);
|
||||
if (h.isLocal()) {
|
||||
item = new ConversationMessageItem(
|
||||
R.layout.list_item_conversation_msg_out, h);
|
||||
} else {
|
||||
item = new ConversationMessageItem(
|
||||
R.layout.list_item_conversation_msg_in, h);
|
||||
}
|
||||
String text = textCache.getText(h.getId());
|
||||
if (text != null) item.setText(text);
|
||||
return item;
|
||||
@@ -58,12 +63,14 @@ class ConversationVisitor implements
|
||||
if (r.isLocal()) {
|
||||
String text = ctx.getString(R.string.blogs_sharing_invitation_sent,
|
||||
r.getName(), contactName.getValue());
|
||||
return new ConversationNoticeOutItem(text, r);
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_out, text, r);
|
||||
} else {
|
||||
String text = ctx.getString(
|
||||
R.string.blogs_sharing_invitation_received,
|
||||
contactName.getValue(), r.getName());
|
||||
return new ConversationRequestItem(text, BLOG, r);
|
||||
return new ConversationRequestItem(
|
||||
R.layout.list_item_conversation_request, text, BLOG, r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +88,8 @@ class ConversationVisitor implements
|
||||
R.string.blogs_sharing_response_declined_sent,
|
||||
contactName.getValue());
|
||||
}
|
||||
return new ConversationNoticeOutItem(text, r);
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_out, text, r);
|
||||
} else {
|
||||
String text;
|
||||
if (r.wasAccepted()) {
|
||||
@@ -93,7 +101,8 @@ class ConversationVisitor implements
|
||||
R.string.blogs_sharing_response_declined_received,
|
||||
contactName.getValue());
|
||||
}
|
||||
return new ConversationNoticeInItem(text, r);
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_in, text, r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,12 +112,14 @@ class ConversationVisitor implements
|
||||
if (r.isLocal()) {
|
||||
String text = ctx.getString(R.string.forum_invitation_sent,
|
||||
r.getName(), contactName.getValue());
|
||||
return new ConversationNoticeOutItem(text, r);
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_out, text, r);
|
||||
} else {
|
||||
String text = ctx.getString(
|
||||
R.string.forum_invitation_received,
|
||||
contactName.getValue(), r.getName());
|
||||
return new ConversationRequestItem(text, FORUM, r);
|
||||
return new ConversationRequestItem(
|
||||
R.layout.list_item_conversation_request, text, FORUM, r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +137,8 @@ class ConversationVisitor implements
|
||||
R.string.forum_invitation_response_declined_sent,
|
||||
contactName.getValue());
|
||||
}
|
||||
return new ConversationNoticeOutItem(text, r);
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_out, text, r);
|
||||
} else {
|
||||
String text;
|
||||
if (r.wasAccepted()) {
|
||||
@@ -138,7 +150,8 @@ class ConversationVisitor implements
|
||||
R.string.forum_invitation_response_declined_received,
|
||||
contactName.getValue());
|
||||
}
|
||||
return new ConversationNoticeInItem(text, r);
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_in, text, r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,12 +162,14 @@ class ConversationVisitor implements
|
||||
String text = ctx.getString(
|
||||
R.string.groups_invitations_invitation_sent,
|
||||
contactName.getValue(), r.getName());
|
||||
return new ConversationNoticeOutItem(text, r);
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_out, text, r);
|
||||
} else {
|
||||
String text = ctx.getString(
|
||||
R.string.groups_invitations_invitation_received,
|
||||
contactName.getValue(), r.getName());
|
||||
return new ConversationRequestItem(text, GROUP, r);
|
||||
return new ConversationRequestItem(
|
||||
R.layout.list_item_conversation_request, text, GROUP, r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +187,8 @@ class ConversationVisitor implements
|
||||
R.string.groups_invitations_response_declined_sent,
|
||||
contactName.getValue());
|
||||
}
|
||||
return new ConversationNoticeOutItem(text, r);
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_out, text, r);
|
||||
} else {
|
||||
String text;
|
||||
if (r.wasAccepted()) {
|
||||
@@ -184,7 +200,8 @@ class ConversationVisitor implements
|
||||
R.string.groups_invitations_response_declined_received,
|
||||
contactName.getValue());
|
||||
}
|
||||
return new ConversationNoticeInItem(text, r);
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_in, text, r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,11 +211,14 @@ class ConversationVisitor implements
|
||||
if (r.isLocal()) {
|
||||
String text = ctx.getString(R.string.introduction_request_sent,
|
||||
contactName.getValue(), name);
|
||||
return new ConversationNoticeOutItem(text, r);
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_out, text, r);
|
||||
} else {
|
||||
String text = ctx.getString(R.string.introduction_request_received,
|
||||
contactName.getValue(), name);
|
||||
return new ConversationRequestItem(text, INTRODUCTION, r);
|
||||
return new ConversationRequestItem(
|
||||
R.layout.list_item_conversation_request, text, INTRODUCTION,
|
||||
r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +241,8 @@ class ConversationVisitor implements
|
||||
R.string.introduction_response_declined_sent,
|
||||
introducedAuthor);
|
||||
}
|
||||
return new ConversationNoticeOutItem(text, r);
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_out, text, r);
|
||||
} else {
|
||||
String text;
|
||||
if (r.wasAccepted()) {
|
||||
@@ -240,7 +261,8 @@ class ConversationVisitor implements
|
||||
contactName.getValue(),
|
||||
introducedAuthor);
|
||||
}
|
||||
return new ConversationNoticeInItem(text, r);
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_in, text, r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.support.annotation.UiThread;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
|
||||
@UiThread
|
||||
@NotNullByDefault
|
||||
class OutItemViewHolder {
|
||||
|
||||
private final ImageView status;
|
||||
|
||||
OutItemViewHolder(View v) {
|
||||
status = v.findViewById(R.id.status);
|
||||
}
|
||||
|
||||
void bind(ConversationItem item) {
|
||||
int res;
|
||||
if (item.isSeen()) {
|
||||
res = R.drawable.message_delivered;
|
||||
} else if (item.isSent()) {
|
||||
res = R.drawable.message_sent;
|
||||
} else {
|
||||
res = R.drawable.message_stored;
|
||||
}
|
||||
status.setImageResource(res);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,19 +12,19 @@ import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState;
|
||||
import org.briarproject.bramble.api.lifecycle.event.LifecycleEvent;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.COMPACTING_DATABASE;
|
||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.MIGRATING_DATABASE;
|
||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.STARTING_SERVICES;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
public class OpenDatabaseActivity extends BriarActivity
|
||||
implements EventListener {
|
||||
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M18,7l-1.41,-1.41 -6.34,6.34 1.41,1.41L18,7zm4.24,-1.41L11.66,16.17 7.48,12l-1.41,1.41L11.66,19l12,-12 -1.42,-1.41zM0.41,13.41L6,19l1.41,-1.41L1.83,12 0.41,13.41z"/>
|
||||
</vector>
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="16dp"
|
||||
android:height="16dp"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M18,7l-1.41,-1.41 -6.34,6.34 1.41,1.41L18,7zm4.24,-1.41L11.66,16.17 7.48,12l-1.41,1.41L11.66,19l12,-12 -1.42,-1.41zM0.41,13.41L6,19l1.41,-1.41L1.83,12 0.41,13.41z"/>
|
||||
</vector>
|
||||
@@ -5,6 +5,6 @@
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
|
||||
</vector>
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="16dp"
|
||||
android:height="16dp"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
|
||||
</vector>
|
||||
@@ -4,6 +4,6 @@
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8zM12.5,7H11v6l5.25,3.15 0.75,-1.23 -4.5,-2.67z"/>
|
||||
</vector>
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<vector android:height="16dp"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="16dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillAlpha=".9" android:fillColor="#FFFFFF" android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8zM12.5,7H11v6l5.25,3.15 0.75,-1.23 -4.5,-2.67z"/>
|
||||
</vector>
|
||||
@@ -27,6 +27,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/briar_text_primary_inverse"
|
||||
app:layout_constraintBottom_toTopOf="@+id/time"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="This is a long long long message that spans over several lines.\n\nIt ends here."/>
|
||||
@@ -52,7 +53,7 @@
|
||||
app:layout_constraintStart_toEndOf="@+id/time"
|
||||
app:layout_constraintTop_toTopOf="@+id/time"
|
||||
tools:ignore="ContentDescription"
|
||||
tools:src="@drawable/message_delivered_white"/>
|
||||
tools:src="@drawable/message_delivered"/>
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/text"
|
||||
tools:text="Dec 24, 13:37"/>
|
||||
|
||||
<android.support.v7.widget.AppCompatImageView
|
||||
<ImageView
|
||||
android:id="@+id/status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -64,7 +64,6 @@
|
||||
app:layout_constraintBottom_toBottomOf="@+id/time"
|
||||
app:layout_constraintStart_toEndOf="@+id/time"
|
||||
app:layout_constraintTop_toTopOf="@+id/time"
|
||||
app:tint="@color/private_message_date_inverse"
|
||||
tools:ignore="ContentDescription"
|
||||
tools:src="@drawable/message_delivered"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user