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 43f48482c0..365e8c6e4c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -877,7 +877,7 @@ public boolean onOptionsItemSelected(MenuItem item){ }else if(id==R.id.open_in_browser){ UiUtils.launchWebBrowser(getActivity(), account.url); }else if(id==R.id.block_domain){ - UiUtils.confirmToggleBlockDomain(getActivity(), accountID, account.getDomain(), relationship.domainBlocking, ()->{ + UiUtils.confirmToggleBlockDomain(getActivity(), accountID, account, relationship.domainBlocking, ()->{ relationship.domainBlocking=!relationship.domainBlocking; updateRelationship(); }); 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 58b8285e6f..cf93a9cf4c 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 @@ -279,7 +279,7 @@ public void onError(ErrorResponse error){ Toast.makeText(activity, activity.getString(rel.following ? R.string.followed_user : rel.requested ? R.string.following_user_requested : R.string.unfollowed_user, account.getDisplayUsername()), Toast.LENGTH_SHORT).show(); }); }else if(id==R.id.block_domain){ - UiUtils.confirmToggleBlockDomain(activity, item.parentFragment.getAccountID(), account.getDomain(), relationship!=null && relationship.domainBlocking, ()->{}); + UiUtils.confirmToggleBlockDomain(activity, item.parentFragment.getAccountID(), account, relationship!=null && relationship.domainBlocking, ()->{}); }else if(id==R.id.bookmark){ AccountSessionManager.getInstance().getAccount(item.accountID).getStatusInteractionController().setBookmarked(item.status, !item.status.bookmarked); }else if(id==R.id.manage_user_lists){ 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 69b20f7c74..5bc7c22c3d 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 @@ -123,6 +123,7 @@ import org.joinmastodon.android.ui.sheets.AccountSwitcherSheet; import org.joinmastodon.android.ui.sheets.BlockAccountConfirmationSheet; import org.joinmastodon.android.ui.sheets.MuteAccountConfirmationSheet; +import org.joinmastodon.android.ui.sheets.BlockDomainConfirmationSheet; import org.joinmastodon.android.ui.text.CustomEmojiSpan; import org.joinmastodon.android.ui.text.HtmlParser; import org.joinmastodon.android.utils.Tracking; @@ -574,27 +575,61 @@ public void onError(ErrorResponse error) { ); } - public static void confirmToggleBlockDomain(Activity activity, String accountID, String domain, boolean currentlyBlocked, Runnable resultCallback) { - showConfirmationAlert(activity, activity.getString(currentlyBlocked ? R.string.confirm_unblock_domain_title : R.string.confirm_block_domain_title), - activity.getString(currentlyBlocked ? R.string.confirm_unblock : R.string.confirm_block, domain), - activity.getString(currentlyBlocked ? R.string.do_unblock : R.string.do_block), - R.drawable.ic_fluent_shield_28_regular, - () -> { - new SetDomainBlocked(domain, !currentlyBlocked) - .setCallback(new Callback<>() { - @Override - public void onSuccess(Object result) { - resultCallback.run(); - } + public static void confirmToggleBlockDomain(Activity activity, String accountID, Account account, boolean currentlyBlocked, Runnable resultCallback){ + if(!currentlyBlocked){ + new BlockDomainConfirmationSheet(activity, account, (onSuccess, onError)->{ + new SetDomainBlocked(account.getDomain(), true) + .setCallback(new Callback<>(){ + @Override + public void onSuccess(Object result){ + resultCallback.run(); + onSuccess.run(); + } - @Override - public void onError(ErrorResponse error) { - error.showToast(activity); - } - }) - .wrapProgress(activity, R.string.loading, false) - .exec(accountID); - }); + @Override + public void onError(ErrorResponse error){ + error.showToast(activity); + onError.run(); + } + }) + .exec(accountID); + }, (onSuccess, onError)->{ + new SetAccountBlocked(account.id, true) + .setCallback(new Callback<>(){ + @Override + public void onSuccess(Relationship result){ + resultCallback.run(); + onSuccess.run(); + E.post(new RemoveAccountPostsEvent(accountID, account.id, false)); + } + + @Override + public void onError(ErrorResponse error){ + error.showToast(activity); + onError.run(); + } + }) + .exec(accountID); + }).show(); + }else{ + new SetDomainBlocked(account.getDomain(), false) + .setCallback(new Callback<>(){ + @Override + public void onSuccess(Object result){ + resultCallback.run(); + new Snackbar.Builder(activity) + .setText(activity.getString(R.string.unblocked_domain_x, account.getDomain())) + .show(); + } + + @Override + public void onError(ErrorResponse error){ + error.showToast(activity); + } + }) + .wrapProgress(activity, R.string.loading, false) + .exec(accountID); + } } public static void confirmToggleMuteUser(Context context, String accountID, Account account, boolean currentlyMuted, Consumer resultCallback){ if(!currentlyMuted){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/viewholders/AccountViewHolder.java b/mastodon/src/main/java/org/joinmastodon/android/ui/viewholders/AccountViewHolder.java index a18175f769..724cb34c0d 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/viewholders/AccountViewHolder.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/viewholders/AccountViewHolder.java @@ -312,7 +312,7 @@ private boolean onContextMenuItemSelected(MenuItem item){ }else if(id==R.id.open_in_browser){ UiUtils.launchWebBrowser(fragment.getActivity(), account.url); }else if(id==R.id.block_domain){ - UiUtils.confirmToggleBlockDomain(fragment.getActivity(), accountID, account.getDomain(), relationship.domainBlocking, ()->{ + UiUtils.confirmToggleBlockDomain(fragment.getActivity(), accountID, account, relationship.domainBlocking, ()->{ relationship.domainBlocking=!relationship.domainBlocking; bindRelationship(); });