From 28a811ae956adf3e60ebdda456be61fa8acb49cf Mon Sep 17 00:00:00 2001 From: FineFindus Date: Sun, 14 Jan 2024 20:14:16 +0100 Subject: [PATCH 1/2] feat: add mute notification toggle to mute dialog Closes https://github.com/sk22/megalodon/issues/966, by bringing parity with the web platform. --- .../requests/accounts/SetAccountMuted.java | 8 +++-- .../android/ui/utils/UiUtils.java | 5 ++- .../src/main/res/layout/mute_user_dialog.xml | 31 ++++++++++++++++++- mastodon/src/main/res/values/strings_sk.xml | 3 +- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SetAccountMuted.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SetAccountMuted.java index 7d6afadf6a..4f812bab24 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SetAccountMuted.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SetAccountMuted.java @@ -4,15 +4,17 @@ import org.joinmastodon.android.model.Relationship; public class SetAccountMuted extends MastodonAPIRequest{ - public SetAccountMuted(String id, boolean muted, long duration){ + public SetAccountMuted(String id, boolean muted, long duration, boolean muteNotifications){ super(HttpMethod.POST, "/accounts/"+id+"/"+(muted ? "mute" : "unmute"), Relationship.class); - setRequestBody(new Request(duration)); + setRequestBody(new Request(duration, muteNotifications)); } private static class Request{ public long duration; - public Request(long duration){ + public boolean muteNotifications; + public Request(long duration, boolean muteNotifications){ this.duration=duration; + this.muteNotifications=muteNotifications; } } } 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 d5f3281ad0..b24d71a943 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 @@ -61,6 +61,7 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupMenu; +import android.widget.Switch; import android.widget.TextView; import android.widget.Toast; @@ -567,6 +568,8 @@ public static void confirmToggleMuteUser(Context context, String accountID, Acco durationView.setLayoutParams(params); Button button=durationView.findViewById(R.id.button); ((TextView) durationView.findViewById(R.id.message)).setText(context.getString(R.string.confirm_mute, account.getDisplayName())); + Switch muteNotificationsSwitch=durationView.findViewById(R.id.mute_notifications_switch); + durationView.findViewById(R.id.mute_notifications).setOnClickListener(l->muteNotificationsSwitch.setChecked(!muteNotificationsSwitch.isChecked())); AtomicReference muteDuration=new AtomicReference<>(Duration.ZERO); @@ -603,7 +606,7 @@ else if(id==R.id.duration_minutes_5){ .setMessage(currentlyMuted ? context.getString(R.string.confirm_unmute, account.getDisplayName()) : null) .setView(currentlyMuted ? null : durationView) .setPositiveButton(context.getString(currentlyMuted ? R.string.do_unmute : R.string.do_mute), (dlg, i)->{ - new SetAccountMuted(account.id, !currentlyMuted, muteDuration.get().getSeconds()) + new SetAccountMuted(account.id, !currentlyMuted, muteDuration.get().getSeconds(), muteNotificationsSwitch.isChecked()) .setCallback(new Callback<>(){ @Override public void onSuccess(Relationship result){ diff --git a/mastodon/src/main/res/layout/mute_user_dialog.xml b/mastodon/src/main/res/layout/mute_user_dialog.xml index 966716b928..cc83d550e3 100644 --- a/mastodon/src/main/res/layout/mute_user_dialog.xml +++ b/mastodon/src/main/res/layout/mute_user_dialog.xml @@ -15,6 +15,35 @@ android:text="@string/confirm_mute" android:textSize="16sp"/> + + + + + + + +