Use date/time picker for snooze / send at

pull/147/head
M66B 7 years ago
parent 44212af438
commit 68ef67e3f8

@ -918,8 +918,13 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
private void onShowSnoozed(TupleMessageEx message) { private void onShowSnoozed(TupleMessageEx message) {
if (message.ui_snoozed != null) if (message.ui_snoozed != null) {
Toast.makeText(context, DialogDuration.formatTime(message.ui_snoozed), Toast.LENGTH_LONG).show(); 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) { private void onToggleFlag(TupleMessageEx message) {

@ -2,49 +2,62 @@ package eu.faircode.email;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Build;
import android.text.format.DateFormat;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.NumberPicker; import android.widget.DatePicker;
import android.widget.TextView; import android.widget.TimePicker;
import java.text.DateFormat; import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
public class DialogDuration { public class DialogDuration {
private static final long HOUR_MS = 3600L * 1000L;
static void show(Context context, LifecycleOwner owner, int title, final IDialogDuration intf) { 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 View dview = LayoutInflater.from(context).inflate(R.layout.dialog_duration, null);
final NumberPicker npHours = dview.findViewById(R.id.npHours); final TimePicker timePicker = dview.findViewById(R.id.timePicker);
final NumberPicker npDays = dview.findViewById(R.id.npDays); final DatePicker datePicker = dview.findViewById(R.id.datePicker);
final TextView tvTime = dview.findViewById(R.id.tvTime);
final long now = new Date().getTime() / HOUR_MS * HOUR_MS;
npHours.setMinValue(0); final Calendar cal = Calendar.getInstance();
npHours.setMaxValue(24); cal.setTimeInMillis(new Date().getTime() / (60 * 1000L) * (60 * 1000L));
Log.i("Set init=" + new Date(cal.getTimeInMillis()));
npDays.setMinValue(0); timePicker.setIs24HourView(DateFormat.is24HourFormat(context));
npDays.setMaxValue(90); 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));
}
NumberPicker.OnValueChangeListener valueChanged = new NumberPicker.OnValueChangeListener() { timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
@Override @Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) { public void onTimeChanged(TimePicker view, int hour, int minute) {
int hours = npHours.getValue(); cal.set(Calendar.HOUR_OF_DAY, hour);
int days = npDays.getValue(); cal.set(Calendar.MINUTE, minute);
long duration = (hours + days * 24) * HOUR_MS; Log.i("Set hour=" + hour + " minute=" + minute +
long time = now + duration; " time=" + new Date(cal.getTimeInMillis()));
DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.MEDIUM, SimpleDateFormat.SHORT);
tvTime.setText(formatTime(time));
tvTime.setVisibility(duration == 0 ? View.INVISIBLE : View.VISIBLE);
} }
}; });
npHours.setOnValueChangedListener(valueChanged); datePicker.init(
npDays.setOnValueChangedListener(valueChanged); cal.get(Calendar.YEAR),
valueChanged.onValueChange(null, 0, 0); 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) new DialogBuilderLifecycle(context, owner)
.setTitle(title) .setTitle(title)
@ -52,11 +65,12 @@ public class DialogDuration {
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
int hours = npHours.getValue(); long now = new Date().getTime();
int days = npDays.getValue(); long duration = (cal.getTimeInMillis() - now);
long duration = (hours + days * 24) * HOUR_MS; if (duration < 0)
long time = now + duration; duration = 0;
intf.onDurationSelected(duration, time); Log.i("Set duration=" + duration + " time=" + new Date(cal.getTimeInMillis()));
intf.onDurationSelected(duration, cal.getTimeInMillis());
} }
}) })
.setOnDismissListener(new DialogInterface.OnDismissListener() { .setOnDismissListener(new DialogInterface.OnDismissListener() {
@ -68,11 +82,6 @@ public class DialogDuration {
.show(); .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 { interface IDialogDuration {
void onDurationSelected(long duration, long time); void onDurationSelected(long duration, long time);

@ -9,57 +9,20 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="24dp"> android:padding="24dp">
<TextView <TimePicker
android:id="@+id/tvHours" android:id="@+id/timePicker"
android:layout_width="0dp" 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_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvDays"
android:layout_width="0dp"
android:layout_height="wrap_content" 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_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvHours" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<NumberPicker <DatePicker
android:id="@+id/npHours" android:id="@+id/datePicker"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="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_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/npDays" /> app:layout_constraintTop_toBottomOf="@id/timePicker" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView> </ScrollView>

@ -462,8 +462,6 @@
<string name="title_undo">Undo</string> <string name="title_undo">Undo</string>
<string name="title_add">Add</string> <string name="title_add">Add</string>
<string name="title_browse">Browse</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_report">Report</string>
<string name="title_no_ask_again">Do not ask this again</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> <string name="title_no_adobe">Adobe Acrobat reader cannot open safely shared files, see the FAQ for more information</string>

Loading…
Cancel
Save