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 e38479f18..1799120a9 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.api.MastodonAPIRequest; 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 5040c2f8b..db3a628be 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 class ProfileFragment extends LoaderFragment implements OnBackPressedList 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 class ProfileFragment extends LoaderFragment implements OnBackPressedList }); actionButton.setOnClickListener(this::onActionButtonClick); + notifyButton.setOnClickListener(this::onNotifyButtonClick); avatar.setOnClickListener(this::onAvatarClick); cover.setOnClickListener(this::onCoverClick); refreshLayout.setOnRefreshListener(this); @@ -454,6 +457,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList 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 class ProfileFragment extends LoaderFragment implements OnBackPressedList 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 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList 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 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList 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 d9ab73f2f..00e51d610 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 @@ public abstract class BaseAccountListFragment extends BaseRecyclerFragment(){ @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 1970bf48d..52fe7e452 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 @@ public class ReportDoneFragment extends MastodonToolbarFragment{ } 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 84436cca2..261b35e6f 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.content.res.TypedArray; 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 class UiUtils{ 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 class UiUtils{ 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 000000000..8894f5596 --- /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 000000000..c7dd28f1b --- /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 000000000..7d2eb9fe8 --- /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 8c31d928b..d49662cc4 100644 --- a/mastodon/src/main/res/layout/fragment_profile.xml +++ b/mastodon/src/main/res/layout/fragment_profile.xml @@ -166,31 +166,46 @@ - - + +