Add bot indicator overlay to avatars (#1173)
* Add bot indicator overlay to avatars * Add bot overlay to account list in search view * Add preference for bot avatar overlay
This commit is contained in:
parent
63e4c1d4e0
commit
391cd12974
13 changed files with 115 additions and 34 deletions
|
|
@ -2,6 +2,8 @@ package com.keylesspalace.tusky.adapter;
|
|||
|
||||
import android.content.Context;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
|
@ -17,13 +19,17 @@ class AccountViewHolder extends RecyclerView.ViewHolder {
|
|||
private TextView username;
|
||||
private TextView displayName;
|
||||
private ImageView avatar;
|
||||
private ImageView avatarInset;
|
||||
private String accountId;
|
||||
private boolean showBotOverlay;
|
||||
|
||||
AccountViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
username = itemView.findViewById(R.id.account_username);
|
||||
displayName = itemView.findViewById(R.id.account_display_name);
|
||||
avatar = itemView.findViewById(R.id.account_avatar);
|
||||
avatarInset = itemView.findViewById(R.id.account_avatar_inset);
|
||||
showBotOverlay = PreferenceManager.getDefaultSharedPreferences(itemView.getContext()).getBoolean("showBotOverlay", true);
|
||||
}
|
||||
|
||||
void setupWithAccount(Account account) {
|
||||
|
|
@ -38,6 +44,13 @@ class AccountViewHolder extends RecyclerView.ViewHolder {
|
|||
.load(account.getAvatar())
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.into(avatar);
|
||||
if (showBotOverlay && account.getBot()) {
|
||||
avatarInset.setVisibility(View.VISIBLE);
|
||||
avatarInset.setImageResource(R.drawable.ic_bot_24dp);
|
||||
avatarInset.setBackgroundColor(0x50ffffff);
|
||||
} else {
|
||||
avatarInset.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
void setupActionListener(final AccountActionListener listener) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.keylesspalace.tusky.adapter;
|
|||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
|
@ -62,6 +63,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
private View sensitiveMediaShow;
|
||||
protected TextView mediaLabel;
|
||||
private ToggleButton contentWarningButton;
|
||||
protected ImageView avatarInset;
|
||||
|
||||
public ImageView avatar;
|
||||
public TextView timestampInfo;
|
||||
|
|
@ -71,6 +73,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
private boolean useAbsoluteTime;
|
||||
private SimpleDateFormat shortSdf;
|
||||
private SimpleDateFormat longSdf;
|
||||
private boolean showBotOverlay;
|
||||
|
||||
private final NumberFormat numberFormat = NumberFormat.getNumberInstance();
|
||||
|
||||
|
|
@ -82,7 +85,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
content = itemView.findViewById(R.id.status_content);
|
||||
avatar = itemView.findViewById(R.id.status_avatar);
|
||||
replyButton = itemView.findViewById(R.id.status_reply);
|
||||
reblogButton = itemView.findViewById(R.id.status_reblog);
|
||||
reblogButton = itemView.findViewById(R.id.status_inset);
|
||||
favouriteButton = itemView.findViewById(R.id.status_favourite);
|
||||
moreButton = itemView.findViewById(R.id.status_more);
|
||||
reblogged = false;
|
||||
|
|
@ -104,10 +107,12 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
mediaLabel = itemView.findViewById(R.id.status_media_label);
|
||||
contentWarningDescription = itemView.findViewById(R.id.status_content_warning_description);
|
||||
contentWarningButton = itemView.findViewById(R.id.status_content_warning_button);
|
||||
avatarInset = itemView.findViewById(R.id.status_avatar_inset);
|
||||
|
||||
this.useAbsoluteTime = useAbsoluteTime;
|
||||
shortSdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
longSdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault());
|
||||
showBotOverlay = PreferenceManager.getDefaultSharedPreferences(itemView.getContext()).getBoolean("showBotOverlay", true);
|
||||
}
|
||||
|
||||
protected abstract int getMediaPreviewHeight(Context context);
|
||||
|
|
@ -173,7 +178,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
}
|
||||
}
|
||||
|
||||
protected void setAvatar(String url, @Nullable String rebloggedUrl) {
|
||||
protected void setAvatar(String url, @Nullable String rebloggedUrl, boolean isBot) {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
avatar.setImageResource(R.drawable.avatar_default);
|
||||
} else {
|
||||
|
|
@ -182,6 +187,14 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
.placeholder(R.drawable.avatar_default)
|
||||
.into(avatar);
|
||||
}
|
||||
|
||||
if (showBotOverlay && isBot && TextUtils.isEmpty(rebloggedUrl)) {
|
||||
avatarInset.setVisibility(View.VISIBLE);
|
||||
avatarInset.setImageResource(R.drawable.ic_bot_24dp);
|
||||
avatarInset.setBackgroundColor(0x50ffffff);
|
||||
} else {
|
||||
avatarInset.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setCreatedAt(@Nullable Date createdAt) {
|
||||
|
|
@ -555,7 +568,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
setUsername(status.getNickname());
|
||||
setCreatedAt(status.getCreatedAt());
|
||||
setIsReply(status.getInReplyToId() != null);
|
||||
setAvatar(status.getAvatar(), status.getRebloggedAvatar());
|
||||
setAvatar(status.getAvatar(), status.getRebloggedAvatar(), status.isBot());
|
||||
setReblogged(status.isReblogged());
|
||||
setFavourited(status.isFavourited());
|
||||
List<Attachment> attachments = status.getAttachments();
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ package com.keylesspalace.tusky.adapter;
|
|||
|
||||
import android.content.Context;
|
||||
import android.text.InputFilter;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
|
@ -36,35 +37,28 @@ public class StatusViewHolder extends StatusBaseViewHolder {
|
|||
private static final InputFilter[] COLLAPSE_INPUT_FILTER = new InputFilter[]{SmartLengthInputFilter.INSTANCE};
|
||||
private static final InputFilter[] NO_INPUT_FILTER = new InputFilter[0];
|
||||
|
||||
private ImageView avatarReblog;
|
||||
private TextView rebloggedBar;
|
||||
private ToggleButton contentCollapseButton;
|
||||
|
||||
StatusViewHolder(View itemView, boolean useAbsoluteTime) {
|
||||
super(itemView, useAbsoluteTime);
|
||||
avatarReblog = itemView.findViewById(R.id.status_avatar_reblog);
|
||||
rebloggedBar = itemView.findViewById(R.id.status_reblogged);
|
||||
contentCollapseButton = itemView.findViewById(R.id.button_toggle_content);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAvatar(String url, @Nullable String rebloggedUrl) {
|
||||
super.setAvatar(url, rebloggedUrl);
|
||||
|
||||
protected void setAvatar(String url, @Nullable String rebloggedUrl, boolean isBot) {
|
||||
super.setAvatar(url, rebloggedUrl, isBot);
|
||||
Context context = avatar.getContext();
|
||||
boolean hasReblog = rebloggedUrl != null && !rebloggedUrl.isEmpty();
|
||||
int padding = hasReblog ? Utils.dpToPx(context, 12) : 0;
|
||||
|
||||
avatar.setPaddingRelative(0, 0, padding, padding);
|
||||
|
||||
if (hasReblog) {
|
||||
avatarReblog.setVisibility(View.VISIBLE);
|
||||
if (!TextUtils.isEmpty(rebloggedUrl)) {
|
||||
int padding = Utils.dpToPx(context, 12);
|
||||
avatar.setPaddingRelative(0, 0, padding, padding);
|
||||
avatarInset.setVisibility(View.VISIBLE);
|
||||
Picasso.with(context)
|
||||
.load(rebloggedUrl)
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.into(avatarReblog);
|
||||
} else {
|
||||
avatarReblog.setVisibility(View.GONE);
|
||||
.into(avatarInset);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue