Skip to content

Commit

Permalink
#2
Browse files Browse the repository at this point in the history
Added support for min and max date
  • Loading branch information
jonatansalas committed Jan 11, 2017
1 parent ef67e12 commit c304742
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@

import java.util.Calendar;

import io.blackbox_vision.datetimepickeredittext.internal.utils.DateUtils;

import static android.app.DatePickerDialog.*;


public final class DatePickerFragment extends DialogFragment {
private static final String DEFAULT_TEMPLATE = "dd/MM/yyyy";
private static final String DEFAULT_MIN_DATE = "01/01/1980";
private static final String DEFAULT_MAX_DATE = "01/01/2100";

private OnDateSetListener onDateSetListener;
private Calendar date;

private Long minDate;
private Long maxDate;
private String minDate;
private String maxDate;

private Integer themeId;

Expand Down Expand Up @@ -45,8 +51,14 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
datePickerDialog = new DatePickerDialog(getActivity(), onDateSetListener, year, month, day);
}

datePickerDialog.getDatePicker().setMinDate(minDate);
datePickerDialog.getDatePicker().setMaxDate(maxDate);
final String minDateStr = null != minDate? minDate : DEFAULT_MIN_DATE;
final String maxDateStr = null != maxDate? maxDate : DEFAULT_MAX_DATE;

final long min = DateUtils.parse(minDateStr, DEFAULT_TEMPLATE).getTime();
final long max = DateUtils.parse(maxDateStr, DEFAULT_TEMPLATE).getTime();

datePickerDialog.getDatePicker().setMinDate(min);
datePickerDialog.getDatePicker().setMaxDate(max);

return datePickerDialog;
}
Expand Down Expand Up @@ -78,20 +90,20 @@ public DatePickerFragment setThemeId(Integer themeId) {
return this;
}

public Long getMaxDate() {
public String getMaxDate() {
return maxDate;
}

public DatePickerFragment setMaxDate(Long maxDate) {
public DatePickerFragment setMaxDate(String maxDate) {
this.maxDate = maxDate;
return this;
}

public Long getMinDate() {
public String getMinDate() {
return minDate;
}

public DatePickerFragment setMinDate(Long minDate) {
public DatePickerFragment setMinDate(String minDate) {
this.minDate = minDate;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
public final class DatePickerEditText extends EditText implements OnFocusChangeListener, OnDateSetListener {
private static final String TAG = DatePickerEditText.class.getSimpleName();

private static final String DEFAULT_TEMPLATE = "dd/MM/yyyy";
private static final String DEFAULT_MIN_DATE = "01/01/1980";
private static final String DEFAULT_MAX_DATE = "01/01/2100";

private OnFocusChangeListener onFocusChangedListener;

private FragmentManager manager;
Expand Down Expand Up @@ -85,20 +81,12 @@ public void onFocusChange(View view, boolean isFocused) {
imm.hideSoftInputFromWindow(getWindowToken(), 0);

if (isFocused) {
final String minDateStr = null != minDate? minDate : DEFAULT_MIN_DATE;
final String maxDateStr = null != maxDate? maxDate : DEFAULT_MAX_DATE;

final long min = DateUtils.parse(minDateStr, null != minDate? dateFormat : DEFAULT_TEMPLATE).getTime();
final long max = DateUtils.parse(maxDateStr, null != maxDate? dateFormat : DEFAULT_TEMPLATE).getTime();

final DatePickerFragment datePickerFragment = new DatePickerFragment();

datePickerFragment.setDate(date);
datePickerFragment.setThemeId(themeId);
datePickerFragment.setOnDateSetListener(this);

datePickerFragment.setMinDate(min);
datePickerFragment.setMaxDate(max);
final DatePickerFragment datePickerFragment = new DatePickerFragment()
.setDate(date)
.setThemeId(themeId)
.setOnDateSetListener(this)
.setMinDate(minDate)
.setMaxDate(maxDate);

datePickerFragment.show(manager, TAG);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
public final class DatePickerInputEditText extends TextInputEditText implements OnFocusChangeListener, OnDateSetListener {
private static final String TAG = DatePickerInputEditText.class.getSimpleName();

private static final String DEFAULT_TEMPLATE = "dd/MM/yyyy";
private static final String DEFAULT_MIN_DATE = "01/01/1980";
private static final String DEFAULT_MAX_DATE = "01/01/2100";

private OnFocusChangeListener onFocusChangedListener;

private FragmentManager manager;
Expand Down Expand Up @@ -85,20 +81,12 @@ public void onFocusChange(View view, boolean isFocused) {
imm.hideSoftInputFromWindow(getWindowToken(), 0);

if (isFocused) {
final String minDateStr = null != minDate? minDate : DEFAULT_MIN_DATE;
final String maxDateStr = null != maxDate? maxDate : DEFAULT_MAX_DATE;

final long min = DateUtils.parse(minDateStr, null != minDate? dateFormat : DEFAULT_TEMPLATE).getTime();
final long max = DateUtils.parse(maxDateStr, null != maxDate? dateFormat : DEFAULT_TEMPLATE).getTime();

final DatePickerFragment datePickerFragment = new DatePickerFragment();

datePickerFragment.setDate(date);
datePickerFragment.setThemeId(themeId);
datePickerFragment.setOnDateSetListener(this);

datePickerFragment.setMinDate(min);
datePickerFragment.setMaxDate(max);
final DatePickerFragment datePickerFragment = new DatePickerFragment()
.setDate(date)
.setThemeId(themeId)
.setOnDateSetListener(this)
.setMinDate(minDate)
.setMaxDate(maxDate);

datePickerFragment.show(manager, TAG);
}
Expand Down

0 comments on commit c304742

Please sign in to comment.