mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-23 08:09:54 +01:00
Always show private messages expanded in conversation view. Bug #32.
This give a simple and usable interface; we can worry about collapsing blocks of read messages later.
This commit is contained in:
@@ -160,35 +160,21 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
list.setVisibility(VISIBLE);
|
list.setVisibility(VISIBLE);
|
||||||
loading.setVisibility(GONE);
|
loading.setVisibility(GONE);
|
||||||
adapter.clear();
|
adapter.clear();
|
||||||
for(MessageHeader h : headers)
|
for(MessageHeader h : headers) {
|
||||||
adapter.add(new ConversationItem(h));
|
ConversationItem item = new ConversationItem(h);
|
||||||
|
byte[] body = bodyCache.get(h.getId());
|
||||||
|
if(body == null) loadMessageBody(h);
|
||||||
|
else item.setBody(body);
|
||||||
|
adapter.add(item);
|
||||||
|
}
|
||||||
adapter.sort(ConversationItemComparator.INSTANCE);
|
adapter.sort(ConversationItemComparator.INSTANCE);
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
expandMessages();
|
// Scroll to the bottom
|
||||||
|
list.setSelection(adapter.getCount() - 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expandMessages() {
|
|
||||||
// Expand unread messages and the last three messages
|
|
||||||
int count = adapter.getCount();
|
|
||||||
if(count == 0) return;
|
|
||||||
for(int i = 0; i < count; i++) {
|
|
||||||
ConversationItem item = adapter.getItem(i);
|
|
||||||
MessageHeader h = item.getHeader();
|
|
||||||
if(h.isRead() && i < count - 3) {
|
|
||||||
item.setExpanded(false);
|
|
||||||
} else {
|
|
||||||
item.setExpanded(true);
|
|
||||||
byte[] body = bodyCache.get(h.getId());
|
|
||||||
if(body == null) loadMessageBody(h);
|
|
||||||
else item.setBody(body);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Scroll to the bottom
|
|
||||||
list.setSelection(count - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadMessageBody(final MessageHeader h) {
|
private void loadMessageBody(final MessageHeader h) {
|
||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -199,7 +185,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
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");
|
||||||
displayMessage(h.getId(), body);
|
displayMessageBody(h.getId(), body);
|
||||||
} catch(NoSuchMessageException e) {
|
} catch(NoSuchMessageException e) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Message expired");
|
if(LOG.isLoggable(INFO)) LOG.info("Message expired");
|
||||||
// The item will be removed when we get the event
|
// The item will be removed when we get the event
|
||||||
@@ -215,7 +201,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayMessage(final MessageId m, final byte[] body) {
|
private void displayMessageBody(final MessageId m, final byte[] body) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
bodyCache.put(m, body);
|
bodyCache.put(m, body);
|
||||||
@@ -224,10 +210,9 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
|||||||
ConversationItem item = adapter.getItem(i);
|
ConversationItem item = adapter.getItem(i);
|
||||||
if(item.getHeader().getId().equals(m)) {
|
if(item.getHeader().getId().equals(m)) {
|
||||||
item.setBody(body);
|
item.setBody(body);
|
||||||
if(item.isExpanded()) {
|
adapter.notifyDataSetChanged();
|
||||||
adapter.notifyDataSetChanged();
|
// Scroll to the bottom
|
||||||
list.setSelection(count - 1);
|
list.setSelection(count - 1);
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,48 +43,48 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
|
|||||||
Context ctx = getContext();
|
Context ctx = getContext();
|
||||||
Resources res = ctx.getResources();
|
Resources res = ctx.getResources();
|
||||||
|
|
||||||
LinearLayout headerLayout = new LinearLayout(ctx);
|
LinearLayout layout = new LinearLayout(ctx);
|
||||||
headerLayout.setOrientation(HORIZONTAL);
|
layout.setOrientation(VERTICAL);
|
||||||
headerLayout.setGravity(CENTER_VERTICAL);
|
layout.setGravity(CENTER_HORIZONTAL);
|
||||||
int background;
|
int background;
|
||||||
if(header.isRead()) background = res.getColor(R.color.read_background);
|
if(header.isRead()) background = res.getColor(R.color.read_background);
|
||||||
else background = res.getColor(R.color.unread_background);
|
else background = res.getColor(R.color.unread_background);
|
||||||
headerLayout.setBackgroundColor(background);
|
layout.setBackgroundColor(background);
|
||||||
|
|
||||||
|
LinearLayout headerLayout = new LinearLayout(ctx);
|
||||||
|
headerLayout.setOrientation(HORIZONTAL);
|
||||||
|
headerLayout.setGravity(CENTER_VERTICAL);
|
||||||
|
|
||||||
AuthorView authorView = new AuthorView(ctx);
|
AuthorView authorView = new AuthorView(ctx);
|
||||||
authorView.setLayoutParams(WRAP_WRAP_1);
|
authorView.setLayoutParams(WRAP_WRAP_1);
|
||||||
authorView.init(header.getAuthor().getName(), VERIFIED);
|
authorView.init(header.getAuthor().getName(), VERIFIED);
|
||||||
headerLayout.addView(authorView);
|
headerLayout.addView(authorView);
|
||||||
|
|
||||||
// FIXME: Factor this out into a TimestampView
|
|
||||||
TextView date = new TextView(ctx);
|
TextView date = new TextView(ctx);
|
||||||
date.setTextSize(14);
|
date.setTextSize(14);
|
||||||
date.setPadding(0, pad, pad, pad);
|
date.setPadding(0, pad, pad, pad);
|
||||||
long then = header.getTimestamp(), now = System.currentTimeMillis();
|
long then = header.getTimestamp(), now = System.currentTimeMillis();
|
||||||
date.setText(DateUtils.formatSameDayTime(then, now, SHORT, SHORT));
|
date.setText(DateUtils.formatSameDayTime(then, now, SHORT, SHORT));
|
||||||
headerLayout.addView(date);
|
headerLayout.addView(date);
|
||||||
|
layout.addView(headerLayout);
|
||||||
|
|
||||||
if(!item.isExpanded() || item.getBody() == null) return headerLayout;
|
if(item.getBody() == null) {
|
||||||
|
TextView ellipsis = new TextView(ctx);
|
||||||
LinearLayout expanded = new LinearLayout(ctx);
|
ellipsis.setPadding(pad, 0, pad, pad);
|
||||||
expanded.setOrientation(VERTICAL);
|
ellipsis.setText("\u2026");
|
||||||
expanded.setGravity(CENTER_HORIZONTAL);
|
layout.addView(ellipsis);
|
||||||
expanded.setBackgroundColor(background);
|
} else if(header.getContentType().equals("text/plain")) {
|
||||||
expanded.addView(headerLayout);
|
|
||||||
|
|
||||||
if(header.getContentType().equals("text/plain")) {
|
|
||||||
TextView text = new TextView(ctx);
|
TextView text = new TextView(ctx);
|
||||||
text.setPadding(pad, 0, pad, pad);
|
text.setPadding(pad, 0, pad, pad);
|
||||||
text.setBackgroundColor(background);
|
|
||||||
text.setText(StringUtils.fromUtf8(item.getBody()));
|
text.setText(StringUtils.fromUtf8(item.getBody()));
|
||||||
expanded.addView(text);
|
layout.addView(text);
|
||||||
} else {
|
} else {
|
||||||
ImageButton attachment = new ImageButton(ctx);
|
ImageButton attachment = new ImageButton(ctx);
|
||||||
attachment.setPadding(pad, 0, pad, pad);
|
attachment.setPadding(pad, 0, pad, pad);
|
||||||
attachment.setImageResource(R.drawable.content_attachment);
|
attachment.setImageResource(R.drawable.content_attachment);
|
||||||
expanded.addView(attachment);
|
layout.addView(attachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
return expanded;
|
return layout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,12 +6,10 @@ import org.briarproject.api.db.MessageHeader;
|
|||||||
class ConversationItem {
|
class ConversationItem {
|
||||||
|
|
||||||
private final MessageHeader header;
|
private final MessageHeader header;
|
||||||
private boolean expanded;
|
|
||||||
private byte[] body;
|
private byte[] body;
|
||||||
|
|
||||||
ConversationItem(MessageHeader header) {
|
ConversationItem(MessageHeader header) {
|
||||||
this.header = header;
|
this.header = header;
|
||||||
expanded = false;
|
|
||||||
body = null;
|
body = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,14 +17,6 @@ class ConversationItem {
|
|||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isExpanded() {
|
|
||||||
return expanded;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setExpanded(boolean expanded) {
|
|
||||||
this.expanded = expanded;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] getBody() {
|
byte[] getBody() {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user