diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogDuration.java b/app/src/main/java/eu/faircode/email/FragmentDialogDuration.java index c956eedfc7..db6b5594e5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogDuration.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogDuration.java @@ -25,6 +25,7 @@ import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; +import android.widget.Button; import android.widget.DatePicker; import android.widget.TextView; import android.widget.TimePicker; @@ -56,6 +57,8 @@ public class FragmentDialogDuration extends FragmentDialogEx { final View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_duration, null); final TextView tvDuration = dview.findViewById(R.id.tvDuration); + final Button btn1hour = dview.findViewById(R.id.btn1hour); + final Button btn1day = dview.findViewById(R.id.btn1day); final TimePicker timePicker = dview.findViewById(R.id.timePicker); final DatePicker datePicker = dview.findViewById(R.id.datePicker); @@ -77,6 +80,59 @@ public class FragmentDialogDuration extends FragmentDialogEx { timePicker.setMinute(cal.get(Calendar.MINUTE)); } + Dialog dialog = new AlertDialog.Builder(getContext()) + .setTitle(title) + .setView(dview) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + 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())); + + Bundle args = getArguments(); + args.putLong("duration", duration); + args.putLong("time", cal.getTimeInMillis()); + + sendResult(RESULT_OK); + } + }) + .create(); + + btn1hour.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dialog.dismiss(); + + long now = new Date().getTime(); + long duration = 3600 * 1000L; + + Bundle args = getArguments(); + args.putLong("duration", duration); + args.putLong("time", now + duration); + + sendResult(RESULT_OK); + } + }); + + btn1day.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dialog.dismiss(); + + long now = new Date().getTime(); + long duration = 24 * 3600 * 1000L; + + Bundle args = getArguments(); + args.putLong("duration", duration); + args.putLong("time", now + duration); + + sendResult(RESULT_OK); + } + }); + timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Override public void onTimeChanged(TimePicker view, int hour, int minute) { @@ -105,25 +161,6 @@ public class FragmentDialogDuration extends FragmentDialogEx { } ); - return new AlertDialog.Builder(getContext()) - .setTitle(title) - .setView(dview) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - 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())); - - Bundle args = getArguments(); - args.putLong("duration", duration); - args.putLong("time", cal.getTimeInMillis()); - - sendResult(RESULT_OK); - } - }) - .create(); + return dialog; } } diff --git a/app/src/main/res/layout/dialog_duration.xml b/app/src/main/res/layout/dialog_duration.xml index fbe084ad47..e59e43f450 100644 --- a/app/src/main/res/layout/dialog_duration.xml +++ b/app/src/main/res/layout/dialog_duration.xml @@ -21,6 +21,32 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> +