mirror of https://github.com/M66B/FairEmail.git
Use date/time picker for snooze / send at
This commit is contained in:
parent
44212af438
commit
68ef67e3f8
|
@ -918,8 +918,13 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
}
|
||||
|
||||
private void onShowSnoozed(TupleMessageEx message) {
|
||||
if (message.ui_snoozed != null)
|
||||
Toast.makeText(context, DialogDuration.formatTime(message.ui_snoozed), Toast.LENGTH_LONG).show();
|
||||
if (message.ui_snoozed != null) {
|
||||
DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.MEDIUM, SimpleDateFormat.SHORT);
|
||||
DateFormat day = new SimpleDateFormat("E");
|
||||
Toast.makeText(context,
|
||||
day.format(message.ui_snoozed) + " " + df.format(message.ui_snoozed),
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void onToggleFlag(TupleMessageEx message) {
|
||||
|
|
|
@ -2,49 +2,62 @@ package eu.faircode.email;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Build;
|
||||
import android.text.format.DateFormat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.NumberPicker;
|
||||
import android.widget.TextView;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.TimePicker;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
public class DialogDuration {
|
||||
private static final long HOUR_MS = 3600L * 1000L;
|
||||
|
||||
static void show(Context context, LifecycleOwner owner, int title, final IDialogDuration intf) {
|
||||
final View dview = LayoutInflater.from(context).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 now = new Date().getTime() / HOUR_MS * HOUR_MS;
|
||||
final TimePicker timePicker = dview.findViewById(R.id.timePicker);
|
||||
final DatePicker datePicker = dview.findViewById(R.id.datePicker);
|
||||
|
||||
npHours.setMinValue(0);
|
||||
npHours.setMaxValue(24);
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(new Date().getTime() / (60 * 1000L) * (60 * 1000L));
|
||||
Log.i("Set init=" + new Date(cal.getTimeInMillis()));
|
||||
|
||||
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 = now + duration;
|
||||
DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.MEDIUM, SimpleDateFormat.SHORT);
|
||||
tvTime.setText(formatTime(time));
|
||||
tvTime.setVisibility(duration == 0 ? View.INVISIBLE : View.VISIBLE);
|
||||
timePicker.setIs24HourView(DateFormat.is24HourFormat(context));
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
timePicker.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY));
|
||||
timePicker.setCurrentMinute(cal.get(Calendar.MINUTE));
|
||||
} else {
|
||||
timePicker.setHour(cal.get(Calendar.HOUR_OF_DAY));
|
||||
timePicker.setMinute(cal.get(Calendar.MINUTE));
|
||||
}
|
||||
};
|
||||
|
||||
npHours.setOnValueChangedListener(valueChanged);
|
||||
npDays.setOnValueChangedListener(valueChanged);
|
||||
valueChanged.onValueChange(null, 0, 0);
|
||||
timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
|
||||
@Override
|
||||
public void onTimeChanged(TimePicker view, int hour, int minute) {
|
||||
cal.set(Calendar.HOUR_OF_DAY, hour);
|
||||
cal.set(Calendar.MINUTE, minute);
|
||||
Log.i("Set hour=" + hour + " minute=" + minute +
|
||||
" time=" + new Date(cal.getTimeInMillis()));
|
||||
}
|
||||
});
|
||||
|
||||
datePicker.init(
|
||||
cal.get(Calendar.YEAR),
|
||||
cal.get(Calendar.MONTH),
|
||||
cal.get(Calendar.DAY_OF_MONTH),
|
||||
new DatePicker.OnDateChangedListener() {
|
||||
@Override
|
||||
public void onDateChanged(DatePicker view, int year, int month, int day) {
|
||||
cal.set(Calendar.YEAR, year);
|
||||
cal.set(Calendar.MONTH, month);
|
||||
cal.set(Calendar.DAY_OF_MONTH, day);
|
||||
Log.i("Set year=" + year + " month=" + month + " day=" + day +
|
||||
" time=" + new Date(cal.getTimeInMillis()));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
new DialogBuilderLifecycle(context, owner)
|
||||
.setTitle(title)
|
||||
|
@ -52,11 +65,12 @@ public class DialogDuration {
|
|||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
int hours = npHours.getValue();
|
||||
int days = npDays.getValue();
|
||||
long duration = (hours + days * 24) * HOUR_MS;
|
||||
long time = now + duration;
|
||||
intf.onDurationSelected(duration, time);
|
||||
long now = new Date().getTime();
|
||||
long duration = (cal.getTimeInMillis() - now);
|
||||
if (duration < 0)
|
||||
duration = 0;
|
||||
Log.i("Set duration=" + duration + " time=" + new Date(cal.getTimeInMillis()));
|
||||
intf.onDurationSelected(duration, cal.getTimeInMillis());
|
||||
}
|
||||
})
|
||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
|
@ -68,11 +82,6 @@ public class DialogDuration {
|
|||
.show();
|
||||
}
|
||||
|
||||
static String formatTime(long time) {
|
||||
DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.MEDIUM, SimpleDateFormat.SHORT);
|
||||
return new SimpleDateFormat("E").format(time) + " " + df.format(time);
|
||||
}
|
||||
|
||||
interface IDialogDuration {
|
||||
void onDurationSelected(long duration, long time);
|
||||
|
||||
|
|
|
@ -9,57 +9,20 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:padding="24dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvHours"
|
||||
android:layout_width="0dp"
|
||||
<TimePicker
|
||||
android:id="@+id/timePicker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/title_hours"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintEnd_toStartOf="@+id/tvDays"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDays"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/title_days"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/tvHours"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<NumberPicker
|
||||
android:id="@+id/npHours"
|
||||
<DatePicker
|
||||
android:id="@+id/datePicker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
app:layout_constraintEnd_toEndOf="@id/tvHours"
|
||||
app:layout_constraintStart_toStartOf="@id/tvHours"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvHours" />
|
||||
|
||||
<NumberPicker
|
||||
android:id="@+id/npDays"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
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" />
|
||||
app:layout_constraintTop_toBottomOf="@id/timePicker" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</ScrollView>
|
|
@ -462,8 +462,6 @@
|
|||
<string name="title_undo">Undo</string>
|
||||
<string name="title_add">Add</string>
|
||||
<string name="title_browse">Browse</string>
|
||||
<string name="title_hours">Hours</string>
|
||||
<string name="title_days">Days</string>
|
||||
<string name="title_report">Report</string>
|
||||
<string name="title_no_ask_again">Do not ask this again</string>
|
||||
<string name="title_no_adobe">Adobe Acrobat reader cannot open safely shared files, see the FAQ for more information</string>
|
||||
|
|
Loading…
Reference in New Issue