Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libs - Material calendar to 1.4.0, RN to 0.20 #12

Merged
merged 2 commits into from
Aug 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ android {

dependencies {
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.facebook.react:react-native:0.19.+'
compile 'com.prolificinteractive:material-calendarview:1.1.0'
compile 'com.facebook.react:react-native:0.20.+'
compile 'com.prolificinteractive:material-calendarview:1.4.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ public void setArrowColor(Calendar view, String color) {
@ReactProp(name = "firstDayOfWeek")
public void setFirstDayOfWeek(Calendar view, String firstDayOfWeek) {
if (firstDayOfWeek != null) {
view.setFirstDayOfWeek(getFirstDayOfWeekFromString(firstDayOfWeek));
view.state().edit()
.setFirstDayOfWeek(getFirstDayOfWeekFromString(firstDayOfWeek))
.commit();
}
}

Expand Down Expand Up @@ -130,6 +132,62 @@ public void setCurrentDate(Calendar view, ReadableArray data) {
}
}

@ReactProp(name = "minimumDate")
public void setMinimumDate(Calendar view, ReadableArray data) {
String type = data.getType(0).name();
if ("String".equals(type)) {
try {
Date date = dateFormat.parse(data.getString(0));
if (shouldUpdateMinMaxDate(view.getMinimumDate(), date)) {
view.state().edit()
.setMinimumDate(date)
.commit();
}
} catch (ParseException e) {
throw new JSApplicationIllegalArgumentException("Invalid date format: " + data.getString(0));
}
} else if ("Number".equals(type)) {
Double value = data.getDouble(0);
Date date = new Date(value.longValue());
if (shouldUpdateMinMaxDate(view.getMinimumDate(), date)) {
view.state().edit()
.setMinimumDate(date)
.commit();
}
} else {
throw new JSApplicationIllegalArgumentException("Invalid date format: " + data.getString(0));
}
}

@ReactProp(name = "maximumDate")
public void setMaximumDate(Calendar view, ReadableArray data) {
String type = data.getType(0).name();

if ("String".equals(type)) {
try {
Date date = dateFormat.parse(data.getString(0));
if (shouldUpdateMinMaxDate(view.getMaximumDate(), date)) {
view.state().edit()
.setMaximumDate(date)
.commit();
}
} catch (ParseException e) {
throw new JSApplicationIllegalArgumentException("Invalid date format: " + data.getString(0));
}
} else if ("Number".equals(type)) {
Double value = data.getDouble(0);
Date date = new Date(value.longValue());

if (shouldUpdateMinMaxDate(view.getMaximumDate(), date)) {
view.state().edit()
.setMaximumDate(date)
.commit();
}
} else {
throw new JSApplicationIllegalArgumentException("Invalid date format: " + data.getString(0));
}
}

@ReactProp(name = "selectionMode")
public void setSelectionMode(Calendar view, String mode) {
if (mode != null) {
Expand Down Expand Up @@ -200,4 +258,26 @@ private int getFirstDayOfWeekFromString(String firstDayOfWeek) {
throw new JSApplicationIllegalArgumentException("Unknown firstDayOfWeek property: " + firstDayOfWeek);
}
}

/**
* Should update new value of minimum or maximum date
*
* Check if the new min or max date is different from the previous one, if yes we update otherwise we don't.
*
* @param minMaxDate
* @param newDate
* @return boolean
*/
private boolean shouldUpdateMinMaxDate(CalendarDay minMaxDate, Date newDate) {
if (minMaxDate == null) {
return true;
}

java.util.Calendar newDateCalendar = java.util.Calendar.getInstance();
newDateCalendar.setTimeInMillis(newDate.getTime());

return (minMaxDate.getYear() != newDateCalendar.get(java.util.Calendar.YEAR) &&
minMaxDate.getMonth() != newDateCalendar.get(java.util.Calendar.MONTH) &&
minMaxDate.getDay() != newDateCalendar.get(java.util.Calendar.DAY_OF_MONTH));
}
}