[android] Show Author alias in AuthorView

parent 0ee74654
...@@ -14,7 +14,6 @@ import android.view.ViewGroup; ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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
......
...@@ -31,8 +31,7 @@ class MemberListItemHolder extends RecyclerView.ViewHolder { ...@@ -31,8 +31,7 @@ class MemberListItemHolder extends RecyclerView.ViewHolder {
protected void bind(MemberListItem item) { protected void bind(MemberListItem item) {
// member name, avatar and author info // member name, avatar and author info
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) {
......
...@@ -43,9 +43,8 @@ public abstract class BaseThreadItemViewHolder<I extends ThreadItem> ...@@ -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);
......
...@@ -33,7 +33,9 @@ import android.view.View; ...@@ -33,7 +33,9 @@ import android.view.View;
import android.widget.TextView; 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.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;
...@@ -74,6 +76,17 @@ public class UiUtils { ...@@ -74,6 +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(Author author,
@Nullable String alias) {
String name = author.getName();
if (alias == null) return 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) {
...@@ -127,7 +140,9 @@ public class UiUtils { ...@@ -127,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);
} }
......
...@@ -26,6 +26,7 @@ import static android.graphics.Typeface.BOLD; ...@@ -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 { ...@@ -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 { ...@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment