mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
New Trust Level Indicator Replaces The Stars
This implements a generic `TrustIndicatorView` with a `setTrustLevel()` method which updates the drawable according to the `Author.State`. Closes #78
This commit is contained in:
@@ -29,6 +29,7 @@ import org.briarproject.android.BriarActivity;
|
||||
import org.briarproject.android.api.AndroidNotificationManager;
|
||||
import org.briarproject.android.controller.handler.UiResultHandler;
|
||||
import org.briarproject.android.util.BriarRecyclerView;
|
||||
import org.briarproject.android.util.TrustIndicatorView;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
@@ -275,6 +276,7 @@ public class ForumActivity extends BriarActivity implements
|
||||
public final TextView textView, lvlText, dateText, repliesText;
|
||||
public final View[] lvls;
|
||||
public final ImageView avatar;
|
||||
final TrustIndicatorView trust;
|
||||
public final View chevron, replyButton;
|
||||
public final ViewGroup cell;
|
||||
public final View bottomDivider;
|
||||
@@ -295,6 +297,7 @@ public class ForumActivity extends BriarActivity implements
|
||||
lvls[i] = v.findViewById(nestedLineIds[i]);
|
||||
}
|
||||
avatar = (ImageView) v.findViewById(R.id.avatar);
|
||||
trust = (TrustIndicatorView) v.findViewById(R.id.trustIndicator);
|
||||
chevron = v.findViewById(R.id.chevron);
|
||||
replyButton = v.findViewById(R.id.btn_reply);
|
||||
cell = (ViewGroup) v.findViewById(R.id.forum_cell);
|
||||
@@ -513,6 +516,7 @@ public class ForumActivity extends BriarActivity implements
|
||||
ui.dateText.setText(DateUtils
|
||||
.getRelativeTimeSpanString(ForumActivity.this,
|
||||
data.getTimestamp()) + " " + data.getAuthor());
|
||||
ui.trust.setTrustLevel(data.getStatus());
|
||||
|
||||
int replies = getReplyCount(data);
|
||||
if (replies == 0) {
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
package org.briarproject.android.forum;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.text.format.DateUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.AuthorView;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.api.forum.ForumPostHeader;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
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 org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
|
||||
|
||||
class ForumAdapter extends ArrayAdapter<ForumItem> {
|
||||
|
||||
private final int pad;
|
||||
|
||||
ForumAdapter(Context ctx) {
|
||||
super(ctx, android.R.layout.simple_expandable_list_item_1,
|
||||
new ArrayList<ForumItem>());
|
||||
pad = LayoutUtils.getPadding(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ForumItem item = getItem(position);
|
||||
ForumPostHeader header = item.getHeader();
|
||||
Context ctx = getContext();
|
||||
Resources res = ctx.getResources();
|
||||
|
||||
LinearLayout layout = new LinearLayout(ctx);
|
||||
layout.setOrientation(VERTICAL);
|
||||
layout.setGravity(CENTER_HORIZONTAL);
|
||||
if (!header.isRead())
|
||||
layout.setBackgroundColor(res.getColor(R.color.unread_background));
|
||||
|
||||
LinearLayout headerLayout = new LinearLayout(ctx);
|
||||
headerLayout.setOrientation(HORIZONTAL);
|
||||
headerLayout.setGravity(CENTER_VERTICAL);
|
||||
|
||||
AuthorView authorView = new AuthorView(ctx);
|
||||
authorView.setLayoutParams(WRAP_WRAP_1);
|
||||
authorView.setPadding(0, pad, pad, pad);
|
||||
Author author = header.getAuthor();
|
||||
if (author == null) {
|
||||
authorView.init(null, null, header.getAuthorStatus());
|
||||
} else {
|
||||
authorView.init(author.getName(), author.getId(),
|
||||
header.getAuthorStatus());
|
||||
}
|
||||
headerLayout.addView(authorView);
|
||||
|
||||
TextView date = new TextView(ctx);
|
||||
date.setPadding(pad, pad, pad, pad);
|
||||
long timestamp = header.getTimestamp();
|
||||
date.setText(DateUtils.getRelativeTimeSpanString(ctx, timestamp));
|
||||
headerLayout.addView(date);
|
||||
layout.addView(headerLayout);
|
||||
|
||||
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.setText(StringUtils.fromUtf8(item.getBody()));
|
||||
layout.addView(text);
|
||||
} else {
|
||||
ImageButton attachment = new ImageButton(ctx);
|
||||
attachment.setPadding(pad, 0, pad, pad);
|
||||
attachment.setImageResource(R.drawable.content_attachment);
|
||||
layout.addView(attachment);
|
||||
}
|
||||
|
||||
return layout;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.briarproject.android.forum;
|
||||
|
||||
import org.briarproject.api.forum.ForumPostHeader;
|
||||
import org.briarproject.api.identity.Author.Status;
|
||||
import org.briarproject.api.identity.AuthorId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
@@ -12,23 +13,25 @@ public class ForumEntry {
|
||||
private final long timestamp;
|
||||
private final String author;
|
||||
private final AuthorId authorId;
|
||||
private Status status;
|
||||
private boolean isShowingDescendants = true;
|
||||
private boolean isRead = true;
|
||||
|
||||
public ForumEntry(ForumPostHeader h, String text, int level) {
|
||||
this(h.getId(), text, level, h.getTimestamp(), h.getAuthor().getName(),
|
||||
h.getAuthor().getId());
|
||||
h.getAuthor().getId(), h.getAuthorStatus());
|
||||
this.isRead = h.isRead();
|
||||
}
|
||||
|
||||
public ForumEntry(MessageId messageId, String text, int level,
|
||||
long timestamp, String author, AuthorId authorId) {
|
||||
long timestamp, String author, AuthorId authorId, Status status) {
|
||||
this.messageId = messageId;
|
||||
this.text = text;
|
||||
this.level = level;
|
||||
this.timestamp = timestamp;
|
||||
this.author = author;
|
||||
this.authorId = authorId;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
@@ -51,6 +54,10 @@ public class ForumEntry {
|
||||
return authorId;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public boolean isShowingDescendants() {
|
||||
return isShowingDescendants;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.api.identity.Author.Status.UNVERIFIED;
|
||||
|
||||
public class ForumTestControllerImpl implements ForumController {
|
||||
|
||||
private static final Logger LOG =
|
||||
@@ -115,7 +117,7 @@ public class ForumTestControllerImpl implements ForumController {
|
||||
forumEntries[e] =
|
||||
new ForumEntry(new MessageId(b), SAGA.substring(0, i[e]),
|
||||
l[e], timestamp, AUTHORS[authorIndex],
|
||||
AUTHOR_ID[authorIndex]);
|
||||
AUTHOR_ID[authorIndex], UNVERIFIED);
|
||||
}
|
||||
LOG.info("forum entries: " + forumEntries.length);
|
||||
resultHandler.onResult(true);
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
package org.briarproject.android.util;
|
||||
|
||||
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.TextView;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.api.crypto.CryptoComponent;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.identity.AuthorId;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import im.delight.android.identicons.IdenticonDrawable;
|
||||
|
||||
public class AuthorView extends FrameLayout {
|
||||
|
||||
private ImageView avatarView;
|
||||
private TextView nameView;
|
||||
private ImageView statusView;
|
||||
|
||||
public AuthorView(Context ctx) {
|
||||
super(ctx);
|
||||
|
||||
initViews();
|
||||
}
|
||||
|
||||
public AuthorView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
initViews();
|
||||
}
|
||||
|
||||
public AuthorView(Context context, AttributeSet attrs,
|
||||
int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
initViews();
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
if (isInEditMode())
|
||||
return;
|
||||
|
||||
View v = LayoutInflater.from(getContext()).inflate(
|
||||
R.layout.author_view, this, true);
|
||||
|
||||
avatarView = (ImageView) v.findViewById(R.id.avatarView);
|
||||
nameView = (TextView) v.findViewById(R.id.nameView);
|
||||
statusView = (ImageView) v.findViewById(R.id.statusView);
|
||||
}
|
||||
|
||||
public void init(String name, AuthorId id, Author.Status status) {
|
||||
if (name == null) {
|
||||
nameView.setText(R.string.anonymous);
|
||||
} else {
|
||||
nameView.setText(name);
|
||||
avatarView.setImageDrawable(
|
||||
new IdenticonDrawable(id.getBytes()));
|
||||
}
|
||||
|
||||
switch(status) {
|
||||
case ANONYMOUS:
|
||||
statusView.setImageResource(R.drawable.identity_anonymous);
|
||||
break;
|
||||
case UNKNOWN:
|
||||
statusView.setImageResource(R.drawable.identity_unknown);
|
||||
break;
|
||||
case UNVERIFIED:
|
||||
statusView.setImageResource(R.drawable.identity_unverified);
|
||||
break;
|
||||
case VERIFIED:
|
||||
statusView.setImageResource(R.drawable.identity_verified);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.briarproject.android.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.api.identity.Author.Status;
|
||||
|
||||
public class TrustIndicatorView extends ImageView {
|
||||
|
||||
public TrustIndicatorView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public TrustIndicatorView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public TrustIndicatorView(Context context, AttributeSet attrs,
|
||||
int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public void setTrustLevel(Status status) {
|
||||
int res;
|
||||
switch (status) {
|
||||
case ANONYMOUS:
|
||||
res = R.drawable.trust_indicator_anonymous;
|
||||
break;
|
||||
case UNVERIFIED:
|
||||
res = R.drawable.trust_indicator_unverified;
|
||||
break;
|
||||
case VERIFIED:
|
||||
res = R.drawable.trust_indicator_verified;
|
||||
break;
|
||||
default:
|
||||
res = R.drawable.trust_indicator_unknown;
|
||||
}
|
||||
setImageDrawable(ContextCompat.getDrawable(getContext(), res));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user