feat(mute-sheet): use secondary button for mute duration instead of a new row

This commit is contained in:
LucasGGamerM 2024-04-10 12:30:02 -03:00
parent 4f3d711d2b
commit 6c519b3cb9
1 changed files with 47 additions and 23 deletions

View File

@ -1,13 +1,19 @@
package org.joinmastodon.android.ui.sheets; package org.joinmastodon.android.ui.sheets;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Typeface;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.PopupMenu; import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
import org.joinmastodon.android.R; import org.joinmastodon.android.R;
import org.joinmastodon.android.model.Account; import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.ui.M3AlertDialogBuilder;
import org.joinmastodon.android.ui.views.M3Switch; import org.joinmastodon.android.ui.views.M3Switch;
import java.time.Duration; import java.time.Duration;
@ -38,41 +44,59 @@ public class MuteAccountConfirmationSheet extends AccountRestrictionConfirmation
addRow(R.drawable.ic_fluent_alert_off_24_regular, R.string.mo_mute_notifications, m3Switch); addRow(R.drawable.ic_fluent_alert_off_24_regular, R.string.mo_mute_notifications, m3Switch);
// add mute duration (Moshidon) // add mute duration (Moshidon)
Button button=new Button(getContext()); secondaryBtn.setVisibility(View.VISIBLE);
PopupMenu popupMenu=getMuteDurationPopupMenu(context, muteDuration, button); secondaryBtn.setOnClickListener(v->getMuteDurationDialog(context, muteDuration, secondaryBtn).show());
button.setOnClickListener(v->popupMenu.show()); secondaryBtn.setText(R.string.sk_duration_indefinite);
button.setOnTouchListener(popupMenu.getDragToOpenListener()); secondaryBtn.setTypeface(null, Typeface.BOLD_ITALIC);
button.setText(popupMenu.getMenu().getItem(0).getTitle());
addRow(R.drawable.ic_fluent_clock_20_regular, R.string.sk_mute_label, button);
} }
@NonNull @NonNull
private PopupMenu getMuteDurationPopupMenu(@NonNull Context context, AtomicReference<Duration> muteDuration, Button button){ private M3AlertDialogBuilder getMuteDurationDialog(@NonNull Context context, AtomicReference<Duration> muteDuration, Button button){
PopupMenu popupMenu=new PopupMenu(context, button, Gravity.CENTER_HORIZONTAL); M3AlertDialogBuilder builder=new M3AlertDialogBuilder(context);
popupMenu.inflate(R.menu.mute_duration); builder.setTitle(R.string.sk_mute_label);
popupMenu.setOnMenuItemClickListener(item->{ builder.setIcon(R.drawable.ic_fluent_clock_20_regular);
int id=item.getItemId();
if(id==R.id.duration_indefinite) String[] choices = {context.getString(R.string.sk_duration_indefinite),
context.getString(R.string.sk_duration_minutes_5),
context.getString(R.string.sk_duration_minutes_30),
context.getString(R.string.sk_duration_hours_1),
context.getString(R.string.sk_duration_hours_6),
context.getString(R.string.sk_duration_days_1),
context.getString(R.string.sk_duration_days_3),
context.getString(R.string.sk_duration_days_7)};
builder.setSingleChoiceItems(choices, 0, (dialog, which) -> {});
builder.setPositiveButton(R.string.save, (dialog, which)->{
int selected = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
if(selected==0){
muteDuration.set(Duration.ZERO); muteDuration.set(Duration.ZERO);
else if(id==R.id.duration_minutes_5){ }else if(selected==1){
muteDuration.set(Duration.ofMinutes(5)); muteDuration.set(Duration.ofMinutes(5));
}else if(id==R.id.duration_minutes_30){ }else if(selected==2){
muteDuration.set(Duration.ofMinutes(30)); muteDuration.set(Duration.ofMinutes(30));
}else if(id==R.id.duration_hours_1){ }else if(selected==3){
muteDuration.set(Duration.ofHours(1)); muteDuration.set(Duration.ofHours(1));
}else if(id==R.id.duration_hours_6){ }else if(selected==4){
muteDuration.set(Duration.ofHours(6)); muteDuration.set(Duration.ofHours(6));
}else if(id==R.id.duration_days_1){ }else if(selected==5){
muteDuration.set(Duration.ofDays(1)); muteDuration.set(Duration.ofDays(1));
}else if(id==R.id.duration_days_3){ }else if(selected==6){
muteDuration.set(Duration.ofDays(3)); muteDuration.set(Duration.ofDays(3));
}else if(id==R.id.duration_days_7){ }else if(selected==7){
muteDuration.set(Duration.ofDays(7)); muteDuration.set(Duration.ofDays(7));
} }
button.setText(item.getTitle()); if(selected >= 0 && selected <= 7){
return true; button.setText(choices[selected]);
}); } else {
return popupMenu; Toast.makeText(context, "" + selected, Toast.LENGTH_SHORT).show();
} }
});
builder.setNegativeButton(R.string.cancel, ((dialogInterface, i) -> {}));
return builder;
}
} }