From d86af9125ad624a26a41775b90bb180407785f7e Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Wed, 3 Feb 2016 14:18:19 -0600 Subject: [PATCH] Fix date picker bug --- .../tasks/activities/DateAndTimePickerActivity.java | 4 +++- .../java/org/tasks/activities/DatePickerActivity.java | 11 ++--------- src/main/java/org/tasks/time/DateTime.java | 4 ++++ src/main/java/org/tasks/ui/DeadlineControlSet.java | 10 +++++----- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/tasks/activities/DateAndTimePickerActivity.java b/src/main/java/org/tasks/activities/DateAndTimePickerActivity.java index 06813c4e8..9a201cbea 100644 --- a/src/main/java/org/tasks/activities/DateAndTimePickerActivity.java +++ b/src/main/java/org/tasks/activities/DateAndTimePickerActivity.java @@ -67,7 +67,9 @@ public class DateAndTimePickerActivity extends InjectingAppCompatActivity implem @Override public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) { dateSelected = true; - final long timestamp = initial.withYear(year).withMonthOfYear(month + 1).withDayOfMonth(day).getMillis(); + final long timestamp = new DateTime(year, month + 1, day) + .withMillisOfDay(initial.getMillisOfDay()) + .getMillis(); datePickerDialog.dismiss(); startActivity(new Intent(this, TimePickerActivity.class) {{ addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); diff --git a/src/main/java/org/tasks/activities/DatePickerActivity.java b/src/main/java/org/tasks/activities/DatePickerActivity.java index b9573e852..06ee57a67 100644 --- a/src/main/java/org/tasks/activities/DatePickerActivity.java +++ b/src/main/java/org/tasks/activities/DatePickerActivity.java @@ -26,8 +26,6 @@ public class DatePickerActivity extends InjectingAppCompatActivity @Inject ActivityPreferences preferences; - private DateTime initial; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -35,7 +33,7 @@ public class DatePickerActivity extends InjectingAppCompatActivity preferences.applyTheme(); long timestamp = getIntent().getLongExtra(EXTRA_TIMESTAMP, currentTimeMillis()); - initial = timestamp > 0 ? new DateTime(timestamp) : new DateTime().startOfDay(); + DateTime initial = (timestamp > 0 ? new DateTime(timestamp) : new DateTime()).startOfDay(); FragmentManager fragmentManager = getFragmentManager(); MyDatePickerDialog dialog = (MyDatePickerDialog) fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER); @@ -51,15 +49,10 @@ public class DatePickerActivity extends InjectingAppCompatActivity dialog.setOnDateSetListener(this); } - @Override public void onDateSet(DatePickerDialog view, final int year, final int monthOfYear, final int dayOfMonth) { setResult(RESULT_OK, new Intent() {{ - putExtra(EXTRA_TIMESTAMP, initial - .withYear(year) - .withMonthOfYear(monthOfYear + 1) - .withDayOfMonth(dayOfMonth) - .getMillis()); + putExtra(EXTRA_TIMESTAMP, new DateTime(year, monthOfYear + 1, dayOfMonth).getMillis()); }}); } diff --git a/src/main/java/org/tasks/time/DateTime.java b/src/main/java/org/tasks/time/DateTime.java index 787f373fe..188f64c00 100644 --- a/src/main/java/org/tasks/time/DateTime.java +++ b/src/main/java/org/tasks/time/DateTime.java @@ -17,6 +17,10 @@ public class DateTime { private final TimeZone timeZone; private final long timestamp; + public DateTime(int year, int month, int day) { + this(year, month, day, 0, 0, 0, 0); + } + public DateTime(int year, int month, int day, int hour, int minute) { this(year, month, day, hour, minute, 0, 0); } diff --git a/src/main/java/org/tasks/ui/DeadlineControlSet.java b/src/main/java/org/tasks/ui/DeadlineControlSet.java index b43b4504a..b590d6a76 100644 --- a/src/main/java/org/tasks/ui/DeadlineControlSet.java +++ b/src/main/java/org/tasks/ui/DeadlineControlSet.java @@ -206,7 +206,7 @@ public class DeadlineControlSet extends TaskEditControlFragment { break; case 4: startActivityForResult(new Intent(context, DatePickerActivity.class) {{ - putExtra(DatePickerActivity.EXTRA_TIMESTAMP, getDueDate()); + putExtra(DatePickerActivity.EXTRA_TIMESTAMP, date); }}, REQUEST_DATE); break; } @@ -234,7 +234,7 @@ public class DeadlineControlSet extends TaskEditControlFragment { break; case 6: startActivityForResult(new Intent(context, TimePickerActivity.class) {{ - putExtra(TimePickerActivity.EXTRA_TIMESTAMP, getDueDate()); + putExtra(TimePickerActivity.EXTRA_TIMESTAMP, getDueDateTime()); }}, REQUEST_TIME); break; } @@ -257,7 +257,7 @@ public class DeadlineControlSet extends TaskEditControlFragment { @Override public boolean hasChanges(Task original) { - return original.getDueDate() != getDueDate(); + return original.getDueDate() != getDueDateTime(); } @Override @@ -274,7 +274,7 @@ public class DeadlineControlSet extends TaskEditControlFragment { @Override public void apply(Task task) { - long dueDate = getDueDate(); + long dueDate = getDueDateTime(); if (dueDate != task.getDueDate()) { task.setReminderSnooze(0L); } @@ -304,7 +304,7 @@ public class DeadlineControlSet extends TaskEditControlFragment { } } - private long getDueDate() { + private long getDueDateTime() { return time >= 0 ? Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, newDateTime(date).withMillisOfDay(time).getMillis()) : Task.createDueDate(Task.URGENCY_SPECIFIC_DAY, date);