From 0fe58e49b6437d6d699b90a6ab362697dcc90e40 Mon Sep 17 00:00:00 2001 From: Grishka Date: Fri, 29 Apr 2022 17:11:23 +0300 Subject: [PATCH] Display more relationship states + locked accounts closes #85, #73, #30 --- .../android/fragments/ProfileFragment.java | 27 ++++++++++- .../android/ui/utils/UiUtils.java | 46 +++++++++++++++---- .../res/drawable/bg_profile_follows_you.xml | 5 ++ .../ic_fluent_lock_closed_20_filled.xml | 3 ++ .../src/main/res/layout/fragment_profile.xml | 21 ++++++++- 5 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 mastodon/src/main/res/drawable/bg_profile_follows_you.xml create mode 100644 mastodon/src/main/res/drawable/ic_fluent_lock_closed_20_filled.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 0daf53b7..da6d464c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -14,6 +14,8 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.text.SpannableStringBuilder; +import android.text.TextUtils; +import android.text.style.ImageSpan; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; @@ -104,6 +106,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList private ProgressBar actionProgress; private FrameLayout[] tabViews; private TabLayoutMediator tabLayoutMediator; + private TextView followsYouView; private Account account; private String accountID; @@ -178,6 +181,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList bioEdit=content.findViewById(R.id.bio_edit); actionProgress=content.findViewById(R.id.action_progress); fab=content.findViewById(R.id.fab); + followsYouView=content.findViewById(R.id.follows_you); avatar.setOutlineProvider(new ViewOutlineProvider(){ @Override @@ -400,8 +404,25 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList HtmlParser.parseCustomEmoji(ssb, account.emojis); name.setText(ssb); setTitle(ssb); - username.setText('@'+account.acct); - bio.setText(HtmlParser.parse(account.note, account.emojis, Collections.emptyList(), Collections.emptyList(), accountID)); + if(account.locked){ + ssb=new SpannableStringBuilder("@"); + ssb.append(account.acct); + ssb.append(" "); + Drawable lock=username.getResources().getDrawable(R.drawable.ic_fluent_lock_closed_20_filled, 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_BOTTOM), 0); + username.setText(ssb); + }else{ + username.setText('@'+account.acct); + } + CharSequence parsedBio=HtmlParser.parse(account.note, account.emojis, Collections.emptyList(), Collections.emptyList(), accountID); + if(TextUtils.isEmpty(parsedBio)){ + bio.setVisibility(View.GONE); + }else{ + bio.setVisibility(View.VISIBLE); + bio.setText(parsedBio); + } followersCount.setText(UiUtils.abbreviateNumber(account.followersCount)); followingCount.setText(UiUtils.abbreviateNumber(account.followingCount)); postsCount.setText(UiUtils.abbreviateNumber(account.statusesCount)); @@ -565,6 +586,8 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList invalidateOptionsMenu(); actionButton.setVisibility(View.VISIBLE); UiUtils.setRelationshipToActionButton(relationship, actionButton); + actionProgress.setIndeterminateTintList(actionButton.getTextColors()); + followsYouView.setVisibility(relationship.followedBy ? View.VISIBLE : View.GONE); } private void onScrollChanged(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY){ 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 b442e8d7..85720f6c 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 @@ -141,12 +141,15 @@ public class UiUtils{ @SuppressLint("DefaultLocale") public static String abbreviateNumber(int n){ - if(n<1000) + if(n<1000){ return String.format("%,d", n); - else if(n<1_000_000) - return String.format("%,.1fK", n/1000f); - else - return String.format("%,.1fM", n/1_000_000f); + }else if(n<1_000_000){ + float a=n/1000f; + return a>99f ? String.format("%,dK", (int)Math.floor(a)) : String.format("%,.1fK", a); + }else{ + float a=n/1_000_000f; + return a>99f ? String.format("%,dM", (int)Math.floor(a)) : String.format("%,.1fM", n/1_000_000f); + } } /** @@ -340,13 +343,38 @@ public class UiUtils{ } public static void setRelationshipToActionButton(Relationship relationship, Button button){ + boolean secondaryStyle; if(relationship.blocking){ button.setText(R.string.button_blocked); - }else if(relationship.muting){ - button.setText(R.string.button_muted); + secondaryStyle=true; + }else if(relationship.blockedBy){ + button.setText(R.string.button_follow); + secondaryStyle=false; + }else if(relationship.requested){ + button.setText(R.string.button_follow_pending); + secondaryStyle=true; + }else if(!relationship.following){ + button.setText(relationship.followedBy ? R.string.follow_back : R.string.button_follow); + secondaryStyle=false; }else{ - button.setText(relationship.following ? R.string.button_following : R.string.button_follow); + button.setText(R.string.button_following); + secondaryStyle=true; } + + button.setEnabled(!relationship.blockedBy); + int attr=secondaryStyle ? R.attr.secondaryButtonStyle : android.R.attr.buttonStyle; + TypedArray ta=button.getContext().obtainStyledAttributes(new int[]{attr}); + int styleRes=ta.getResourceId(0, 0); + ta.recycle(); + ta=button.getContext().obtainStyledAttributes(styleRes, new int[]{android.R.attr.background}); + button.setBackground(ta.getDrawable(0)); + ta.recycle(); + ta=button.getContext().obtainStyledAttributes(styleRes, new int[]{android.R.attr.textColor}); + if(relationship.blocking) + button.setTextColor(button.getResources().getColorStateList(R.color.error_600)); + else + button.setTextColor(ta.getColorStateList(0)); + ta.recycle(); } public static void performAccountAction(Activity activity, Account account, String accountID, Relationship relationship, Button button, Consumer progressCallback, Consumer resultCallback){ @@ -356,7 +384,7 @@ public class UiUtils{ confirmToggleMuteUser(activity, accountID, account, true, resultCallback); }else{ progressCallback.accept(true); - new SetAccountFollowed(account.id, !relationship.following, true) + new SetAccountFollowed(account.id, !relationship.following && !relationship.requested, true) .setCallback(new Callback<>(){ @Override public void onSuccess(Relationship result){ diff --git a/mastodon/src/main/res/drawable/bg_profile_follows_you.xml b/mastodon/src/main/res/drawable/bg_profile_follows_you.xml new file mode 100644 index 00000000..a69ae89f --- /dev/null +++ b/mastodon/src/main/res/drawable/bg_profile_follows_you.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/mastodon/src/main/res/drawable/ic_fluent_lock_closed_20_filled.xml b/mastodon/src/main/res/drawable/ic_fluent_lock_closed_20_filled.xml new file mode 100644 index 00000000..38c6d39e --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_lock_closed_20_filled.xml @@ -0,0 +1,3 @@ + + + diff --git a/mastodon/src/main/res/layout/fragment_profile.xml b/mastodon/src/main/res/layout/fragment_profile.xml index 731e038b..620e6f99 100644 --- a/mastodon/src/main/res/layout/fragment_profile.xml +++ b/mastodon/src/main/res/layout/fragment_profile.xml @@ -22,7 +22,7 @@ + +