Show followers/following number when blocking a server (AND-233)

This commit is contained in:
Grishka 2024-11-12 18:49:05 +03:00
parent 20ed47032e
commit 134bd13d60
6 changed files with 88 additions and 8 deletions

View File

@ -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"
}

View File

@ -0,0 +1,15 @@
package org.joinmastodon.android.api.requests.accounts;
import org.joinmastodon.android.api.MastodonAPIRequest;
public class GetDomainBlockPreview extends MastodonAPIRequest<GetDomainBlockPreview.Response>{
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;
}
}

View File

@ -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){

View File

@ -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();
}
}

View File

@ -501,7 +501,7 @@ public class UiUtils{
}
})
.exec(accountID);
}).show();
}, accountID).show();
}else{
new SetDomainBlocked(account.getDomain(), false)
.setCallback(new Callback<>(){

View File

@ -675,7 +675,6 @@
<string name="block_user_x_instead">Block %s instead</string>
<string name="users_cant_see_blocked">You wont see posts or notifications from users on this server.</string>
<string name="you_wont_see_server_posts">You wont see any posts from users on this server.</string>
<string name="server_followers_will_be_removed">Your followers from this server will be removed.</string>
<string name="server_cant_mention_or_follow_you">Nobody from this server can follow you.</string>
<string name="server_can_interact_with_older">People from this server can interact with your old posts.</string>
<string name="unblocked_domain_x">Unblocked domain %s</string>
@ -840,4 +839,21 @@
<item quantity="one">%,d follower you know</item>
<item quantity="other">%,d followers you know</item>
</plurals>
<!-- appears when you're about to block a server -->
<plurals name="server_x_followers_will_be_removed">
<item quantity="one">%,d follower from this server will be removed.</item>
<item quantity="other">%,d followers from this server will be removed.</item>
</plurals>
<!-- The complete string will look like "You will lose X followers and Y people you follow". See will_lose_x_followers and will_lose_x_following -->
<string name="server_x_followers_and_following_will_be_removed">You will lose %1$s and %2$s.</string>
<plurals name="will_lose_x_followers">
<item quantity="one">%,d follower</item>
<item quantity="other">%,d followers</item>
</plurals>
<plurals name="will_lose_x_following">
<item quantity="one">%,d person you follow</item>
<item quantity="other">%,d people you follow</item>
</plurals>
<!-- The complete string will look like "You will lose X people you follow". See will_lose_x_following -->
<string name="server_x_following_will_be_removed">You will lose %s.</string>
</resources>