feat: re-add mute duration option

This commit is contained in:
FineFindus 2024-04-02 19:32:08 +02:00
parent 37f63b1142
commit 56540d7e7b
No known key found for this signature in database
GPG Key ID: 64873EE210FF8E6B
2 changed files with 49 additions and 4 deletions

View File

@ -1,17 +1,22 @@
package org.joinmastodon.android.ui.sheets;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.PopupMenu;
import org.joinmastodon.android.R;
import org.joinmastodon.android.model.Account;
import java.time.Duration;
import java.util.concurrent.atomic.AtomicReference;
import androidx.annotation.NonNull;
public class MuteAccountConfirmationSheet extends AccountRestrictionConfirmationSheet{
public MuteAccountConfirmationSheet(@NonNull Context context, Account user, ConfirmCallback confirmCallback){
public MuteAccountConfirmationSheet(@NonNull Context context, Account user, AtomicReference<Duration> muteDuration, ConfirmCallback confirmCallback){
super(context, user, confirmCallback);
//TODO: readd the time option
titleView.setText(R.string.mute_user_confirm_title);
confirmBtn.setText(R.string.do_mute);
secondaryBtn.setVisibility(View.GONE);
@ -21,5 +26,43 @@ public class MuteAccountConfirmationSheet extends AccountRestrictionConfirmation
addRow(R.drawable.ic_fluent_eye_off_24_regular, R.string.user_can_still_see_your_posts);
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 duration (Moshidon)
Button button=new Button(getContext());
PopupMenu popupMenu=getMuteDurationPopupMenu(context, muteDuration, button);
button.setOnClickListener(v->popupMenu.show());
button.setOnTouchListener(popupMenu.getDragToOpenListener());
button.setText(popupMenu.getMenu().getItem(0).getTitle());
addRow(R.drawable.ic_fluent_clock_20_regular, R.string.sk_mute_label, button);
}
@NonNull
private PopupMenu getMuteDurationPopupMenu(@NonNull Context context, AtomicReference<Duration> muteDuration, Button button){
PopupMenu popupMenu=new PopupMenu(context, button, Gravity.CENTER_HORIZONTAL);
popupMenu.inflate(R.menu.mute_duration);
popupMenu.setOnMenuItemClickListener(item->{
int id=item.getItemId();
if(id==R.id.duration_indefinite)
muteDuration.set(Duration.ZERO);
else if(id==R.id.duration_minutes_5){
muteDuration.set(Duration.ofMinutes(5));
}else if(id==R.id.duration_minutes_30){
muteDuration.set(Duration.ofMinutes(30));
}else if(id==R.id.duration_hours_1){
muteDuration.set(Duration.ofHours(1));
}else if(id==R.id.duration_hours_6){
muteDuration.set(Duration.ofHours(6));
}else if(id==R.id.duration_days_1){
muteDuration.set(Duration.ofDays(1));
}else if(id==R.id.duration_days_3){
muteDuration.set(Duration.ofDays(3));
}else if(id==R.id.duration_days_7){
muteDuration.set(Duration.ofDays(7));
}
button.setText(item.getTitle());
return true;
});
return popupMenu;
}
}

View File

@ -599,8 +599,10 @@ public class UiUtils {
}
public static void confirmToggleMuteUser(Context context, String accountID, Account account, boolean currentlyMuted, Consumer<Relationship> resultCallback){
if(!currentlyMuted){
new MuteAccountConfirmationSheet(context, account, (onSuccess, onError)->{
new SetAccountMuted(account.id, true, 0)
//pass a reference to the duration, so it 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())
.setCallback(new Callback<>(){
@Override
public void onSuccess(Relationship result){