Skip to content

Commit

Permalink
feat: add mute notification toggle to mute dialog
Browse files Browse the repository at this point in the history
Closes sk22#966, by bringing parity with the web platform.
  • Loading branch information
FineFindus committed Jan 14, 2024
1 parent f7dfebc commit 28a811a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
import org.joinmastodon.android.model.Relationship;

public class SetAccountMuted extends MastodonAPIRequest<Relationship>{
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Duration> muteDuration=new AtomicReference<>(Duration.ZERO);

Expand Down Expand Up @@ -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){
Expand Down
31 changes: 30 additions & 1 deletion mastodon/src/main/res/layout/mute_user_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@
android:text="@string/confirm_mute"
android:textSize="16sp"/>

<LinearLayout
android:id="@+id/mute_notifications"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:gravity="center_vertical"
android:layoutDirection="locale">

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingVertical="8dp"
android:textSize="16sp"
android:textColor="?android:textColorPrimary"
android:text="@string/sk_mute_notifications_label" />

<org.joinmastodon.android.ui.views.M3Switch
android:id="@+id/mute_notifications_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:checked="true"
android:focusable="false"
android:clickable="false"/>

</LinearLayout>

<org.joinmastodon.android.ui.views.AutoOrientationLinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -28,7 +57,7 @@
android:paddingVertical="8dp"
android:gravity="center_vertical"
android:textColor="?android:textColorPrimary"
android:text="@string/sk_mute_label"
android:text="@string/sk_mute_duration_label"
android:textSize="16sp"/>

<Button
Expand Down
3 changes: 2 additions & 1 deletion mastodon/src/main/res/values/strings_sk.xml
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@
<string name="sk_button_react">React with emoji</string>
<string name="sk_enter_emoji_toast">Please type an emoji</string>
<string name="sk_enter_emoji_hint">Type an emoji or search</string>
<string name="sk_mute_label">Duration</string>
<string name="sk_mute_duration_label">Duration</string>
<string name="sk_mute_notifications_label">Mute Notifications?</string>
<string name="sk_duration_indefinite">Indefinite</string>
<string name="sk_duration_minutes_5">5 minutes</string>
<string name="sk_duration_minutes_30">30 minutes</string>
Expand Down

0 comments on commit 28a811a

Please sign in to comment.