feat: add mute notifications toggle
This commit is contained in:
@@ -4,16 +4,18 @@ import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||
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);
|
||||
if(muted)
|
||||
setRequestBody(new Request(duration, muteNotifications));
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ public abstract class AccountRestrictionConfirmationSheet extends BottomSheet{
|
||||
|
||||
AutoOrientationLinearLayout layout = new AutoOrientationLinearLayout(getContext());
|
||||
LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(0,ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
lp.gravity=Gravity.CENTER;
|
||||
lp.weight=1f;
|
||||
layout.addView(tv, lp);
|
||||
layout.addView(view, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
@@ -8,14 +8,16 @@ import android.widget.PopupMenu;
|
||||
|
||||
import org.joinmastodon.android.R;
|
||||
import org.joinmastodon.android.model.Account;
|
||||
import org.joinmastodon.android.ui.views.M3Switch;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class MuteAccountConfirmationSheet extends AccountRestrictionConfirmationSheet{
|
||||
public MuteAccountConfirmationSheet(@NonNull Context context, Account user, AtomicReference<Duration> muteDuration, ConfirmCallback confirmCallback){
|
||||
public MuteAccountConfirmationSheet(@NonNull Context context, Account user, AtomicReference<Duration> muteDuration, AtomicBoolean muteNotifications, ConfirmCallback confirmCallback){
|
||||
super(context, user, confirmCallback);
|
||||
titleView.setText(R.string.mute_user_confirm_title);
|
||||
confirmBtn.setText(R.string.do_mute);
|
||||
@@ -27,6 +29,13 @@ public class MuteAccountConfirmationSheet extends AccountRestrictionConfirmation
|
||||
addRow(R.drawable.ic_fluent_mention_24_regular, R.string.you_wont_see_user_mentions);
|
||||
addRow(R.drawable.ic_fluent_arrow_reply_24_regular, R.string.user_can_mention_and_follow_you);
|
||||
|
||||
// add mute notifications toggle (Moshidon)
|
||||
M3Switch m3Switch=new M3Switch(getContext());
|
||||
m3Switch.setClickable(true);
|
||||
m3Switch.setChecked(muteNotifications.get());
|
||||
m3Switch.setOnCheckedChangeListener((compoundButton, b) -> muteNotifications.set(b));
|
||||
addRow(R.drawable.ic_fluent_alert_off_24_regular, R.string.mo_mute_notifications, m3Switch);
|
||||
|
||||
// add mute duration (Moshidon)
|
||||
Button button=new Button(getContext());
|
||||
PopupMenu popupMenu=getMuteDurationPopupMenu(context, muteDuration, button);
|
||||
|
||||
@@ -156,6 +156,7 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiPredicate;
|
||||
@@ -599,10 +600,11 @@ public class UiUtils {
|
||||
}
|
||||
public static void confirmToggleMuteUser(Context context, String accountID, Account account, boolean currentlyMuted, Consumer<Relationship> resultCallback){
|
||||
if(!currentlyMuted){
|
||||
//pass a reference to the duration, so it can be changed inside the confirmation sheet
|
||||
//pass a references, so they can be changed inside the confirmation sheet
|
||||
AtomicReference<Duration> muteDuration=new AtomicReference<>(Duration.ZERO);
|
||||
new MuteAccountConfirmationSheet(context, account, muteDuration, (onSuccess, onError)->{
|
||||
new SetAccountMuted(account.id, true, muteDuration.get().getSeconds())
|
||||
AtomicBoolean muteNotifications=new AtomicBoolean(true);
|
||||
new MuteAccountConfirmationSheet(context, account, muteDuration, muteNotifications, (onSuccess, onError)->{
|
||||
new SetAccountMuted(account.id, true, muteDuration.get().getSeconds(), muteNotifications.get())
|
||||
.setCallback(new Callback<>(){
|
||||
@Override
|
||||
public void onSuccess(Relationship result){
|
||||
@@ -620,7 +622,7 @@ public class UiUtils {
|
||||
.exec(accountID);
|
||||
}).show();
|
||||
}else{
|
||||
new SetAccountMuted(account.id, false, 0)
|
||||
new SetAccountMuted(account.id, false, 0, false)
|
||||
.setCallback(new Callback<>(){
|
||||
@Override
|
||||
public void onSuccess(Relationship result){
|
||||
|
||||
@@ -119,4 +119,5 @@
|
||||
<!-- <string name="mo_mutes">Mutes</string>-->
|
||||
<string name="mo_blocked_accounts">Blocked accounts</string>
|
||||
<!-- <string name="mo_blocks">Blocks</string>-->
|
||||
<string name="mo_mute_notifications">Hide notifications from this user?</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user