diff --git a/mastodon/build.gradle b/mastodon/build.gradle index aca406f2..cd0a6f70 100644 --- a/mastodon/build.gradle +++ b/mastodon/build.gradle @@ -13,8 +13,8 @@ android { applicationId "org.joinmastodon.android" minSdk 23 targetSdk 34 - versionCode 126 - versionName "2.8.0" + versionCode 128 + versionName "2.9.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetDomainBlockPreview.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetDomainBlockPreview.java new file mode 100644 index 00000000..a490b291 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetDomainBlockPreview.java @@ -0,0 +1,15 @@ +package org.joinmastodon.android.api.requests.accounts; + +import org.joinmastodon.android.api.MastodonAPIRequest; + +public class GetDomainBlockPreview extends MastodonAPIRequest{ + public GetDomainBlockPreview(String domain){ + super(HttpMethod.GET, "/domain_blocks/preview", Response.class); + addQueryParameter("domain", domain); + } + + public static class Response{ + public int followingCount; + public int followersCount; + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java index 85c89f1a..d253c22a 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java @@ -308,8 +308,9 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD if(!gap.visible){ gap.visible=true; gap.enteredFromTop=child.getTop() currentRequest; + + public BlockDomainConfirmationSheet(@NonNull Context context, Account user, ConfirmCallback confirmCallback, ConfirmCallback blockUserConfirmCallback, String accountID){ super(context, user, confirmCallback); titleView.setText(R.string.block_domain_confirm_title); confirmBtn.setText(R.string.do_block_server); secondaryBtn.setText(context.getString(R.string.block_user_x_instead, user.getDisplayUsername())); icon.setImageResource(R.drawable.ic_domain_disabled_24px); subtitleView.setText(user.getDomain()); + TextView relationsRow=addRow(R.drawable.ic_person_remove_24px, ""); addRow(R.drawable.ic_campaign_24px, R.string.users_cant_see_blocked); addRow(R.drawable.ic_visibility_off_24px, R.string.you_wont_see_server_posts); - addRow(R.drawable.ic_person_remove_24px, R.string.server_followers_will_be_removed); addRow(R.drawable.ic_reply_24px, R.string.server_cant_mention_or_follow_you); addRow(R.drawable.ic_history_24px, R.string.server_can_interact_with_older); @@ -32,5 +41,44 @@ public class BlockDomainConfirmationSheet extends AccountRestrictionConfirmation loading=false; }); }); + + relationsRow.setVisibility(View.GONE); + relationsRow.setTypeface(Typeface.DEFAULT_BOLD); + currentRequest=new GetDomainBlockPreview(user.getDomain()) + .setCallback(new Callback<>(){ + @Override + public void onSuccess(GetDomainBlockPreview.Response result){ + currentRequest=null; + if(result.followersCount>0 || result.followingCount>0){ + UiUtils.beginLayoutTransition(container); + relationsRow.setVisibility(View.VISIBLE); + if(result.followersCount>0 && result.followingCount>0){ + relationsRow.setText(context.getString(R.string.server_x_followers_and_following_will_be_removed, + context.getResources().getQuantityString(R.plurals.will_lose_x_followers, result.followersCount, result.followersCount), + context.getResources().getQuantityString(R.plurals.will_lose_x_following, result.followingCount, result.followingCount))); + }else if(result.followersCount>0){ + relationsRow.setText(context.getResources().getQuantityString(R.plurals.server_x_followers_will_be_removed, result.followersCount, result.followersCount)); + }else{ + relationsRow.setText(context.getString(R.string.server_x_following_will_be_removed, + context.getResources().getQuantityString(R.plurals.will_lose_x_following, result.followingCount, result.followingCount))); + } + } + } + + @Override + public void onError(ErrorResponse error){ + currentRequest=null; + } + }) + .exec(accountID); + } + + @Override + public void dismiss(){ + if(currentRequest!=null){ + currentRequest.cancel(); + currentRequest=null; + } + super.dismiss(); } } 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 d4694302..f6e83f8d 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 @@ -501,7 +501,7 @@ public class UiUtils{ } }) .exec(accountID); - }).show(); + }, accountID).show(); }else{ new SetDomainBlocked(account.getDomain(), false) .setCallback(new Callback<>(){ @@ -651,6 +651,9 @@ public class UiUtils{ } public static void updateList(List oldList, List newList, RecyclerView list, RecyclerView.Adapter adapter, BiPredicate areItemsSame){ + RecyclerView.ItemAnimator animator=list.getItemAnimator(); + if(animator!=null) + animator.endAnimations(); // Save topmost item position and offset because for some reason RecyclerView would scroll the list to weird places when you insert items at the top int topItem, topItemOffset; if(list.getChildCount()==0){ diff --git a/mastodon/src/main/res/layout/display_item_gap.xml b/mastodon/src/main/res/layout/display_item_gap.xml index cbc06a8b..6aec0c9f 100644 --- a/mastodon/src/main/res/layout/display_item_gap.xml +++ b/mastodon/src/main/res/layout/display_item_gap.xml @@ -1,5 +1,6 @@ @@ -9,10 +10,13 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" + android:layout_marginHorizontal="16dp" android:gravity="center_horizontal" android:textAppearance="@style/m3_body_large" android:textColor="?android:textColorSecondary" - android:text="@string/load_missing_posts"/> + android:maxLines="2" + android:ellipsize="end" + tools:text="@string/load_missing_posts_above"/> These are all the posts from all users in your server (%s). You might like these accounts based on others you follow. New posts - Load missing posts Follow back Pending Follows you @@ -675,7 +674,6 @@ Block %s instead You won’t see posts or notifications from users on this server. You won’t see any posts from users on this server. - Your followers from this server will be removed. Nobody from this server can follow you. People from this server can interact with your old posts. Unblocked domain %s @@ -840,4 +838,23 @@ %,d follower you know %,d followers you know + + + %,d follower from this server will be removed. + %,d followers from this server will be removed. + + + You will lose %1$s and %2$s. + + %,d follower + %,d followers + + + %,d person you follow + %,d people you follow + + + You will lose %s. + Load missing posts above + Load missing posts below \ No newline at end of file