mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-05 08:33:37 +02:00
Show snooze until time, snap to hours
This commit is contained in:
@@ -52,6 +52,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@@ -1203,6 +1204,8 @@ public class FragmentMessages extends FragmentEx {
|
||||
final View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_duration, null);
|
||||
final NumberPicker npHours = dview.findViewById(R.id.npHours);
|
||||
final NumberPicker npDays = dview.findViewById(R.id.npDays);
|
||||
final TextView tvTime = dview.findViewById(R.id.tvTime);
|
||||
final long HOUR_MS = 3600L * 1000L;
|
||||
|
||||
npHours.setMinValue(0);
|
||||
npHours.setMaxValue(24);
|
||||
@@ -1210,8 +1213,21 @@ public class FragmentMessages extends FragmentEx {
|
||||
npDays.setMinValue(0);
|
||||
npDays.setMaxValue(90);
|
||||
|
||||
npHours.setValue(prefs.getInt("snooze_hours", 1));
|
||||
npDays.setValue(prefs.getInt("snooze_days", 0));
|
||||
NumberPicker.OnValueChangeListener valueChanged = new NumberPicker.OnValueChangeListener() {
|
||||
@Override
|
||||
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
|
||||
int hours = npHours.getValue();
|
||||
int days = npDays.getValue();
|
||||
long duration = (hours + days * 24) * HOUR_MS;
|
||||
long time = new Date().getTime() / HOUR_MS * HOUR_MS + duration;
|
||||
tvTime.setText(SimpleDateFormat.getDateTimeInstance().format(time));
|
||||
tvTime.setVisibility(duration == 0 ? View.INVISIBLE : View.VISIBLE);
|
||||
}
|
||||
};
|
||||
|
||||
npHours.setOnValueChangedListener(valueChanged);
|
||||
npDays.setOnValueChangedListener(valueChanged);
|
||||
valueChanged.onValueChange(null, 0, 0);
|
||||
|
||||
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
|
||||
.setTitle(R.string.title_snooze)
|
||||
@@ -1222,16 +1238,12 @@ public class FragmentMessages extends FragmentEx {
|
||||
try {
|
||||
int hours = npHours.getValue();
|
||||
int days = npDays.getValue();
|
||||
long duration = (hours + days * 24) * 3600L * 1000L;
|
||||
|
||||
if (duration > 0) {
|
||||
prefs.edit().putInt("snooze_hours", hours).apply();
|
||||
prefs.edit().putInt("snooze_days", days).apply();
|
||||
}
|
||||
long duration = (hours + days * 24) * HOUR_MS;
|
||||
long time = new Date().getTime() / HOUR_MS * HOUR_MS + duration;
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putLongArray("ids", getSelection());
|
||||
args.putLong("wakeup", duration == 0 ? 0 : new Date().getTime() + duration);
|
||||
args.putLong("wakeup", duration == 0 ? 0 : time);
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user