[android] Show Author alias in AuthorView

This commit is contained in:
Torsten Grote
2018-10-29 17:54:05 -03:00
parent 1423ca7a15
commit 7af4b3d3ca
5 changed files with 21 additions and 24 deletions

View File

@@ -14,7 +14,6 @@ import android.view.ViewGroup;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.TextView; import android.widget.TextView;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.R; import org.briarproject.briar.R;
import org.briarproject.briar.android.view.AuthorView; import org.briarproject.briar.android.view.AuthorView;
@@ -98,9 +97,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
// author and date // author and date
BlogPostHeader post = item.getPostHeader(); BlogPostHeader post = item.getPostHeader();
Author a = post.getAuthor(); author.setAuthor(post.getAuthor(), post.getAuthorInfo());
author.setAuthor(a);
author.setAuthorInfo(post.getAuthorInfo());
author.setDate(post.getTimestamp()); author.setDate(post.getTimestamp());
author.setPersona( author.setPersona(
item.isRssFeed() ? AuthorView.RSS_FEED : AuthorView.NORMAL); item.isRssFeed() ? AuthorView.RSS_FEED : AuthorView.NORMAL);
@@ -143,8 +140,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
private void onBindComment(BlogCommentItem item) { private void onBindComment(BlogCommentItem item) {
// reblogger // reblogger
reblogger.setAuthor(item.getAuthor()); reblogger.setAuthor(item.getAuthor(), item.getAuthorInfo());
reblogger.setAuthorInfo(item.getAuthorInfo());
reblogger.setDate(item.getTimestamp()); reblogger.setDate(item.getTimestamp());
if (!fullText) { if (!fullText) {
reblogger.setAuthorClickable(v -> listener.onAuthorClick(item)); reblogger.setAuthorClickable(v -> listener.onAuthorClick(item));
@@ -165,8 +161,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
AuthorView author = v.findViewById(R.id.authorView); AuthorView author = v.findViewById(R.id.authorView);
TextView text = v.findViewById(R.id.textView); TextView text = v.findViewById(R.id.textView);
author.setAuthor(c.getAuthor()); author.setAuthor(c.getAuthor(), c.getAuthorInfo());
author.setAuthorInfo(c.getAuthorInfo());
author.setDate(c.getTimestamp()); author.setDate(c.getTimestamp());
// TODO make author clickable #624 // TODO make author clickable #624

View File

@@ -31,8 +31,7 @@ class MemberListItemHolder extends RecyclerView.ViewHolder {
protected void bind(MemberListItem item) { protected void bind(MemberListItem item) {
// member name, avatar and status // member name, avatar and status
author.setAuthor(item.getMember()); author.setAuthor(item.getMember(), item.getAuthorInfo());
author.setAuthorInfo(item.getAuthorInfo());
// online status of visible contacts // online status of visible contacts
if (item.getContactId() != null) { if (item.getContactId() != null) {

View File

@@ -43,9 +43,8 @@ public abstract class BaseThreadItemViewHolder<I extends ThreadItem>
public void bind(I item, ThreadItemListener<I> listener) { public void bind(I item, ThreadItemListener<I> listener) {
textView.setText(StringUtils.trim(item.getText())); textView.setText(StringUtils.trim(item.getText()));
author.setAuthor(item.getAuthor()); author.setAuthor(item.getAuthor(), item.getAuthorInfo());
author.setDate(item.getTimestamp()); author.setDate(item.getTimestamp());
author.setAuthorInfo(item.getAuthorInfo());
if (item.isHighlighted()) { if (item.isHighlighted()) {
layout.setActivated(true); layout.setActivated(true);

View File

@@ -35,6 +35,7 @@ import android.widget.TextView;
import org.acra.ACRA; import org.acra.ACRA;
import org.briarproject.bramble.api.contact.Contact; import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault; import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault; import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.bramble.api.system.AndroidExecutor; import org.briarproject.bramble.api.system.AndroidExecutor;
@@ -75,13 +76,17 @@ public class UiUtils {
public static final int TEASER_LENGTH = 320; public static final int TEASER_LENGTH = 320;
public static final float GREY_OUT = 0.5f; public static final float GREY_OUT = 0.5f;
public static String getContactDisplayName(Contact c) { public static String getContactDisplayName(Author author,
String name = c.getAuthor().getName(); @Nullable String alias) {
String alias = c.getAlias(); String name = author.getName();
if (alias == null) return name; if (alias == null) return name;
else return String.format("%s (%s)", alias, name); else return String.format("%s (%s)", alias, name);
} }
public static String getContactDisplayName(Contact c) {
return getContactDisplayName(c.getAuthor(), c.getAlias());
}
public static void setError(TextInputLayout til, @Nullable String error, public static void setError(TextInputLayout til, @Nullable String error,
boolean set) { boolean set) {
if (set) { if (set) {
@@ -135,7 +140,9 @@ public class UiUtils {
return builder; return builder;
} }
public static Spanned getSpanned(String s) { public static Spanned getSpanned(@Nullable String s) {
// TODO move to HtmlCompat
// https://commonsware.com/blog/2018/05/29/at-last-htmlcompat.html
return Html.fromHtml(s); return Html.fromHtml(s);
} }

View File

@@ -26,6 +26,7 @@ import static android.graphics.Typeface.BOLD;
import static android.util.TypedValue.COMPLEX_UNIT_PX; import static android.util.TypedValue.COMPLEX_UNIT_PX;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.NONE; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.NONE;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
import static org.briarproject.briar.android.util.UiUtils.getContactDisplayName;
import static org.briarproject.briar.android.util.UiUtils.resolveAttribute; import static org.briarproject.briar.android.util.UiUtils.resolveAttribute;
@UiThread @UiThread
@@ -70,16 +71,12 @@ public class AuthorView extends ConstraintLayout {
this(context, null); this(context, null);
} }
public void setAuthor(Author author) { public void setAuthor(Author author, AuthorInfo authorInfo) {
authorName.setText(author.getName()); authorName
.setText(getContactDisplayName(author, authorInfo.getAlias()));
IdenticonDrawable d = new IdenticonDrawable(author.getId().getBytes()); IdenticonDrawable d = new IdenticonDrawable(author.getId().getBytes());
avatar.setImageDrawable(d); avatar.setImageDrawable(d);
invalidate();
requestLayout();
}
public void setAuthorInfo(AuthorInfo authorInfo) {
if (authorInfo.getStatus() != NONE) { if (authorInfo.getStatus() != NONE) {
trustIndicator.setTrustLevel(authorInfo.getStatus()); trustIndicator.setTrustLevel(authorInfo.getStatus());
trustIndicator.setVisibility(VISIBLE); trustIndicator.setVisibility(VISIBLE);
@@ -123,7 +120,7 @@ public class AuthorView extends ConstraintLayout {
* *
* Attention: RSS_FEED and RSS_FEED_REBLOGGED change the avatar * Attention: RSS_FEED and RSS_FEED_REBLOGGED change the avatar
* and override the one set by * and override the one set by
* {@link AuthorView#setAuthor(Author)}. * {@link AuthorView#setAuthor(Author, AuthorInfo)}.
*/ */
public void setPersona(int persona) { public void setPersona(int persona) {
switch (persona) { switch (persona) {