Show rating icons in private message activities.

This keeps the visual language consistent: rating icon plus name equals
author.
This commit is contained in:
akwizgran
2013-04-15 11:24:41 +01:00
parent 5a365f6ce9
commit 85875a4e6c
5 changed files with 52 additions and 18 deletions

View File

@@ -132,7 +132,7 @@ implements OnClickListener {
header.setGravity(CENTER_VERTICAL);
thumb = new ImageView(this);
thumb.setPadding(0, 10, 10, 10);
thumb.setPadding(10, 10, 10, 10);
if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good);
else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad);
else thumb.setImageResource(R.drawable.rating_unrated);
@@ -143,7 +143,7 @@ implements OnClickListener {
author.setLayoutParams(WRAP_WRAP_1);
author.setTextSize(18);
author.setMaxLines(1);
author.setPadding(10, 10, 10, 10);
author.setPadding(0, 10, 10, 10);
if(authorName == null) {
author.setTextColor(res.getColor(R.color.anonymous_author));
author.setText(R.string.anonymous);

View File

@@ -130,7 +130,7 @@ implements OnClickListener {
header.setGravity(CENTER_VERTICAL);
thumb = new ImageView(this);
thumb.setPadding(0, 10, 10, 10);
thumb.setPadding(10, 10, 10, 10);
if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good);
else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad);
else thumb.setImageResource(R.drawable.rating_unrated);
@@ -141,7 +141,7 @@ implements OnClickListener {
author.setLayoutParams(WRAP_WRAP_1);
author.setTextSize(18);
author.setMaxLines(1);
author.setPadding(10, 10, 10, 10);
author.setPadding(0, 10, 10, 10);
if(authorName == null) {
author.setTextColor(res.getColor(R.color.anonymous_author));
author.setText(R.string.anonymous);

View File

@@ -223,10 +223,11 @@ implements DatabaseListener, OnClickListener, OnItemClickListener {
Intent i = new Intent(this, ReadPrivateMessageActivity.class);
i.putExtra("net.sf.briar.CONTACT_ID", contactId.getInt());
i.putExtra("net.sf.briar.CONTACT_NAME", contactName);
i.putExtra("net.sf.briar.AUTHOR_NAME", item.getAuthor().getName());
i.putExtra("net.sf.briar.RATING", item.getRating().toString());
i.putExtra("net.sf.briar.MESSAGE_ID", item.getId().getBytes());
i.putExtra("net.sf.briar.CONTENT_TYPE", item.getContentType());
i.putExtra("net.sf.briar.TIMESTAMP", item.getTimestamp());
i.putExtra("net.sf.briar.INCOMING", item.isIncoming());
startActivityForResult(i, position);
}
}

View File

@@ -1,16 +1,20 @@
package net.sf.briar.android.messages;
import static android.graphics.Typeface.BOLD;
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 net.sf.briar.android.widgets.CommonLayoutParams.WRAP_WRAP_1;
import static net.sf.briar.api.messaging.Rating.BAD;
import static net.sf.briar.api.messaging.Rating.GOOD;
import java.util.ArrayList;
import net.sf.briar.R;
import net.sf.briar.android.widgets.HorizontalSpace;
import net.sf.briar.api.db.PrivateMessageHeader;
import net.sf.briar.api.messaging.Rating;
import android.content.Context;
import android.content.res.Resources;
import android.text.format.DateUtils;
@@ -45,12 +49,27 @@ class ConversationAdapter extends ArrayAdapter<PrivateMessageHeader> {
innerLayout.setLayoutParams(WRAP_WRAP_1);
innerLayout.setOrientation(VERTICAL);
LinearLayout authorLayout = new LinearLayout(ctx);
authorLayout.setOrientation(HORIZONTAL);
authorLayout.setGravity(CENTER_VERTICAL);
ImageView thumb = new ImageView(ctx);
thumb.setPadding(10, 10, 10, 10);
Rating rating = item.getRating();
if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good);
else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad);
else thumb.setImageResource(R.drawable.rating_unrated);
authorLayout.addView(thumb);
TextView name = new TextView(ctx);
// Give me all the unused width
name.setLayoutParams(WRAP_WRAP_1);
name.setTextSize(18);
name.setMaxLines(1);
name.setPadding(10, 10, 10, 10);
name.setPadding(0, 10, 10, 10);
name.setText(item.getAuthor().getName());
innerLayout.addView(name);
authorLayout.addView(name);
innerLayout.addView(authorLayout);
if(item.getContentType().equals("text/plain")) {
TextView subject = new TextView(ctx);

View File

@@ -10,6 +10,9 @@ import static java.util.logging.Level.WARNING;
import static net.sf.briar.android.widgets.CommonLayoutParams.MATCH_WRAP;
import static net.sf.briar.android.widgets.CommonLayoutParams.MATCH_WRAP_1;
import static net.sf.briar.android.widgets.CommonLayoutParams.WRAP_WRAP_1;
import static net.sf.briar.api.messaging.Rating.BAD;
import static net.sf.briar.api.messaging.Rating.GOOD;
import static net.sf.briar.api.messaging.Rating.UNRATED;
import java.io.UnsupportedEncodingException;
import java.util.concurrent.Executor;
@@ -28,6 +31,7 @@ import net.sf.briar.api.db.DatabaseComponent;
import net.sf.briar.api.db.DbException;
import net.sf.briar.api.db.NoSuchMessageException;
import net.sf.briar.api.messaging.MessageId;
import net.sf.briar.api.messaging.Rating;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
@@ -35,6 +39,7 @@ import android.text.format.DateUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
@@ -56,6 +61,7 @@ implements OnClickListener {
@Inject private BundleEncrypter bundleEncrypter;
private ContactId contactId = null;
private Rating rating = UNRATED;
private boolean read;
private ImageButton readButton = null, prevButton = null, nextButton = null;
private ImageButton replyButton = null;
@@ -77,6 +83,11 @@ implements OnClickListener {
String contactName = i.getStringExtra("net.sf.briar.CONTACT_NAME");
if(contactName == null) throw new IllegalStateException();
setTitle(contactName);
String authorName = i.getStringExtra("net.sf.briar.AUTHOR_NAME");
if(authorName == null) throw new IllegalStateException();
String r = i.getStringExtra("net.sf.briar.RATING");
if(r == null) throw new IllegalStateException();
rating = Rating.valueOf(r);
byte[] b = i.getByteArrayExtra("net.sf.briar.MESSAGE_ID");
if(b == null) throw new IllegalStateException();
messageId = new MessageId(b);
@@ -84,7 +95,6 @@ implements OnClickListener {
if(contentType == null) throw new IllegalStateException();
long timestamp = i.getLongExtra("net.sf.briar.TIMESTAMP", -1);
if(timestamp == -1) throw new IllegalStateException();
boolean incoming = i.getBooleanExtra("net.sf.briar.INCOMING", false);
if(state != null && bundleEncrypter.decrypt(state)) {
read = state.getBoolean("net.sf.briar.READ");
@@ -111,17 +121,21 @@ implements OnClickListener {
header.setOrientation(HORIZONTAL);
header.setGravity(CENTER_VERTICAL);
TextView name = new TextView(this);
ImageView thumb = new ImageView(this);
thumb.setPadding(10, 10, 10, 10);
if(rating == GOOD) thumb.setImageResource(R.drawable.rating_good);
else if(rating == BAD) thumb.setImageResource(R.drawable.rating_bad);
else thumb.setImageResource(R.drawable.rating_unrated);
header.addView(thumb);
TextView author = new TextView(this);
// Give me all the unused width
name.setLayoutParams(WRAP_WRAP_1);
name.setTextSize(18);
name.setMaxLines(1);
name.setPadding(10, 10, 10, 10);
String format;
if(incoming) format = res.getString(R.string.format_from);
else format = res.getString(R.string.format_to);
name.setText(String.format(format, contactName));
header.addView(name);
author.setLayoutParams(WRAP_WRAP_1);
author.setTextSize(18);
author.setMaxLines(1);
author.setPadding(0, 10, 10, 10);
author.setText(authorName);
header.addView(author);
TextView date = new TextView(this);
date.setTextSize(14);