Added more duration options

pull/212/head
M66B 2 years ago
parent e1bb4034a4
commit 4a0e57e275

@ -30,6 +30,7 @@ import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
@ -39,6 +40,7 @@ import android.widget.TimePicker;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.preference.PreferenceManager;
import java.text.DateFormat;
@ -68,10 +70,10 @@ public class FragmentDialogDuration extends FragmentDialogBase {
int default_snooze = prefs.getInt("default_snooze", 1);
final View dview = LayoutInflater.from(context).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 Button btn1week = dview.findViewById(R.id.btn1week);
final Button btnMore = dview.findViewById(R.id.btnMore);
final TextView tvDuration = dview.findViewById(R.id.tvDuration);
final TimePicker timePicker = dview.findViewById(R.id.timePicker);
final DatePicker datePicker = dview.findViewById(R.id.datePicker);
@ -144,8 +146,6 @@ public class FragmentDialogDuration extends FragmentDialogBase {
long duration = 3600 * 1000L;
if (view.getId() != R.id.btn1hour)
duration *= 24;
if (view.getId() == R.id.btn1week)
duration *= 7;
Bundle args = getArguments();
args.putLong("duration", duration);
@ -157,7 +157,109 @@ public class FragmentDialogDuration extends FragmentDialogBase {
btn1hour.setOnClickListener(buttonListener);
btn1day.setOnClickListener(buttonListener);
btn1week.setOnClickListener(buttonListener);
btnMore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Context context = v.getContext();
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, getViewLifecycleOwner(), btnMore);
popupMenu.inflate(R.menu.menu_duration);
DateFormat dtf = Helper.getTimeInstance(context, SimpleDateFormat.SHORT);
Calendar cal = Calendar.getInstance();
long now = cal.getTimeInMillis();
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.HOUR_OF_DAY, 8);
long morning = cal.getTimeInMillis();
String at8am = dtf.format(cal.getTimeInMillis());
cal.set(Calendar.HOUR_OF_DAY, 12);
long afternoon = cal.getTimeInMillis();
String at12pm = dtf.format(cal.getTimeInMillis());
cal.set(Calendar.HOUR_OF_DAY, 18);
long evening = cal.getTimeInMillis();
String at18pm = dtf.format(cal.getTimeInMillis());
popupMenu.getMenu().findItem(R.id.menu_this_afternoon)
.setTitle(getString(R.string.title_today_at, at12pm))
.setVisible(now < afternoon);
popupMenu.getMenu().findItem(R.id.menu_this_evening)
.setTitle(getString(R.string.title_today_at, at18pm))
.setVisible(now < evening);
popupMenu.getMenu().findItem(R.id.menu_tomorrow_morning)
.setTitle(getString(R.string.title_tomorrow_at, at8am));
popupMenu.getMenu().findItem(R.id.menu_tomorrow_afternoon)
.setTitle(getString(R.string.title_tomorrow_at, at12pm));
popupMenu.getMenu().findItem(R.id.menu_after_tomorrow_morning)
.setTitle(getString(R.string.title_after_tomorrow_at, at8am));
popupMenu.getMenu().findItem(R.id.menu_after_tomorrow_afternoon)
.setTitle(getString(R.string.title_after_tomorrow_at, at12pm));
popupMenu.getMenu().findItem(R.id.menu_saturday_norming)
.setTitle(getString(R.string.title_saturday_at, at8am));
popupMenu.getMenu().findItem(R.id.menu_monday_norming)
.setTitle(getString(R.string.title_monday_at, at8am));
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
dialog.dismiss();
Calendar cal = Calendar.getInstance();
long now = cal.getTimeInMillis();
int itemId = item.getItemId();
if (itemId == R.id.menu_tomorrow_morning ||
itemId == R.id.menu_after_tomorrow_morning ||
itemId == R.id.menu_saturday_norming ||
itemId == R.id.menu_monday_norming) {
cal.set(Calendar.HOUR_OF_DAY, 8);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
if (itemId == R.id.menu_tomorrow_morning)
cal.add(Calendar.DATE, 1);
else if (itemId == R.id.menu_after_tomorrow_morning)
cal.add(Calendar.DATE, 2);
else if (itemId == R.id.menu_saturday_norming) {
cal.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
if (cal.getTimeInMillis() < now)
cal.add(Calendar.DATE, 7);
} else if (itemId == R.id.menu_monday_norming) {
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
if (cal.getTimeInMillis() < now)
cal.add(Calendar.DATE, 7);
}
} else if (itemId == R.id.menu_this_afternoon ||
itemId == R.id.menu_tomorrow_afternoon ||
itemId == R.id.menu_after_tomorrow_afternoon) {
cal.set(Calendar.HOUR_OF_DAY, 12);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
if (itemId == R.id.menu_tomorrow_afternoon)
cal.add(Calendar.DATE, 1);
else if (itemId == R.id.menu_after_tomorrow_afternoon)
cal.add(Calendar.DATE, 2);
} else if (itemId == R.id.menu_this_evening) {
cal.set(Calendar.HOUR_OF_DAY, 18);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
} else if (itemId == R.id.menu_next_week)
cal.add(Calendar.DATE, 7);
Bundle args = getArguments();
args.putLong("duration", cal.getTimeInMillis() - now);
args.putLong("time", cal.getTimeInMillis());
sendResult(RESULT_OK);
return false;
}
});
popupMenu.show();
}
});
timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
@Override

