Migrate AuthorView to XML, add identicon

This commit is contained in:
str4d
2016-01-05 07:19:10 +00:00
parent 88d81634ca
commit 35c59fdb39
5 changed files with 100 additions and 34 deletions

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<im.delight.android.identicons.SymmetricIdenticon
android:id="@+id/identiconView"
android:layout_width="@dimen/listitem_picture_size"
android:layout_height="@dimen/listitem_picture_size"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/listitem_horizontal_margin"
android:layout_marginStart="@dimen/listitem_horizontal_margin"/>
<ImageView
android:id="@+id/statusView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/identity_anonymous"/>
<TextView
android:id="@+id/nameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/margin_small"
android:layout_marginLeft="@dimen/listitem_text_left_margin"
android:layout_marginRight="@dimen/margin_small"
android:layout_marginStart="@dimen/listitem_text_left_margin"
android:layout_toLeftOf="@id/statusView"
android:layout_toStartOf="@id/statusView"
android:ellipsize="end"
android:singleLine="true"
android:text="@string/anonymous"
android:textSize="@dimen/text_size_medium"/>
</RelativeLayout>

View File

@@ -18,6 +18,7 @@ import org.briarproject.android.util.ElasticHorizontalSpace;
import org.briarproject.android.util.HorizontalBorder; import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.ListLoadingProgressBar; import org.briarproject.android.util.ListLoadingProgressBar;
import org.briarproject.api.android.AndroidNotificationManager; import org.briarproject.api.android.AndroidNotificationManager;
import org.briarproject.api.android.ReferenceManager;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.NoSuchMessageException; import org.briarproject.api.db.NoSuchMessageException;
import org.briarproject.api.db.NoSuchSubscriptionException; import org.briarproject.api.db.NoSuchSubscriptionException;
@@ -70,6 +71,8 @@ public class ForumActivity extends BriarActivity implements EventListener,
private ListLoadingProgressBar loading = null; private ListLoadingProgressBar loading = null;
private ImageButton composeButton = null, shareButton = null; private ImageButton composeButton = null, shareButton = null;
@Inject private ReferenceManager referenceManager;
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject private volatile ForumManager forumManager; @Inject private volatile ForumManager forumManager;
@Inject private volatile EventBus eventBus; @Inject private volatile EventBus eventBus;
@@ -366,7 +369,8 @@ public class ForumActivity extends BriarActivity implements EventListener,
i.putExtra("briar.FORUM_NAME", forum.getName()); i.putExtra("briar.FORUM_NAME", forum.getName());
i.putExtra("briar.MESSAGE_ID", header.getId().getBytes()); i.putExtra("briar.MESSAGE_ID", header.getId().getBytes());
Author author = header.getAuthor(); Author author = header.getAuthor();
if (author != null) i.putExtra("briar.AUTHOR_NAME", author.getName()); if (author != null) i.putExtra("briar.AUTHOR_HANDLE",
referenceManager.putReference(author, Author.class));
i.putExtra("briar.AUTHOR_STATUS", header.getAuthorStatus().name()); i.putExtra("briar.AUTHOR_STATUS", header.getAuthorStatus().name());
i.putExtra("briar.CONTENT_TYPE", header.getContentType()); i.putExtra("briar.CONTENT_TYPE", header.getContentType());
i.putExtra("briar.TIMESTAMP", header.getTimestamp()); i.putExtra("briar.TIMESTAMP", header.getTimestamp());

View File

@@ -55,8 +55,7 @@ class ForumAdapter extends ArrayAdapter<ForumItem> {
AuthorView authorView = new AuthorView(ctx); AuthorView authorView = new AuthorView(ctx);
authorView.setLayoutParams(WRAP_WRAP_1); authorView.setLayoutParams(WRAP_WRAP_1);
Author author = header.getAuthor(); Author author = header.getAuthor();
if (author == null) authorView.init(null, header.getAuthorStatus()); authorView.init(author, header.getAuthorStatus());
else authorView.init(author.getName(), header.getAuthorStatus());
headerLayout.addView(authorView); headerLayout.addView(authorView);
TextView date = new TextView(ctx); TextView date = new TextView(ctx);

View File

@@ -17,6 +17,7 @@ import org.briarproject.android.util.AuthorView;
import org.briarproject.android.util.ElasticHorizontalSpace; import org.briarproject.android.util.ElasticHorizontalSpace;
import org.briarproject.android.util.HorizontalBorder; import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.LayoutUtils; import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.android.ReferenceManager;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.NoSuchMessageException; import org.briarproject.api.db.NoSuchMessageException;
import org.briarproject.api.forum.ForumManager; import org.briarproject.api.forum.ForumManager;
@@ -56,6 +57,8 @@ implements OnClickListener {
private TextView content = null; private TextView content = null;
private int position = -1; private int position = -1;
@Inject private ReferenceManager referenceManager;
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@Inject private volatile ForumManager forumManager; @Inject private volatile ForumManager forumManager;
private volatile MessageId messageId = null; private volatile MessageId messageId = null;
@@ -82,7 +85,9 @@ implements OnClickListener {
if (minTimestamp == -1) throw new IllegalStateException(); if (minTimestamp == -1) throw new IllegalStateException();
position = i.getIntExtra("briar.POSITION", -1); position = i.getIntExtra("briar.POSITION", -1);
if (position == -1) throw new IllegalStateException(); if (position == -1) throw new IllegalStateException();
String authorName = i.getStringExtra("briar.AUTHOR_NAME"); long authorHandle = i.getLongExtra("briar.AUTHOR_HANDLE", -1);
if (authorHandle == -1) throw new IllegalStateException();
Author author = referenceManager.removeReference(authorHandle, Author.class);
String s = i.getStringExtra("briar.AUTHOR_STATUS"); String s = i.getStringExtra("briar.AUTHOR_STATUS");
if (s == null) throw new IllegalStateException(); if (s == null) throw new IllegalStateException();
Author.Status authorStatus = Author.Status.valueOf(s); Author.Status authorStatus = Author.Status.valueOf(s);
@@ -102,10 +107,10 @@ implements OnClickListener {
header.setOrientation(HORIZONTAL); header.setOrientation(HORIZONTAL);
header.setGravity(CENTER_VERTICAL); header.setGravity(CENTER_VERTICAL);
AuthorView author = new AuthorView(this); AuthorView authorView = new AuthorView(this);
author.setLayoutParams(WRAP_WRAP_1); authorView.setLayoutParams(WRAP_WRAP_1);
author.init(authorName, authorStatus); authorView.init(author, authorStatus);
header.addView(author); header.addView(authorView);
int pad = LayoutUtils.getPadding(this); int pad = LayoutUtils.getPadding(this);

View File

@@ -1,42 +1,62 @@
package org.briarproject.android.util; package org.briarproject.android.util;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import org.briarproject.R; import org.briarproject.R;
import org.briarproject.api.identity.Author; import org.briarproject.api.identity.Author;
import static android.text.TextUtils.TruncateAt.END; import im.delight.android.identicons.IdenticonView;
public class AuthorView extends RelativeLayout { public class AuthorView extends FrameLayout {
private IdenticonView identiconView;
private TextView nameView;
private ImageView statusView;
public AuthorView(Context ctx) { public AuthorView(Context ctx) {
super(ctx); super(ctx);
initViews();
} }
public void init(String name, Author.Status status) { public AuthorView(Context context, AttributeSet attrs) {
Context ctx = getContext(); super(context, attrs);
int pad = LayoutUtils.getPadding(ctx);
TextView nameView = new TextView(ctx); initViews();
nameView.setId(1); }
nameView.setTextSize(18);
nameView.setSingleLine(); public AuthorView(Context context, AttributeSet attrs,
nameView.setEllipsize(END); int defStyle) {
nameView.setPadding(pad, pad, pad, pad); super(context, attrs, defStyle);
if (name == null) nameView.setText(R.string.anonymous);
else nameView.setText(name); initViews();
LayoutParams leftOf = CommonLayoutParams.relative(); }
leftOf.addRule(ALIGN_PARENT_LEFT);
leftOf.addRule(CENTER_VERTICAL); private void initViews() {
leftOf.addRule(LEFT_OF, 2); if (isInEditMode())
addView(nameView, leftOf); return;
View v = LayoutInflater.from(getContext()).inflate(
R.layout.author_view, this, true);
identiconView = (IdenticonView) v.findViewById(R.id.identiconView);
nameView = (TextView) v.findViewById(R.id.nameView);
statusView = (ImageView) v.findViewById(R.id.statusView);
}
public void init(Author author, Author.Status status) {
if (author == null) nameView.setText(R.string.anonymous);
else {
identiconView.show(author.getId().getBytes());
nameView.setText(author.getName());
}
ImageView statusView = new ImageView(ctx);
statusView.setId(2);
statusView.setPadding(0, pad, pad, pad);
switch(status) { switch(status) {
case ANONYMOUS: case ANONYMOUS:
statusView.setImageResource(R.drawable.identity_anonymous); statusView.setImageResource(R.drawable.identity_anonymous);
@@ -51,9 +71,5 @@ public class AuthorView extends RelativeLayout {
statusView.setImageResource(R.drawable.identity_verified); statusView.setImageResource(R.drawable.identity_verified);
break; break;
} }
LayoutParams right = CommonLayoutParams.relative();
right.addRule(ALIGN_PARENT_RIGHT);
right.addRule(CENTER_VERTICAL);
addView(statusView, right);
} }
} }