From 9f5c420e6635edb4a54bf50c219adf6489a2df29 Mon Sep 17 00:00:00 2001 From: LucasGGamerM Date: Fri, 26 Jul 2024 14:54:21 -0300 Subject: [PATCH] fix(account-cards): add the progressbar for the accept and decline follow request actions --- .../fragments/FollowRequestsListFragment.java | 13 ++++++++++++- .../displayitems/AccountCardStatusDisplayItem.java | 13 ++++++++++++- .../org/joinmastodon/android/ui/utils/UiUtils.java | 7 ++++++- 3 files changed, 30 insertions(+), 3 deletions(-) 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 0750be8e47..52bdbf2b34 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowRequestsListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowRequestsListFragment.java @@ -319,7 +319,18 @@ public void onClick(){ private void onFollowRequestButtonClick(View v) { itemView.setHasTransientState(true); - UiUtils.handleFollowRequest((Activity) v.getContext(), item.account, accountID, null, v == acceptButton, relationship, rel -> { + UiUtils.handleFollowRequest((Activity) v.getContext(), item.account, accountID, null, v == acceptButton, relationship, (Boolean visible) -> { + if(v==acceptButton){ + acceptButton.setTextVisible(!visible); + acceptProgress.setVisibility(visible ? View.VISIBLE : View.GONE); + acceptButton.setClickable(!visible); + }else{ + rejectButton.setTextVisible(!visible); + rejectProgress.setVisibility(visible ? View.VISIBLE : View.GONE); + rejectButton.setClickable(!visible); + } + itemView.setHasTransientState(false); + }, rel -> { if(getContext()==null) return; itemView.setHasTransientState(false); relationships.put(item.account.id, rel); 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 0321d615b4..5fce579a28 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 @@ -172,7 +172,18 @@ public void onBind(AccountCardStatusDisplayItem item){ private void onFollowRequestButtonClick(View v) { itemView.setHasTransientState(true); - UiUtils.handleFollowRequest((Activity) v.getContext(), item.account, item.parentFragment.getAccountID(), null, v == acceptButton, relationship, rel -> { + UiUtils.handleFollowRequest((Activity) v.getContext(), item.account, item.parentFragment.getAccountID(), null, v == acceptButton, relationship, (Boolean visible) -> { + if(v==acceptButton){ + acceptButton.setTextVisible(!visible); + acceptProgress.setVisibility(visible ? View.VISIBLE : View.GONE); + acceptButton.setClickable(!visible); + }else{ + rejectButton.setTextVisible(!visible); + rejectProgress.setVisibility(visible ? View.VISIBLE : View.GONE); + rejectButton.setClickable(!visible); + } + itemView.setHasTransientState(false); + }, rel -> { if(v.getContext()==null || rel==null) return; itemView.setHasTransientState(false); item.parentFragment.putRelationship(item.account.id, rel); 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 59e604952c..82b13b21b1 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 @@ -934,17 +934,20 @@ public void onError(ErrorResponse error){ } - public static void handleFollowRequest(Activity activity, Account account, String accountID, @Nullable String notificationID, boolean accepted, Relationship relationship, Consumer resultCallback) { + public static void handleFollowRequest(Activity activity, Account account, String accountID, @Nullable String notificationID, boolean accepted, Relationship relationship, Consumer progressCallback, Consumer resultCallback) { + progressCallback.accept(true); if (accepted) { new AuthorizeFollowRequest(account.id).setCallback(new Callback<>() { @Override public void onSuccess(Relationship rel) { E.post(new FollowRequestHandledEvent(accountID, true, account, rel)); + progressCallback.accept(false); resultCallback.accept(rel); } @Override public void onError(ErrorResponse error) { + progressCallback.accept(false); resultCallback.accept(relationship); error.showToast(activity); } @@ -956,11 +959,13 @@ public void onSuccess(Relationship rel) { E.post(new FollowRequestHandledEvent(accountID, false, account, rel)); if (notificationID != null) E.post(new NotificationDeletedEvent(notificationID)); + progressCallback.accept(false); resultCallback.accept(rel); } @Override public void onError(ErrorResponse error) { + progressCallback.accept(false); resultCallback.accept(relationship); error.showToast(activity); }