Fix date picker bug

pull/384/head
Alex Baker 9 years ago
parent 607cb2afdb
commit d86af9125a

@ -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);

@ -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());
}});
}

@ -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);
}

@ -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);

Loading…
Cancel
Save