From 35141524395a5393bec736baaa6ae40d384a9ac3 Mon Sep 17 00:00:00 2001 From: sk Date: Wed, 9 Nov 2022 23:28:48 +0100 Subject: [PATCH] fix issues with post notification button --- .../android/fragments/ProfileFragment.java | 25 +++++++---- .../android/ui/utils/UiUtils.java | 12 ++++- .../src/main/res/layout/fragment_profile.xml | 44 ++++++++++++++----- .../src/main/res/values-de-rDE/strings.xml | 4 +- mastodon/src/main/res/values/strings.xml | 4 +- 5 files changed, 64 insertions(+), 25 deletions(-) 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 db3a628be..0d16e8959 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -98,8 +98,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList private CoverImageView cover; private View avatarBorder; private TextView name, username, bio, followersCount, followersLabel, followingCount, followingLabel, postsCount, postsLabel; - private ProgressBarButton actionButton; - private Button notifyButton; + private ProgressBarButton actionButton, notifyButton; private ViewPager2 pager; private NestedRecyclerScrollView scrollView; private AccountTimelineFragment postsFragment, postsWithRepliesFragment, mediaFragment; @@ -110,7 +109,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList private float titleTransY; private View postsBtn, followersBtn, followingBtn; private EditText nameEdit, bioEdit; - private ProgressBar actionProgress; + private ProgressBar actionProgress, notifyProgress; private FrameLayout[] tabViews; private TabLayoutMediator tabLayoutMediator; private TextView followsYouView; @@ -190,6 +189,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList nameEdit=content.findViewById(R.id.name_edit); bioEdit=content.findViewById(R.id.bio_edit); actionProgress=content.findViewById(R.id.action_progress); + notifyProgress=content.findViewById(R.id.notify_progress); fab=content.findViewById(R.id.fab); followsYouView=content.findViewById(R.id.follows_you); @@ -455,9 +455,9 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList UiUtils.loadCustomEmojiInTextView(name); UiUtils.loadCustomEmojiInTextView(bio); + notifyButton.setVisibility(View.GONE); if(AccountSessionManager.getInstance().isSelf(accountID, account)){ actionButton.setText(R.string.edit_profile); - notifyButton.setVisibility(View.GONE); }else{ actionButton.setVisibility(View.GONE); } @@ -615,11 +615,14 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList private void updateRelationship(){ invalidateOptionsMenu(); actionButton.setVisibility(View.VISIBLE); - UiUtils.setRelationshipToActionButton(relationship, actionButton); - actionProgress.setIndeterminateTintList(actionButton.getTextColors()); - followsYouView.setVisibility(relationship.followedBy ? View.VISIBLE : View.GONE); notifyButton.setVisibility(relationship.following ? View.VISIBLE : View.GONE); + UiUtils.setRelationshipToActionButton(relationship, actionButton); + UiUtils.setRelationshipToActionButton(relationship, notifyButton, true); + actionProgress.setIndeterminateTintList(actionButton.getTextColors()); + notifyProgress.setIndeterminateTintList(notifyButton.getTextColors()); + followsYouView.setVisibility(relationship.followedBy ? View.VISIBLE : View.GONE); notifyButton.setSelected(relationship.notifying); + notifyButton.setContentDescription(getString(relationship.notifying ? R.string.user_post_notifications_on : R.string.user_post_notifications_off, '@'+account.username)); } private void onScrollChanged(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY){ @@ -685,6 +688,12 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList actionButton.setClickable(!visible); } + private void setNotifyProgressVisible(boolean visible){ + notifyButton.setTextVisible(!visible); + notifyProgress.setVisibility(visible ? View.VISIBLE : View.GONE); + notifyButton.setClickable(!visible); + } + private void loadAccountInfoAndEnterEditMode(){ if(editModeLoading) return; @@ -854,7 +863,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList } private void onNotifyButtonClick(View v) { - UiUtils.performToggleAccountNotifications(getActivity(), account, accountID, relationship, actionButton, this::updateRelationship); + UiUtils.performToggleAccountNotifications(getActivity(), account, accountID, relationship, actionButton, this::setNotifyProgressVisible, this::updateRelationship); } private void onAvatarClick(View v){ 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 261b35e6f..82528abca 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 @@ -400,6 +400,11 @@ public class UiUtils{ } public static void setRelationshipToActionButton(Relationship relationship, Button button){ + setRelationshipToActionButton(relationship, button, false); + } + + public static void setRelationshipToActionButton(Relationship relationship, Button button, boolean keepText){ + CharSequence textBefore = keepText ? button.getText() : null; boolean secondaryStyle; if(relationship.blocking){ button.setText(R.string.button_blocked); @@ -418,6 +423,8 @@ public class UiUtils{ secondaryStyle=true; } + if (keepText) button.setText(textBefore); + button.setEnabled(!relationship.blockedBy); int attr=secondaryStyle ? R.attr.secondaryButtonStyle : android.R.attr.buttonStyle; TypedArray ta=button.getContext().obtainStyledAttributes(new int[]{attr}); @@ -434,17 +441,20 @@ public class UiUtils{ ta.recycle(); } - public static void performToggleAccountNotifications(Activity activity, Account account, String accountID, Relationship relationship, Button button, Consumer resultCallback) { + public static void performToggleAccountNotifications(Activity activity, Account account, String accountID, Relationship relationship, Button button, Consumer progressCallback, Consumer resultCallback) { + progressCallback.accept(true); new SetAccountFollowed(account.id, true, relationship.showingReblogs, !relationship.notifying) .setCallback(new Callback<>() { @Override public void onSuccess(Relationship result) { resultCallback.accept(result); + progressCallback.accept(false); Toast.makeText(activity, activity.getString(result.notifying ? R.string.user_post_notifications_on : R.string.user_post_notifications_off, '@'+account.username), Toast.LENGTH_SHORT).show(); } @Override public void onError(ErrorResponse error) { + progressCallback.accept(false); error.showToast(activity); } }).exec(accountID); diff --git a/mastodon/src/main/res/layout/fragment_profile.xml b/mastodon/src/main/res/layout/fragment_profile.xml index d49662cc4..a3c9cb5c0 100644 --- a/mastodon/src/main/res/layout/fragment_profile.xml +++ b/mastodon/src/main/res/layout/fragment_profile.xml @@ -171,20 +171,40 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/profile_counters" - android:layout_alignParentEnd="true" - android:clipToPadding="false" - android:padding="16dp"> - -