Skip to content

Commit

Permalink
added option secondDateAfterFirst in DoubleDateAndTimePickerDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
bshka committed Apr 25, 2018
1 parent b7d9496 commit db112c9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit db112c9

Please sign in to comment.