diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 3e413a27b3..13cd9ed870 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -99,6 +99,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -706,6 +707,8 @@ public class FragmentCompose 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); @@ -713,6 +716,22 @@ public class FragmentCompose extends FragmentEx { npDays.setMinValue(0); npDays.setMaxValue(90); + 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_send_after) .setView(dview) @@ -722,11 +741,12 @@ public class FragmentCompose extends FragmentEx { try { int hours = npHours.getValue(); int days = npDays.getValue(); - long duration = (hours + days * 24) * 3600L * 1000L; + long duration = (hours + days * 24) * HOUR_MS; + long time = new Date().getTime() / HOUR_MS * HOUR_MS + duration; Bundle args = new Bundle(); args.putLong("id", working); - args.putLong("wakeup", new Date().getTime() + duration); + args.putLong("wakeup", time); new SimpleTask() { @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 3c473ebb86..66dfecdf5f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -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() { @Override diff --git a/app/src/main/res/layout/dialog_duration.xml b/app/src/main/res/layout/dialog_duration.xml index 877524265c..62c230d6c2 100644 --- a/app/src/main/res/layout/dialog_duration.xml +++ b/app/src/main/res/layout/dialog_duration.xml @@ -46,4 +46,15 @@ app:layout_constraintEnd_toEndOf="@id/tvDays" app:layout_constraintStart_toStartOf="@id/tvDays" app:layout_constraintTop_toBottomOf="@id/tvDays" /> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 465013c935..932793ff60 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -274,7 +274,7 @@ More Spam Move - Snooze + Snooze … Archive Reply Moving to %1$s