feat: display icon for bots (#793)

* feat(profile): display bot icon for bots

* feat(status): display bot icon

* use 16sp size and 4sp spacing

* don't add lock/bot icon as image spans

---------

Co-authored-by: sk <sk22@mailbox.org>
This commit is contained in:
FineFindus 2023-09-03 21:34:22 +02:00 committed by GitHub
parent f14df2bb0f
commit 8cd55fc365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 84 additions and 40 deletions

View File

@ -4,10 +4,12 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
import android.app.assist.AssistContent;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Color;
@ -131,6 +133,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
private CoverImageView cover;
private View avatarBorder;
private TextView name, username, bio, followersCount, followersLabel, followingCount, followingLabel;
private ImageView lockIcon, botIcon;
private ProgressBarButton actionButton, notifyButton;
private ViewPager2 pager;
private NestedRecyclerScrollView scrollView;
@ -230,6 +233,8 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
avatarBorder=content.findViewById(R.id.avatar_border);
name=content.findViewById(R.id.name);
username=content.findViewById(R.id.username);
lockIcon=content.findViewById(R.id.lock_icon);
botIcon=content.findViewById(R.id.bot_icon);
bio=content.findViewById(R.id.bio);
followersCount=content.findViewById(R.id.followers_count);
followersLabel=content.findViewById(R.id.followers_label);
@ -347,7 +352,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
followersBtn.setOnClickListener(this::onFollowersOrFollowingClick);
followingBtn.setOnClickListener(this::onFollowersOrFollowingClick);
username.setOnClickListener(v->{
content.findViewById(R.id.username_wrap).setOnClickListener(v->{
try {
new GetInstance()
.setCallback(new Callback<>(){
@ -368,7 +373,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
.execRemote(Uri.parse(account.url).getHost());
} catch (NullPointerException ignored) {
// maybe the url was malformed?
Toast.makeText(getContext(), R.string.error, Toast.LENGTH_SHORT);
Toast.makeText(getContext(), R.string.error, Toast.LENGTH_SHORT).show();
}
});
@ -592,6 +597,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
}
}
@SuppressLint("SetTextI18n")
private void bindHeaderView(){
setTitle(account.displayName);
setSubtitle(getResources().getQuantityString(R.plurals.x_posts, (int)(account.statusesCount%1000), account.statusesCount));
@ -624,19 +630,15 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
String acct = ((isSelf || account.isRemote)
? account.getFullyQualifiedName()
: account.acct);
if(account.locked){
ssb=new SpannableStringBuilder("@");
ssb.append(acct);
ssb.append(" ");
Drawable lock=username.getResources().getDrawable(R.drawable.ic_lock, getActivity().getTheme()).mutate();
lock.setBounds(0, 0, lock.getIntrinsicWidth(), lock.getIntrinsicHeight());
lock.setTint(username.getCurrentTextColor());
ssb.append(getString(R.string.manually_approves_followers), new ImageSpan(lock, ImageSpan.ALIGN_BASELINE), 0);
username.setText(ssb);
}else{
// noinspection SetTextI18n
username.setText('@'+acct);
}
username.setText('@'+acct);
lockIcon.setVisibility(account.locked ? View.VISIBLE : View.GONE);
lockIcon.setImageTintList(ColorStateList.valueOf(username.getCurrentTextColor()));
botIcon.setVisibility(account.bot ? View.VISIBLE : View.GONE);
botIcon.setImageTintList(ColorStateList.valueOf(username.getCurrentTextColor()));
CharSequence parsedBio=HtmlParser.parse(account.note, account.emojis, Collections.emptyList(), Collections.emptyList(), accountID);
if(TextUtils.isEmpty(parsedBio)){
bio.setVisibility(View.GONE);

View File

@ -134,7 +134,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
public static class Holder extends StatusDisplayItem.Holder<HeaderStatusDisplayItem> implements ImageLoaderViewHolder{
private final TextView name, time, username, extraText, pronouns;
private final View collapseBtn, timeUsernameSeparator;
private final ImageView avatar, more, visibility, deleteNotification, unreadIndicator, markAsRead, collapseBtnIcon;
private final ImageView avatar, more, visibility, deleteNotification, unreadIndicator, markAsRead, collapseBtnIcon, botIcon;
private final PopupMenu optionsMenu;
private Relationship relationship;
private APIRequest<?> currentRelationshipRequest;
@ -148,6 +148,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
name=findViewById(R.id.name);
time=findViewById(R.id.time);
username=findViewById(R.id.username);
botIcon=findViewById(R.id.bot_icon);
timeUsernameSeparator=findViewById(R.id.separator);
avatar=findViewById(R.id.avatar);
more=findViewById(R.id.more);
@ -322,6 +323,9 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
this.time.setVisibility(time==null ? View.GONE : View.VISIBLE);
if(time!=null) this.time.setText(time);
botIcon.setVisibility(item.user.bot ? View.VISIBLE : View.GONE);
botIcon.setColorFilter(username.getCurrentTextColor());
deleteNotification.setVisibility(GlobalUserPreferences.enableDeleteNotifications && item.notification!=null && !item.inset ? View.VISIBLE : View.GONE);
if (item.hasVisibilityToggle){
boolean hidden = !item.status.sensitiveRevealed || (item.status.hasSpoiler() && !item.status.spoilerRevealed);

View File

@ -0,0 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="20dp" android:height="20dp" android:viewportWidth="20" android:viewportHeight="20">
<path android:pathData="M14.69 11.503c1 0 1.81 0.81 1.81 1.81v0.689h-0.005c-0.034 0.78-0.248 1.757-1.123 2.555C14.416 17.43 12.765 18 10 18c-2.766 0-4.416-0.57-5.372-1.443-0.875-0.798-1.089-1.776-1.123-2.555H3.5v-0.69c0-0.999 0.81-1.809 1.81-1.809h9.38zM6.5 3C5.672 3 5 3.672 5 4.5v4C5 9.328 5.672 10 6.5 10h7c0.828 0 1.5-0.672 1.5-1.5v-4C15 3.672 14.328 3 13.5 3h-3V2.5C10.5 2.191 10.276 2 10 2S9.5 2.23 9.5 2.5V3h-3zM7 6.5c0-0.552 0.448-1 1-1s1 0.448 1 1-0.448 1-1 1-1-0.448-1-1zm4 0c0-0.552 0.448-1 1-1s1 0.448 1 1-0.448 1-1 1-1-0.448-1-1z" android:fillColor="@color/fluent_default_icon_tint"/>
</vector>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="16dp" android:height="16dp" android:viewportWidth="16" android:viewportHeight="16">
<group android:translateX="-2" android:translateY="-1">
<path android:pathData="M10 2c1.657 0 3 1.343 3 3v1h1c1.105 0 2 0.895 2 2v7c0 1.105-0.895 2-2 2H6c-1.105 0-2-0.895-2-2V8c0-1.105 0.895-2 2-2h1V5c0-1.657 1.343-3 3-3zm0 8.5c-0.552 0-1 0.448-1 1s0.448 1 1 1 1-0.448 1-1-0.448-1-1-1zM10 4C9.448 4 9 4.448 9 5v1h2V5c0-0.552-0.448-1-1-1z" android:fillColor="@color/fluent_default_icon_tint"/>
</group>
</vector>

View File

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="20"
android:viewportHeight="20">
<path
android:fillColor="@android:color/white"
android:pathData="M5.5,19Q4.875,19 4.438,18.562Q4,18.125 4,17.5V9.5Q4,8.875 4.438,8.438Q4.875,8 5.5,8H6V6Q6,4.333 7.167,3.167Q8.333,2 10,2Q11.667,2 12.833,3.167Q14,4.333 14,6V8H14.5Q15.125,8 15.562,8.438Q16,8.875 16,9.5V17.5Q16,18.125 15.562,18.562Q15.125,19 14.5,19ZM7.5,8H12.5V6Q12.5,4.958 11.771,4.229Q11.042,3.5 10,3.5Q8.958,3.5 8.229,4.229Q7.5,4.958 7.5,6ZM10,15Q10.625,15 11.062,14.562Q11.5,14.125 11.5,13.5Q11.5,12.875 11.062,12.438Q10.625,12 10,12Q9.375,12 8.938,12.438Q8.5,12.875 8.5,13.5Q8.5,14.125 8.938,14.562Q9.375,15 10,15Z"/>
</vector>

View File

@ -173,6 +173,17 @@
android:textColor="?colorM3OnSurfaceVariant"
tools:text="\@Gargron@mastodon.social"/>
<ImageView
android:id="@+id/bot_icon"
android:layout_width="16sp"
android:layout_height="16sp"
android:layout_marginStart="4sp"
android:layout_gravity="center_vertical"
android:visibility="gone"
android:importantForAccessibility="no"
android:contentDescription="@string/sk_icon_bot"
android:src="@drawable/ic_fluent_bot_20_filled" />
<TextView
android:id="@+id/separator"
android:layout_width="wrap_content"

View File

@ -167,17 +167,56 @@
</org.joinmastodon.android.ui.views.AutoOrientationLinearLayout>
<TextView
android:id="@+id/username"
<org.joinmastodon.android.ui.views.AutoOrientationLinearLayout
android:id="@+id/username_wrap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:paddingTop="2dp"
android:paddingBottom="8dp"
android:layout_marginRight="16dp"
android:textAppearance="@style/m3_title_small"
android:textColor="?colorM3OnSurfaceVariant"
tools:text="\@Gargron" />
android:layout_marginStart="16dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="8dp">
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginEnd="4dp"
android:maxLines="1"
android:ellipsize="end"
android:textAppearance="@style/m3_title_small"
android:textColor="?colorM3OnSurfaceVariant"
tools:text="\@Gargron" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="2dp">
<ImageView
android:id="@+id/lock_icon"
android:layout_width="18sp"
android:layout_height="18sp"
android:layout_marginEnd="4dp"
android:layout_gravity="center_vertical"
android:visibility="gone"
android:importantForAccessibility="no"
android:contentDescription="@string/manually_approves_followers"
android:src="@drawable/ic_fluent_lock_closed_20_filled" />
<ImageView
android:id="@+id/bot_icon"
android:layout_width="18sp"
android:layout_height="18sp"
android:layout_marginEnd="4dp"
android:layout_gravity="center_vertical"
android:visibility="gone"
android:importantForAccessibility="no"
android:contentDescription="@string/sk_icon_bot"
android:src="@drawable/ic_fluent_bot_20_filled" />
</LinearLayout>
</org.joinmastodon.android.ui.views.AutoOrientationLinearLayout>
<org.joinmastodon.android.ui.views.LinkedTextView
android:id="@+id/bio"