Improved ConversationActivity (bug #32), but it's still not quite there.

GroupActivity needs to receive a similar treatment.
This commit is contained in:
akwizgran
2014-02-07 22:03:29 +00:00
parent 4154119ea5
commit 6a10688112
9 changed files with 130 additions and 65 deletions

View File

@@ -1,7 +1,9 @@
package org.briarproject.android.contact;
import static android.view.Gravity.CENTER_HORIZONTAL;
import static android.view.Gravity.CENTER_VERTICAL;
import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static java.text.DateFormat.SHORT;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
import static org.briarproject.api.Author.Status.VERIFIED;
@@ -12,6 +14,7 @@ import org.briarproject.R;
import org.briarproject.android.util.AuthorView;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.db.MessageHeader;
import org.briarproject.util.StringUtils;
import android.content.Context;
import android.content.res.Resources;
@@ -20,6 +23,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
class ConversationAdapter extends ArrayAdapter<ConversationItem> {
@@ -34,29 +38,53 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MessageHeader header = getItem(position).getHeader();
ConversationItem item = getItem(position);
MessageHeader header = item.getHeader();
Context ctx = getContext();
Resources res = ctx.getResources();
LinearLayout layout = new LinearLayout(ctx);
layout.setOrientation(HORIZONTAL);
layout.setGravity(CENTER_VERTICAL);
if(!header.isRead()) {
Resources res = ctx.getResources();
layout.setBackgroundColor(res.getColor(R.color.unread_background));
}
LinearLayout headerLayout = new LinearLayout(ctx);
headerLayout.setOrientation(HORIZONTAL);
headerLayout.setGravity(CENTER_VERTICAL);
int background;
if(header.isRead()) background = res.getColor(R.color.read_background);
else background = res.getColor(R.color.unread_background);
headerLayout.setBackgroundColor(background);
AuthorView authorView = new AuthorView(ctx);
authorView.setLayoutParams(WRAP_WRAP_1);
authorView.init(header.getAuthor().getName(), VERIFIED);
layout.addView(authorView);
headerLayout.addView(authorView);
TextView date = new TextView(ctx);
date.setTextSize(14);
date.setPadding(0, pad, pad, pad);
long then = header.getTimestamp(), now = System.currentTimeMillis();
date.setText(DateUtils.formatSameDayTime(then, now, SHORT, SHORT));
layout.addView(date);
headerLayout.addView(date);
return layout;
if(!item.isExpanded()) return headerLayout;
LinearLayout expanded = new LinearLayout(ctx);
expanded.setOrientation(VERTICAL);
expanded.setGravity(CENTER_HORIZONTAL);
expanded.setBackgroundColor(background);
expanded.addView(headerLayout);
byte[] body = item.getBody();
if(body == null) {
ProgressBar progress = new ProgressBar(ctx);
progress.setPadding(pad, 0, pad, pad);
progress.setIndeterminate(true);
expanded.addView(progress);
} 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(body));
expanded.addView(text);
}
return expanded;
}
}
}