@ -4,56 +4,54 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="false"
android:padding="24dp"
android:padding="12dp"
android:scrollbarStyle="outsideOverlay">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Thursday 28 February 2019 06:45 am"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn1hour"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_1hour"
app:layout_constraintEnd_toStartOf="@+id/btn1day"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDuration" />
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn1day"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_1day"
app:layout_constraintEnd_toStartOf="@+id/btn1week"
app:layout_constraintEnd_toStartOf="@+id/btnMore"
app:layout_constraintStart_toEndOf="@id/btn1hour"
app:layout_constraintTop_toBottomOf="@id/tvDuration" />
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn1week"
android:id="@+id/btnMore"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_1week"
android:text="@string/title_more_overflow"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/btn1day"
app:layout_constraintTop_toBottomOf="@id/tvDuration" />
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="Thursday 28 February 2019 06:45 am"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn1hour" />
<TimePicker
android:id="@+id/timePicker"
@ -63,7 +61,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_max="180dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn1hour" />
app:layout_constraintTop_toBottomOf="@id/tvDuration" />
<DatePicker
android:id="@+id/datePicker"

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_this_afternoon"
android:title="@string/title_today_at" />
<item
android:id="@+id/menu_this_evening"
android:title="@string/title_today_at" />
<item
android:id="@+id/menu_tomorrow_morning"
android:title="@string/title_tomorrow_at" />
<item
android:id="@+id/menu_tomorrow_afternoon"
android:title="@string/title_tomorrow_at" />
<item
android:id="@+id/menu_after_tomorrow_morning"
android:title="@string/title_after_tomorrow_at" />
<item
android:id="@+id/menu_after_tomorrow_afternoon"
android:title="@string/title_after_tomorrow_at" />
<item
android:id="@+id/menu_saturday_norming"
android:title="@string/title_saturday_at" />
<item
android:id="@+id/menu_monday_norming"
android:title="@string/title_monday_at" />
<item
android:id="@+id/menu_next_week"
android:title="@string/title_next_week" />
</menu>

@ -2107,7 +2107,13 @@
<string name="title_via">Via: %1$s</string>
<string name="title_1hour">1 hour</string>
<string name="title_1day">1 day</string>
<string name="title_1week">1 week</string>
<string name="title_more_overflow">More &#8230;</string>
<string name="title_today_at">Today at %1$s</string>
<string name="title_tomorrow_at">Tomorrow at %1$s</string>
<string name="title_after_tomorrow_at">After tomorrow at %1$s</string>
<string name="title_saturday_at">Saturday at %1$s</string>
<string name="title_monday_at">Monday at %1$s</string>
<string name="title_next_week">This time next week</string>
<string name="title_now">Now</string>
<string name="title_after">After %1$s</string>
<string name="title_reset">Reset</string>

Loading…
Cancel
Save