diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SetAccountFollowed.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SetAccountFollowed.java index e38479f18e..1799120a9c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SetAccountFollowed.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SetAccountFollowed.java @@ -4,10 +4,10 @@ import org.joinmastodon.android.model.Relationship; public class SetAccountFollowed extends MastodonAPIRequest{ - public SetAccountFollowed(String id, boolean followed, boolean showReblogs){ + public SetAccountFollowed(String id, boolean followed, boolean showReblogs, boolean notify){ super(HttpMethod.POST, "/accounts/"+id+"/"+(followed ? "follow" : "unfollow"), Relationship.class); if(followed) - setRequestBody(new Request(showReblogs, null)); + setRequestBody(new Request(showReblogs, notify)); else setRequestBody(new Object()); } 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 5040c2f8b1..db3a628be4 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -99,6 +99,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList private View avatarBorder; private TextView name, username, bio, followersCount, followersLabel, followingCount, followingLabel, postsCount, postsLabel; private ProgressBarButton actionButton; + private Button notifyButton; private ViewPager2 pager; private NestedRecyclerScrollView scrollView; private AccountTimelineFragment postsFragment, postsWithRepliesFragment, mediaFragment; @@ -181,6 +182,7 @@ public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bu postsLabel=content.findViewById(R.id.posts_label); postsBtn=content.findViewById(R.id.posts_btn); actionButton=content.findViewById(R.id.profile_action_btn); + notifyButton=content.findViewById(R.id.notify_btn); pager=content.findViewById(R.id.pager); scrollView=content.findViewById(R.id.scroller); tabbar=content.findViewById(R.id.tabbar); @@ -256,6 +258,7 @@ public void getOutline(View view, Outline outline){ }); actionButton.setOnClickListener(this::onActionButtonClick); + notifyButton.setOnClickListener(this::onNotifyButtonClick); avatar.setOnClickListener(this::onAvatarClick); cover.setOnClickListener(this::onCoverClick); refreshLayout.setOnRefreshListener(this); @@ -454,6 +457,7 @@ private void bindHeaderView(){ if(AccountSessionManager.getInstance().isSelf(accountID, account)){ actionButton.setText(R.string.edit_profile); + notifyButton.setVisibility(View.GONE); }else{ actionButton.setVisibility(View.GONE); } @@ -566,7 +570,7 @@ public boolean onOptionsItemSelected(MenuItem item){ updateRelationship(); }); }else if(id==R.id.hide_boosts){ - new SetAccountFollowed(account.id, true, !relationship.showingReblogs) + new SetAccountFollowed(account.id, true, !relationship.showingReblogs, relationship.notifying) .setCallback(new Callback<>(){ @Override public void onSuccess(Relationship result){ @@ -614,6 +618,8 @@ private void updateRelationship(){ UiUtils.setRelationshipToActionButton(relationship, actionButton); actionProgress.setIndeterminateTintList(actionButton.getTextColors()); followsYouView.setVisibility(relationship.followedBy ? View.VISIBLE : View.GONE); + notifyButton.setVisibility(relationship.following ? View.VISIBLE : View.GONE); + notifyButton.setSelected(relationship.notifying); } private void onScrollChanged(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY){ @@ -847,6 +853,10 @@ private List createFakeAttachments(String url, Drawable drawable){ return Collections.singletonList(att); } + private void onNotifyButtonClick(View v) { + UiUtils.performToggleAccountNotifications(getActivity(), account, accountID, relationship, actionButton, this::updateRelationship); + } + private void onAvatarClick(View v){ if(isInEditMode){ startImagePicker(AVATAR_RESULT); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BaseAccountListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BaseAccountListFragment.java index d9ab73f2f2..00e51d6101 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BaseAccountListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BaseAccountListFragment.java @@ -353,7 +353,7 @@ private boolean onContextMenuItemSelected(MenuItem item){ bindRelationship(); }); }else if(id==R.id.hide_boosts){ - new SetAccountFollowed(account.id, true, !relationship.showingReblogs) + new SetAccountFollowed(account.id, true, !relationship.showingReblogs, relationship.notifying) .setCallback(new Callback<>(){ @Override public void onSuccess(Relationship result){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportDoneFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportDoneFragment.java index 1970bf48d0..52fe7e452b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportDoneFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportDoneFragment.java @@ -125,7 +125,7 @@ private void onButtonClick(View v){ } private void onUnfollowClick(){ - new SetAccountFollowed(reportAccount.id, false, false) + new SetAccountFollowed(reportAccount.id, false, false, false) .setCallback(new Callback<>(){ @Override public void onSuccess(Relationship result){ 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 84436cca2e..261b35e6f4 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 @@ -11,7 +11,6 @@ import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Canvas; -import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.InsetDrawable; @@ -435,6 +434,22 @@ public static void setRelationshipToActionButton(Relationship relationship, Butt ta.recycle(); } + public static void performToggleAccountNotifications(Activity activity, Account account, String accountID, Relationship relationship, Button button, Consumer resultCallback) { + new SetAccountFollowed(account.id, true, relationship.showingReblogs, !relationship.notifying) + .setCallback(new Callback<>() { + @Override + public void onSuccess(Relationship result) { + resultCallback.accept(result); + Toast.makeText(activity, activity.getString(result.notifying ? R.string.user_post_notifications_on : R.string.user_post_notifications_off, '@'+account.username), Toast.LENGTH_SHORT).show(); + } + + @Override + public void onError(ErrorResponse error) { + error.showToast(activity); + } + }).exec(accountID); + } + public static void performAccountAction(Activity activity, Account account, String accountID, Relationship relationship, Button button, Consumer progressCallback, Consumer resultCallback){ if(relationship.blocking){ confirmToggleBlockUser(activity, accountID, account, true, resultCallback); @@ -442,7 +457,7 @@ public static void performAccountAction(Activity activity, Account account, Stri confirmToggleMuteUser(activity, accountID, account, true, resultCallback); }else{ progressCallback.accept(true); - new SetAccountFollowed(account.id, !relationship.following && !relationship.requested, true) + new SetAccountFollowed(account.id, !relationship.following && !relationship.requested, true, false) .setCallback(new Callback<>(){ @Override public void onSuccess(Relationship result){ diff --git a/mastodon/src/main/res/drawable/ic_fluent_alert_24_filled.xml b/mastodon/src/main/res/drawable/ic_fluent_alert_24_filled.xml new file mode 100644 index 0000000000..8894f5596b --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_alert_24_filled.xml @@ -0,0 +1,3 @@ + + + diff --git a/mastodon/src/main/res/drawable/ic_fluent_alert_24_regular.xml b/mastodon/src/main/res/drawable/ic_fluent_alert_24_regular.xml new file mode 100644 index 0000000000..c7dd28f1bd --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_alert_24_regular.xml @@ -0,0 +1,3 @@ + + + diff --git a/mastodon/src/main/res/drawable/ic_fluent_alert_24_selector.xml b/mastodon/src/main/res/drawable/ic_fluent_alert_24_selector.xml new file mode 100644 index 0000000000..7d2eb9fe89 --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_alert_24_selector.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/mastodon/src/main/res/layout/fragment_profile.xml b/mastodon/src/main/res/layout/fragment_profile.xml index 8c31d928b8..d49662cc4f 100644 --- a/mastodon/src/main/res/layout/fragment_profile.xml +++ b/mastodon/src/main/res/layout/fragment_profile.xml @@ -166,31 +166,46 @@ - - + +