From 134bd13d6033c0ad52ff1be004cf801fd4744964 Mon Sep 17 00:00:00 2001 From: Grishka Date: Tue, 12 Nov 2024 18:49:05 +0300 Subject: [PATCH 1/3] Show followers/following number when blocking a server (AND-233) --- mastodon/build.gradle | 4 +- .../accounts/GetDomainBlockPreview.java | 15 ++++++ .../AccountRestrictionConfirmationSheet.java | 5 +- .../sheets/BlockDomainConfirmationSheet.java | 52 ++++++++++++++++++- .../android/ui/utils/UiUtils.java | 2 +- mastodon/src/main/res/values/strings.xml | 18 ++++++- 6 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetDomainBlockPreview.java diff --git a/mastodon/build.gradle b/mastodon/build.gradle index aca406f2..ea7946c1 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 127 + 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/ui/sheets/AccountRestrictionConfirmationSheet.java b/mastodon/src/main/java/org/joinmastodon/android/ui/sheets/AccountRestrictionConfirmationSheet.java index accda39a..2322b124 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/sheets/AccountRestrictionConfirmationSheet.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/sheets/AccountRestrictionConfirmationSheet.java @@ -66,10 +66,10 @@ public abstract class AccountRestrictionConfirmationSheet extends BottomSheet{ }); } - protected void addRow(@DrawableRes int icon, CharSequence text){ + protected TextView addRow(@DrawableRes int icon, CharSequence text){ TextView tv=new TextView(getContext()); tv.setTextAppearance(R.style.m3_body_large); - tv.setTextColor(UiUtils.getThemeColor(getContext(), R.attr.colorM3OnSurfaceVariant)); + tv.setTextColor(UiUtils.getThemeColor(getContext(), R.attr.colorM3OnSurface)); tv.setCompoundDrawableTintList(ColorStateList.valueOf(UiUtils.getThemeColor(getContext(), R.attr.colorM3Primary))); tv.setGravity(Gravity.START | Gravity.CENTER_VERTICAL); tv.setText(text); @@ -78,6 +78,7 @@ public abstract class AccountRestrictionConfirmationSheet extends BottomSheet{ tv.setCompoundDrawablesRelative(drawable, null, null, null); tv.setCompoundDrawablePadding(V.dp(16)); contentWrap.addView(tv, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + return tv; } protected void addRow(@DrawableRes int icon, @StringRes int text){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/sheets/BlockDomainConfirmationSheet.java b/mastodon/src/main/java/org/joinmastodon/android/ui/sheets/BlockDomainConfirmationSheet.java index f0602a99..52f115b8 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/sheets/BlockDomainConfirmationSheet.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/sheets/BlockDomainConfirmationSheet.java @@ -1,24 +1,33 @@ package org.joinmastodon.android.ui.sheets; import android.content.Context; +import android.graphics.Typeface; import android.view.View; +import android.widget.TextView; import org.joinmastodon.android.R; +import org.joinmastodon.android.api.requests.accounts.GetDomainBlockPreview; import org.joinmastodon.android.model.Account; +import org.joinmastodon.android.ui.utils.UiUtils; import androidx.annotation.NonNull; +import me.grishka.appkit.api.APIRequest; +import me.grishka.appkit.api.Callback; +import me.grishka.appkit.api.ErrorResponse; public class BlockDomainConfirmationSheet extends AccountRestrictionConfirmationSheet{ - public BlockDomainConfirmationSheet(@NonNull Context context, Account user, ConfirmCallback confirmCallback, ConfirmCallback blockUserConfirmCallback){ + private APIRequest 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..13bcb2a3 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<>(){ diff --git a/mastodon/src/main/res/values/strings.xml b/mastodon/src/main/res/values/strings.xml index dd33e870..a44fd66b 100644 --- a/mastodon/src/main/res/values/strings.xml +++ b/mastodon/src/main/res/values/strings.xml @@ -675,7 +675,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 +839,21 @@ %,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. \ No newline at end of file From ea1216b352ce400aad569b0c5a1909a488d6b6ed Mon Sep 17 00:00:00 2001 From: Grishka Date: Tue, 12 Nov 2024 22:12:05 +0300 Subject: [PATCH 2/3] Show the direction on gaps + bug fix --- mastodon/build.gradle | 2 +- .../android/fragments/HomeTimelineFragment.java | 3 ++- .../android/ui/displayitems/GapStatusDisplayItem.java | 1 + mastodon/src/main/res/layout/display_item_gap.xml | 6 +++++- mastodon/src/main/res/values/strings.xml | 3 ++- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/mastodon/build.gradle b/mastodon/build.gradle index ea7946c1..cd0a6f70 100644 --- a/mastodon/build.gradle +++ b/mastodon/build.gradle @@ -13,7 +13,7 @@ android { applicationId "org.joinmastodon.android" minSdk 23 targetSdk 34 - versionCode 127 + versionCode 128 versionName "2.9.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } 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() @@ -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 @@ -856,4 +855,6 @@ You will lose %s. + Load missing posts above + Load missing posts below \ No newline at end of file From 6e4590caf21c4ced52430a52427bc865ad205cff Mon Sep 17 00:00:00 2001 From: Grishka Date: Tue, 12 Nov 2024 22:40:48 +0300 Subject: [PATCH 3/3] Fix #820, probably --- .../main/java/org/joinmastodon/android/ui/utils/UiUtils.java | 3 +++ 1 file changed, 3 insertions(+) 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 13bcb2a3..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 @@ -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){