mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-03 13:44:40 +00:00
Show snooze until time, snap to hours
This commit is contained in:
parent
043f55e94c
commit
1423e0bb4b
4 changed files with 55 additions and 12 deletions
|
@ -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<Void>() {
|
||||
@Override
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -46,4 +46,15 @@
|
|||
app:layout_constraintEnd_toEndOf="@id/tvDays"
|
||||
app:layout_constraintStart_toStartOf="@id/tvDays"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvDays" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="Time"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/npDays" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -274,7 +274,7 @@
|
|||
<string name="title_more">More</string>
|
||||
<string name="title_spam">Spam</string>
|
||||
<string name="title_move">Move</string>
|
||||
<string name="title_snooze">Snooze</string>
|
||||
<string name="title_snooze">Snooze …</string>
|
||||
<string name="title_archive">Archive</string>
|
||||
<string name="title_reply">Reply</string>
|
||||
<string name="title_moving">Moving to %1$s</string>
|
||||
|
|
Loading…
Reference in a new issue