diff --git a/briar-android/src/org/briarproject/android/groups/GroupActivity.java b/briar-android/src/org/briarproject/android/groups/GroupActivity.java index 65d640a8b5df0fcc6ec6db5fd9496fa7f930170e..8f14857a0ef8bf43a8555d1582a8e1f72fe6c3d9 100644 --- a/briar-android/src/org/briarproject/android/groups/GroupActivity.java +++ b/briar-android/src/org/briarproject/android/groups/GroupActivity.java @@ -151,35 +151,21 @@ OnClickListener, OnItemClickListener { list.setVisibility(VISIBLE); loading.setVisibility(GONE); adapter.clear(); - for(MessageHeader h : headers) adapter.add(new GroupItem(h)); + for(MessageHeader h : headers) { + GroupItem item = new GroupItem(h); + byte[] body = bodyCache.get(h.getId()); + if(body == null) loadMessageBody(h); + else item.setBody(body); + adapter.add(item); + } adapter.sort(GroupItemComparator.INSTANCE); 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++) { - GroupItem item = adapter.getItem(i); - MessageHeader h = item.getHeader(); - if(h.isRead() && i < count - 3) { - item.setExpanded(false); - } else { - item.setExpanded(true); - 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) { dbUiExecutor.execute(new Runnable() { public void run() { @@ -215,10 +201,9 @@ OnClickListener, OnItemClickListener { GroupItem item = adapter.getItem(i); if(item.getHeader().getId().equals(m)) { item.setBody(body); - if(item.isExpanded()) { - adapter.notifyDataSetChanged(); - list.setSelection(count - 1); - } + adapter.notifyDataSetChanged(); + // Scroll to the bottom + list.setSelection(count - 1); return; } } diff --git a/briar-android/src/org/briarproject/android/groups/GroupAdapter.java b/briar-android/src/org/briarproject/android/groups/GroupAdapter.java index bbe7d677ca81eeeaf166c8ae1232c7875dacec7f..5fef0bcdc1aad40e8e210d12911319f86568b4ff 100644 --- a/briar-android/src/org/briarproject/android/groups/GroupAdapter.java +++ b/briar-android/src/org/briarproject/android/groups/GroupAdapter.java @@ -43,13 +43,17 @@ class GroupAdapter extends ArrayAdapter<GroupItem> { Context ctx = getContext(); Resources res = ctx.getResources(); - LinearLayout headerLayout = new LinearLayout(ctx); - headerLayout.setOrientation(HORIZONTAL); - headerLayout.setGravity(CENTER_VERTICAL); + LinearLayout layout = new LinearLayout(ctx); + layout.setOrientation(VERTICAL); + layout.setGravity(CENTER_HORIZONTAL); int background; if(header.isRead()) background = res.getColor(R.color.read_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.setLayoutParams(WRAP_WRAP_1); @@ -64,28 +68,25 @@ class GroupAdapter extends ArrayAdapter<GroupItem> { long then = header.getTimestamp(), now = System.currentTimeMillis(); date.setText(DateUtils.formatSameDayTime(then, now, SHORT, SHORT)); headerLayout.addView(date); + layout.addView(headerLayout); - if(!item.isExpanded() || item.getBody() == null) return headerLayout; - - LinearLayout expanded = new LinearLayout(ctx); - expanded.setOrientation(VERTICAL); - expanded.setGravity(CENTER_HORIZONTAL); - expanded.setBackgroundColor(background); - expanded.addView(headerLayout); - - if(header.getContentType().equals("text/plain")) { + if(item.getBody() == null) { + TextView ellipsis = new TextView(ctx); + ellipsis.setPadding(pad, 0, pad, pad); + ellipsis.setText("\u2026"); + layout.addView(ellipsis); + } else if(header.getContentType().equals("text/plain")) { TextView text = new TextView(ctx); text.setPadding(pad, 0, pad, pad); - text.setBackgroundColor(background); text.setText(StringUtils.fromUtf8(item.getBody())); - expanded.addView(text); + layout.addView(text); } else { ImageButton attachment = new ImageButton(ctx); attachment.setPadding(pad, 0, pad, pad); attachment.setImageResource(R.drawable.content_attachment); - expanded.addView(attachment); + layout.addView(attachment); } - return expanded; + return layout; } } \ No newline at end of file diff --git a/briar-android/src/org/briarproject/android/groups/GroupItem.java b/briar-android/src/org/briarproject/android/groups/GroupItem.java index d3ec3cf03b99acab3289e493318af36edb9e2fb4..b9d95299633773d522eefbb5996d02182270324f 100644 --- a/briar-android/src/org/briarproject/android/groups/GroupItem.java +++ b/briar-android/src/org/briarproject/android/groups/GroupItem.java @@ -6,12 +6,10 @@ import org.briarproject.api.db.MessageHeader; class GroupItem { private final MessageHeader header; - private boolean expanded; private byte[] body; GroupItem(MessageHeader header) { this.header = header; - expanded = false; body = null; } @@ -19,14 +17,6 @@ class GroupItem { return header; } - boolean isExpanded() { - return expanded; - } - - void setExpanded(boolean expanded) { - this.expanded = expanded; - } - byte[] getBody() { return body; }