diff --git a/app/src/main/java/com/github/florent37/sample/singledateandtimepicker/SingleDatePickerMainActivityWithDoublePicker.java b/app/src/main/java/com/github/florent37/sample/singledateandtimepicker/SingleDatePickerMainActivityWithDoublePicker.java index a41ee34b..688fa9e7 100644 --- a/app/src/main/java/com/github/florent37/sample/singledateandtimepicker/SingleDatePickerMainActivityWithDoublePicker.java +++ b/app/src/main/java/com/github/florent37/sample/singledateandtimepicker/SingleDatePickerMainActivityWithDoublePicker.java @@ -219,6 +219,8 @@ public void doubleClicked() { .minDateRange(minDate) .maxDateRange(maxDate) + .secondDateAfterFirst(true) + //.defaultDate(now) .tab0Date(now) .tab1Date(new Date(now.getTime() + TimeUnit.HOURS.toMillis(1))) diff --git a/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/SingleDateAndTimePicker.java b/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/SingleDateAndTimePicker.java index 9310ee21..05ea8454 100644 --- a/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/SingleDateAndTimePicker.java +++ b/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/SingleDateAndTimePicker.java @@ -323,6 +323,12 @@ public void removeOnDateChangedListener(OnDateChangedListener listener) { this.listeners.remove(listener); } + public void checkPickersMinMax() { + for (WheelPicker picker : pickers) { + checkMinMaxDate(picker); + } + } + public Date getDate() { int hour = hoursPicker.getCurrentHour(); if (isAmPm && amPmPicker.isPm()) { diff --git a/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/dialog/DoubleDateAndTimePickerDialog.java b/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/dialog/DoubleDateAndTimePickerDialog.java index 1a5cb4cd..a9037543 100644 --- a/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/dialog/DoubleDateAndTimePickerDialog.java +++ b/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/dialog/DoubleDateAndTimePickerDialog.java @@ -1,20 +1,17 @@ package com.github.florent37.singledateandtimepicker.dialog; import android.content.Context; -import android.content.res.ColorStateList; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.StateListDrawable; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.util.StateSet; import android.view.View; import android.view.ViewTreeObserver; import android.widget.TextView; import com.github.florent37.singledateandtimepicker.R; import com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker; -import com.github.florent37.singledateandtimepicker.widget.WheelMinutePicker; import java.text.SimpleDateFormat; import java.util.Arrays; @@ -45,6 +42,7 @@ public class DoubleDateAndTimePickerDialog extends BaseDialog { private Date tab0Date; @Nullable private Date tab1Date; + private boolean secondDateAfterFirst; private DoubleDateAndTimePickerDialog(Context context) { this(context, false); @@ -227,6 +225,16 @@ public void onClick(View view) { pickerTab0.setDayFormatter(dayFormatter); pickerTab1.setDayFormatter(dayFormatter); } + + if (secondDateAfterFirst) { + pickerTab0.addOnDateChangedListener(new SingleDateAndTimePicker.OnDateChangedListener() { + @Override + public void onDateChanged(String displayed, Date date) { + pickerTab1.setMinDate(date); + pickerTab1.checkPickersMinMax(); + } + }); + } } @NonNull @@ -312,6 +320,11 @@ public DoubleDateAndTimePickerDialog setTab1Date(Date tab1Date) { return this; } + public DoubleDateAndTimePickerDialog setSecondDateAfterFirst(boolean secondDateAfterFirst) { + this.secondDateAfterFirst = secondDateAfterFirst; + return this; + } + @Override public void display() { super.display(); @@ -385,6 +398,7 @@ public static class Builder { private String todayText; private boolean curved; + private boolean secondDateAfterFirst; private boolean mustBeOnFuture; private int minutesStep = STEP_MINUTES_DEFAULT; @@ -513,6 +527,11 @@ public DoubleDateAndTimePickerDialog.Builder buttonOkText(@Nullable String butto return this; } + public DoubleDateAndTimePickerDialog.Builder secondDateAfterFirst(boolean secondDateAfterFirst) { + this.secondDateAfterFirst = secondDateAfterFirst; + return this; + } + public DoubleDateAndTimePickerDialog build() { final DoubleDateAndTimePickerDialog dialog = new DoubleDateAndTimePickerDialog(context, bottomSheet) .setTitle(title) @@ -529,7 +548,8 @@ public DoubleDateAndTimePickerDialog build() { .setTab0Date(tab0Date) .setTab1Date(tab1Date) .setDayFormatter(dayFormatter) - .setMustBeOnFuture(mustBeOnFuture); + .setMustBeOnFuture(mustBeOnFuture) + .setSecondDateAfterFirst(secondDateAfterFirst); if (mainColor != null) { dialog.setMainColor(mainColor);