From fc09514a4d49e5bc34a53717dfaf64c9662ad41d Mon Sep 17 00:00:00 2001 From: sk Date: Tue, 17 Oct 2023 00:28:00 +0200 Subject: [PATCH] the pronouns are stored in the balls (extra text) also, improve max-width behavior --- .../android/fragments/ComposeFragment.java | 7 +++--- .../fragments/FollowRequestsListFragment.java | 2 +- .../discover/DiscoverAccountsFragment.java | 2 +- .../AccountCardStatusDisplayItem.java | 2 +- .../displayitems/HeaderStatusDisplayItem.java | 5 ++-- .../android/ui/utils/UiUtils.java | 24 +++++++++---------- .../ui/views/HeaderSubtitleLinearLayout.java | 10 ++++---- .../main/res/layout/display_item_header.xml | 14 ----------- 8 files changed, 25 insertions(+), 41 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java index 0853b33f4a..5ea2d7ff8a 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java @@ -150,7 +150,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr public LinearLayout mainLayout; private SizeListenerLinearLayout contentView; - private TextView selfName, selfUsername, selfExtraText, extraText, pronouns; + private TextView selfName, selfUsername, selfExtraText, extraText; private ImageView selfAvatar; private Account self; private String instanceDomain; @@ -626,7 +626,6 @@ public void afterTextChanged(Editable s){ }); View originalPost=view.findViewById(R.id.original_post); extraText=view.findViewById(R.id.extra_text); - pronouns=view.findViewById(R.id.pronouns); originalPost.setVisibility(View.VISIBLE); originalPost.setOnClickListener(v->{ Bundle args=new Bundle(); @@ -1455,8 +1454,8 @@ private void updateScheduledAt(Instant scheduledAt) { } private void updateHeaders() { - UiUtils.setExtraTextInfo(getContext(), selfExtraText, null, false, false, localOnly || statusVisibility==StatusPrivacy.LOCAL, null); - if (replyTo != null) UiUtils.setExtraTextInfo(getContext(), extraText, pronouns, true, false, replyTo.localOnly || replyTo.visibility==StatusPrivacy.LOCAL, replyTo.account); + UiUtils.setExtraTextInfo(getContext(), selfExtraText, false, false, localOnly || statusVisibility==StatusPrivacy.LOCAL, null); + if (replyTo != null) UiUtils.setExtraTextInfo(getContext(), extraText, true, false, replyTo.localOnly || replyTo.visibility==StatusPrivacy.LOCAL, replyTo.account); } private void buildVisibilityPopup(View v){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowRequestsListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowRequestsListFragment.java index 2a443e4361..37faab2bcc 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowRequestsListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowRequestsListFragment.java @@ -271,7 +271,7 @@ public void onBind(AccountWrapper item){ followingCount.setVisibility(item.account.followingCount < 0 ? View.GONE : View.VISIBLE); followingLabel.setVisibility(item.account.followingCount < 0 ? View.GONE : View.VISIBLE); relationship=relationships.get(item.account.id); - UiUtils.setExtraTextInfo(getContext(), null, findViewById(R.id.pronouns), true, false, false, item.account); + UiUtils.setExtraTextInfo(getContext(), null, true, false, false, item.account); if(relationship==null || !relationship.followedBy){ actionWrap.setVisibility(View.GONE); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverAccountsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverAccountsFragment.java index 324d4f24c0..dead031d00 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverAccountsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverAccountsFragment.java @@ -261,7 +261,7 @@ public void onBind(AccountWrapper item){ followingCount.setVisibility(item.account.followingCount < 0 ? View.GONE : View.VISIBLE); followingLabel.setVisibility(item.account.followingCount < 0 ? View.GONE : View.VISIBLE); relationship=relationships.get(item.account.id); - UiUtils.setExtraTextInfo(getContext(), null, findViewById(R.id.pronouns), true, false, false, item.account); + UiUtils.setExtraTextInfo(getContext(), null, true, false, false, item.account); if(relationship==null){ actionWrap.setVisibility(View.GONE); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/AccountCardStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/AccountCardStatusDisplayItem.java index 9c7394ae5a..f7863374d6 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/AccountCardStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/AccountCardStatusDisplayItem.java @@ -149,7 +149,7 @@ public void onBind(AccountCardStatusDisplayItem item){ followingCount.setVisibility(item.account.followingCount < 0 ? View.GONE : View.VISIBLE); followingLabel.setVisibility(item.account.followingCount < 0 ? View.GONE : View.VISIBLE); relationship=item.parentFragment.getRelationship(item.account.id); - UiUtils.setExtraTextInfo(item.parentFragment.getContext(), null, findViewById(R.id.pronouns), true, false, false, item.account); + UiUtils.setExtraTextInfo(item.parentFragment.getContext(), null,true, false, false, item.account); if(item.notification.type==Notification.Type.FOLLOW_REQUEST && (relationship==null || !relationship.followedBy)){ actionWrap.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 3f502982b7..f07102ad5a 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 @@ -137,7 +137,7 @@ public ImageLoaderRequest getImageRequest(int index){ } public static class Holder extends StatusDisplayItem.Holder implements ImageLoaderViewHolder{ - private final TextView name, time, username, extraText, pronouns; + private final TextView name, time, username, extraText; private final View collapseBtn, timeUsernameSeparator; private final ImageView avatar, more, visibility, deleteNotification, unreadIndicator, markAsRead, collapseBtnIcon, botIcon; private final PopupMenu optionsMenu; @@ -164,7 +164,6 @@ protected Holder(Activity activity, @LayoutRes int layout, ViewGroup parent){ collapseBtn=findViewById(R.id.collapse_btn); collapseBtnIcon=findViewById(R.id.collapse_btn_icon); extraText=findViewById(R.id.extra_text); - pronouns=findViewById(R.id.pronouns); avatar.setOnClickListener(this::onAvaClick); avatar.setOutlineProvider(OutlineProviders.roundedRect(12)); avatar.setClipToOutline(true); @@ -332,7 +331,7 @@ else if (item.status != null && item.status.editedAt != null) if(TextUtils.isEmpty(item.extraText)){ if (item.status != null) { boolean displayPronouns=item.parentFragment instanceof ThreadFragment ? GlobalUserPreferences.displayPronounsInThreads : GlobalUserPreferences.displayPronounsInTimelines; - UiUtils.setExtraTextInfo(item.parentFragment.getContext(), extraText, pronouns, displayPronouns, item.status.visibility==StatusPrivacy.DIRECT, item.status.localOnly || item.status.visibility==StatusPrivacy.LOCAL, item.status.account); + UiUtils.setExtraTextInfo(item.parentFragment.getContext(), extraText, displayPronouns, item.status.visibility==StatusPrivacy.DIRECT, item.status.localOnly || item.status.visibility==StatusPrivacy.LOCAL, item.status.account); } }else{ extraText.setVisibility(View.VISIBLE); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java index d15e4642db..2fbce45efd 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java @@ -1110,23 +1110,21 @@ public static MenuItem makeBackItem(Menu m) { return back; } - public static boolean setExtraTextInfo(Context ctx, @Nullable TextView extraText, @Nullable TextView pronouns, boolean displayPronouns, boolean mentionedOnly, boolean localOnly, @Nullable Account account) { - List extraParts = extraText!=null && (localOnly || mentionedOnly) ? new ArrayList<>() : null; - Optional p=pronouns==null || !displayPronouns ? Optional.empty() : extractPronouns(ctx, account); - if(p.isPresent()) { - HtmlParser.setTextWithCustomEmoji(pronouns, p.get(), account.emojis); - pronouns.setVisibility(View.VISIBLE); - }else if(pronouns!=null){ - pronouns.setVisibility(View.GONE); - } + public static boolean setExtraTextInfo(Context ctx, @Nullable TextView extraText, boolean displayPronouns, boolean mentionedOnly, boolean localOnly, @Nullable Account account) { + List extraParts=new ArrayList<>(); + Optional p=!displayPronouns ? Optional.empty() : extractPronouns(ctx, account); + if(localOnly) extraParts.add(ctx.getString(R.string.sk_inline_local_only)); if(mentionedOnly) extraParts.add(ctx.getString(R.string.sk_inline_direct)); - if(extraText!=null && extraParts!=null && !extraParts.isEmpty()) { - String sepp = ctx.getString(R.string.sk_separator); - String text = String.join(" " + sepp + " ", extraParts); - if(account == null) extraText.setText(text); + if(p.isPresent() && extraParts.isEmpty()) + extraParts.add(p.get()); + + if(extraText!=null && !extraParts.isEmpty()) { + String sepp=ctx.getString(R.string.sk_separator); + String text=String.join(" " + sepp + " ", extraParts); + if(account==null) extraText.setText(text); else HtmlParser.setTextWithCustomEmoji(extraText, text, account.emojis); extraText.setVisibility(View.VISIBLE); return true; diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/views/HeaderSubtitleLinearLayout.java b/mastodon/src/main/java/org/joinmastodon/android/ui/views/HeaderSubtitleLinearLayout.java index 15d6802897..c45fd36643 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/views/HeaderSubtitleLinearLayout.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/views/HeaderSubtitleLinearLayout.java @@ -36,10 +36,12 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){ LayoutParams lp=(LayoutParams) v.getLayoutParams(); remainingWidth-=v.getMeasuredWidth()+lp.leftMargin+lp.rightMargin; } - View first=getChildAt(0); - if(first instanceof TextView){ - // guaranteeing at least 64dp of width for the display name - ((TextView) first).setMaxWidth(Math.max(remainingWidth, V.dp(64))); + if(getChildAt(0) instanceof TextView first){ + // guaranteeing at least 64sp of width for the display name + first.setMaxWidth(Math.max(remainingWidth, V.sp(64))); + } + if(getChildAt(1) instanceof TextView second){ + second.setMaxWidth(Math.max(remainingWidth, V.sp(120))); } }else{ View first=getChildAt(0); diff --git a/mastodon/src/main/res/layout/display_item_header.xml b/mastodon/src/main/res/layout/display_item_header.xml index 28444aac62..cf3d6d6e5d 100644 --- a/mastodon/src/main/res/layout/display_item_header.xml +++ b/mastodon/src/main/res/layout/display_item_header.xml @@ -125,20 +125,6 @@ android:gravity="start|center_vertical" tools:text="Eugen" /> - -