From 72580dadd0e9c8b44b774b13b542ed9804a69f90 Mon Sep 17 00:00:00 2001 From: FineFindus <63370021+FineFindus@users.noreply.github.com> Date: Sat, 30 Sep 2023 18:24:24 +0200 Subject: [PATCH] feat: display blocks and mutes list (#821) * feat: add mutes fragment * feat: add blocks fragment * refactor: add query params * rename "mutes" and "blocks" --------- Co-authored-by: sk --- .../requests/accounts/GetAccountBlocks.java | 16 +++++++++ .../requests/accounts/GetAccountMutes.java | 16 +++++++++ .../android/fragments/ProfileFragment.java | 13 ++++++- .../BlockedAccountsListFragment.java | 36 +++++++++++++++++++ .../MutedAccountsListFragment.java | 36 +++++++++++++++++++ mastodon/src/main/res/menu/profile_own.xml | 2 ++ mastodon/src/main/res/values/strings_sk.xml | 2 ++ 7 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetAccountBlocks.java create mode 100644 mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetAccountMutes.java create mode 100644 mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BlockedAccountsListFragment.java create mode 100644 mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/MutedAccountsListFragment.java diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetAccountBlocks.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetAccountBlocks.java new file mode 100644 index 000000000..16d0403a4 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetAccountBlocks.java @@ -0,0 +1,16 @@ +package org.joinmastodon.android.api.requests.accounts; + +import com.google.gson.reflect.TypeToken; + +import org.joinmastodon.android.api.requests.HeaderPaginationRequest; +import org.joinmastodon.android.model.Account; + +public class GetAccountBlocks extends HeaderPaginationRequest{ + public GetAccountBlocks(String maxID, int limit){ + super(HttpMethod.GET, "/blocks", new TypeToken<>(){}); + if(maxID!=null) + addQueryParameter("max_id", maxID); + if(limit>0) + addQueryParameter("limit", limit+""); + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetAccountMutes.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetAccountMutes.java new file mode 100644 index 000000000..966b36c51 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetAccountMutes.java @@ -0,0 +1,16 @@ +package org.joinmastodon.android.api.requests.accounts; + +import com.google.gson.reflect.TypeToken; + +import org.joinmastodon.android.api.requests.HeaderPaginationRequest; +import org.joinmastodon.android.model.Account; + +public class GetAccountMutes extends HeaderPaginationRequest{ + public GetAccountMutes(String maxID, int limit){ + super(HttpMethod.GET, "/mutes/", new TypeToken<>(){}); + if(maxID!=null) + addQueryParameter("max_id", maxID); + if(limit>0) + addQueryParameter("limit", limit+""); + } +} 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 c726f408f..cf26e2971 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -23,7 +23,6 @@ import android.os.Build; import android.os.Bundle; import android.text.SpannableStringBuilder; import android.text.TextUtils; -import android.text.style.ImageSpan; import android.transition.ChangeBounds; import android.transition.Fade; import android.transition.TransitionManager; @@ -60,8 +59,10 @@ import org.joinmastodon.android.api.requests.accounts.SetAccountFollowed; import org.joinmastodon.android.api.requests.accounts.UpdateAccountCredentials; import org.joinmastodon.android.api.requests.instance.GetInstance; import org.joinmastodon.android.api.session.AccountSessionManager; +import org.joinmastodon.android.fragments.account_list.BlockedAccountsListFragment; import org.joinmastodon.android.fragments.account_list.FollowerListFragment; import org.joinmastodon.android.fragments.account_list.FollowingListFragment; +import org.joinmastodon.android.fragments.account_list.MutedAccountsListFragment; import org.joinmastodon.android.fragments.report.ReportReasonChoiceFragment; import org.joinmastodon.android.fragments.settings.SettingsServerFragment; import org.joinmastodon.android.model.Account; @@ -846,6 +847,16 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList args.putString("profileDisplayUsername", account.getDisplayUsername()); } Nav.go(getActivity(), ListsFragment.class, args); + }else if(id==R.id.muted_accounts){ + final Bundle args=new Bundle(); + args.putString("account", accountID); + args.putParcelable("targetAccount", Parcels.wrap(account)); + Nav.go(getActivity(), MutedAccountsListFragment.class, args); + }else if(id==R.id.blocked_accounts){ + final Bundle args=new Bundle(); + args.putString("account", accountID); + args.putParcelable("targetAccount", Parcels.wrap(account)); + Nav.go(getActivity(), BlockedAccountsListFragment.class, args); }else if(id==R.id.followed_hashtags){ Bundle args=new Bundle(); args.putString("account", accountID); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BlockedAccountsListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BlockedAccountsListFragment.java new file mode 100644 index 000000000..facb4c1d6 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BlockedAccountsListFragment.java @@ -0,0 +1,36 @@ +package org.joinmastodon.android.fragments.account_list; + +import android.net.Uri; +import android.os.Bundle; + +import org.joinmastodon.android.R; +import org.joinmastodon.android.api.requests.HeaderPaginationRequest; +import org.joinmastodon.android.api.requests.accounts.GetAccountBlocks; +import org.joinmastodon.android.model.Account; +import org.joinmastodon.android.ui.viewholders.AccountViewHolder; + +public class BlockedAccountsListFragment extends AccountRelatedAccountListFragment{ + + @Override + public void onCreate(Bundle savedInstanceState){ + super.onCreate(savedInstanceState); + setTitle(R.string.sk_blocked_accounts); + } + + @Override + public HeaderPaginationRequest onCreateRequest(String maxID, int count){ + return new GetAccountBlocks(maxID, count); + } + + @Override + protected void onConfigureViewHolder(AccountViewHolder holder){ + super.onConfigureViewHolder(holder); + holder.setStyle(AccountViewHolder.AccessoryType.NONE, false); + } + + @Override + public Uri getWebUri(Uri.Builder base) { + return super.getWebUri(base).buildUpon() + .appendPath("/blocks").build(); + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/MutedAccountsListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/MutedAccountsListFragment.java new file mode 100644 index 000000000..22dff9921 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/MutedAccountsListFragment.java @@ -0,0 +1,36 @@ +package org.joinmastodon.android.fragments.account_list; + +import android.net.Uri; +import android.os.Bundle; + +import org.joinmastodon.android.R; +import org.joinmastodon.android.api.requests.HeaderPaginationRequest; +import org.joinmastodon.android.api.requests.accounts.GetAccountMutes; +import org.joinmastodon.android.model.Account; +import org.joinmastodon.android.ui.viewholders.AccountViewHolder; + +public class MutedAccountsListFragment extends AccountRelatedAccountListFragment{ + + @Override + public void onCreate(Bundle savedInstanceState){ + super.onCreate(savedInstanceState); + setTitle(R.string.sk_muted_accounts); + } + + @Override + public HeaderPaginationRequest onCreateRequest(String maxID, int count){ + return new GetAccountMutes(maxID, count); + } + + @Override + protected void onConfigureViewHolder(AccountViewHolder holder){ + super.onConfigureViewHolder(holder); + holder.setStyle(AccountViewHolder.AccessoryType.NONE, false); + } + + @Override + public Uri getWebUri(Uri.Builder base) { + return super.getWebUri(base).buildUpon() + .appendPath("/mutes").build(); + } +} diff --git a/mastodon/src/main/res/menu/profile_own.xml b/mastodon/src/main/res/menu/profile_own.xml index 61543c3e5..fbc4db924 100644 --- a/mastodon/src/main/res/menu/profile_own.xml +++ b/mastodon/src/main/res/menu/profile_own.xml @@ -7,6 +7,8 @@ + + \ No newline at end of file diff --git a/mastodon/src/main/res/values/strings_sk.xml b/mastodon/src/main/res/values/strings_sk.xml index 17f7c76c8..911e9e0a0 100644 --- a/mastodon/src/main/res/values/strings_sk.xml +++ b/mastodon/src/main/res/values/strings_sk.xml @@ -392,4 +392,6 @@ %d minutes %d hours %d days + Muted accounts + Blocked accounts \ No newline at end of file