Skip to content

Commit

Permalink
fix(account-cards): add the progressbar for the accept and decline fo…
Browse files Browse the repository at this point in the history
…llow request actions
  • Loading branch information
LucasGGamerM committed Jul 26, 2024
1 parent ca07240 commit 9f5c420
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Relationship> resultCallback) {
public static void handleFollowRequest(Activity activity, Account account, String accountID, @Nullable String notificationID, boolean accepted, Relationship relationship, Consumer<Boolean> progressCallback, Consumer<Relationship> 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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 9f5c420

Please sign in to comment.