From 8cd55fc365dfbe11adec0f0732553c9dec1301f0 Mon Sep 17 00:00:00 2001 From: FineFindus <63370021+FineFindus@users.noreply.github.com> Date: Sun, 3 Sep 2023 21:34:22 +0200 Subject: [PATCH] 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 --- .../android/fragments/ProfileFragment.java | 32 ++++++----- .../displayitems/HeaderStatusDisplayItem.java | 6 +- .../res/drawable/ic_fluent_bot_20_filled.xml | 3 + mastodon/src/main/res/drawable/ic_lock.xml | 6 -- .../main/res/drawable/ic_lock_fill1_20px.xml | 9 --- .../main/res/layout/display_item_header.xml | 11 ++++ .../src/main/res/layout/fragment_profile.xml | 57 ++++++++++++++++--- 7 files changed, 84 insertions(+), 40 deletions(-) create mode 100644 mastodon/src/main/res/drawable/ic_fluent_bot_20_filled.xml delete mode 100644 mastodon/src/main/res/drawable/ic_lock.xml delete mode 100644 mastodon/src/main/res/drawable/ic_lock_fill1_20px.xml diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java index 8dd79cb1a..c159b2836 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -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); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java index 92e7b1e03..f639cbcf9 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java @@ -134,7 +134,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ public static class Holder extends StatusDisplayItem.Holder 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); diff --git a/mastodon/src/main/res/drawable/ic_fluent_bot_20_filled.xml b/mastodon/src/main/res/drawable/ic_fluent_bot_20_filled.xml new file mode 100644 index 000000000..260c2c92b --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_bot_20_filled.xml @@ -0,0 +1,3 @@ + + + diff --git a/mastodon/src/main/res/drawable/ic_lock.xml b/mastodon/src/main/res/drawable/ic_lock.xml deleted file mode 100644 index 5bd09e680..000000000 --- a/mastodon/src/main/res/drawable/ic_lock.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/mastodon/src/main/res/drawable/ic_lock_fill1_20px.xml b/mastodon/src/main/res/drawable/ic_lock_fill1_20px.xml deleted file mode 100644 index 728a4208e..000000000 --- a/mastodon/src/main/res/drawable/ic_lock_fill1_20px.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/mastodon/src/main/res/layout/display_item_header.xml b/mastodon/src/main/res/layout/display_item_header.xml index abf47a7bb..f3d18d939 100644 --- a/mastodon/src/main/res/layout/display_item_header.xml +++ b/mastodon/src/main/res/layout/display_item_header.xml @@ -173,6 +173,17 @@ android:textColor="?colorM3OnSurfaceVariant" tools:text="\@Gargron@mastodon.social"/> + + - + android:layout_marginStart="16dp" + android:layout_marginEnd="12dp" + android:layout_marginBottom="8dp"> + + + + + + + + + + + +