Skip to content

Commit

Permalink
Merge pull request prolificinteractive#515 from prolificinteractive/q…
Browse files Browse the repository at this point in the history
…c_naming_documentation

Fix - Naming for saveCurrentPosition to cacheCurrentPosition
  • Loading branch information
quentin41500 authored Feb 16, 2017
2 parents 30da68b + 6fb9730 commit c210955
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ protected Parcelable onSaveInstanceState() {
ss.calendarMode = calendarMode;
ss.dynamicHeightEnabled = mDynamicHeightEnabled;
ss.currentMonth = currentMonth;
ss.saveCurrentPosition = state.saveCurrentPosition;
ss.cacheCurrentPosition = state.cacheCurrentPosition;
return ss;
}

Expand All @@ -1095,7 +1095,7 @@ protected void onRestoreInstanceState(Parcelable state) {
.setCalendarDisplayMode(ss.calendarMode)
.setMinimumDate(ss.minDate)
.setMaximumDate(ss.maxDate)
.setSaveCurrentPosition(ss.saveCurrentPosition)
.isCacheCalendarPositionEnabled(ss.cacheCurrentPosition)
.commit();

setSelectionColor(ss.color);
Expand Down Expand Up @@ -1157,7 +1157,7 @@ public static class SavedState extends BaseSavedState {
boolean dynamicHeightEnabled = false;
CalendarMode calendarMode = CalendarMode.MONTHS;
CalendarDay currentMonth = null;
boolean saveCurrentPosition;
boolean cacheCurrentPosition;

SavedState(Parcelable superState) {
super(superState);
Expand All @@ -1183,7 +1183,7 @@ public void writeToParcel(@NonNull Parcel out, int flags) {
out.writeInt(dynamicHeightEnabled ? 1 : 0);
out.writeInt(calendarMode == CalendarMode.WEEKS ? 1 : 0);
out.writeParcelable(currentMonth, 0);
out.writeByte((byte) (saveCurrentPosition ? 1 : 0));
out.writeByte((byte) (cacheCurrentPosition ? 1 : 0));
}

public static final Parcelable.Creator<SavedState> CREATOR
Expand Down Expand Up @@ -1217,7 +1217,7 @@ private SavedState(Parcel in) {
dynamicHeightEnabled = in.readInt() == 1;
calendarMode = in.readInt() == 1 ? CalendarMode.WEEKS : CalendarMode.MONTHS;
currentMonth = in.readParcelable(loader);
saveCurrentPosition = in.readByte() != 0;
cacheCurrentPosition = in.readByte() != 0;
}
}

Expand Down Expand Up @@ -1805,18 +1805,18 @@ public StateBuilder newState() {
}

public class State {
public final CalendarMode calendarMode;
public final int firstDayOfWeek;
public final CalendarDay minDate;
public final CalendarDay maxDate;
public final boolean saveCurrentPosition;
private final CalendarMode calendarMode;
private final int firstDayOfWeek;
private final CalendarDay minDate;
private final CalendarDay maxDate;
private final boolean cacheCurrentPosition;

public State(StateBuilder builder) {
private State(final StateBuilder builder) {
calendarMode = builder.calendarMode;
firstDayOfWeek = builder.firstDayOfWeek;
minDate = builder.minDate;
maxDate = builder.maxDate;
saveCurrentPosition = builder.saveCurrentPosition;
cacheCurrentPosition = builder.cacheCurrentPosition;
}

/**
Expand All @@ -1831,9 +1831,9 @@ public StateBuilder edit() {
public class StateBuilder {
private CalendarMode calendarMode = CalendarMode.MONTHS;
private int firstDayOfWeek = Calendar.getInstance().getFirstDayOfWeek();
public CalendarDay minDate = null;
public CalendarDay maxDate = null;
public boolean saveCurrentPosition = false;
private boolean cacheCurrentPosition = false;
private CalendarDay minDate = null;
private CalendarDay maxDate = null;

public StateBuilder() {
}
Expand All @@ -1843,7 +1843,7 @@ private StateBuilder(final State state) {
firstDayOfWeek = state.firstDayOfWeek;
minDate = state.minDate;
maxDate = state.maxDate;
saveCurrentPosition = state.saveCurrentPosition;
cacheCurrentPosition = state.cacheCurrentPosition;
}

/**
Expand Down Expand Up @@ -1921,13 +1921,15 @@ public StateBuilder setMaximumDate(@Nullable CalendarDay calendar) {
}

/**
* Use this method to enable saving the current position when switching
* between week and month mode.
* Use this method to enable saving the current position when switching
* between week and month mode. By default, the calendar update to the latest selected date
* or the current date. When set to true, the view will used the month that the calendar is
* currently on.
*
* @param saveCurrentPosition Set to true to save the current position, false otherwise.
* @param cacheCurrentPosition Set to true to cache the current position, false otherwise.
*/
public StateBuilder setSaveCurrentPosition(final boolean saveCurrentPosition) {
this.saveCurrentPosition = saveCurrentPosition;
public StateBuilder isCacheCalendarPositionEnabled(final boolean cacheCurrentPosition) {
this.cacheCurrentPosition = cacheCurrentPosition;
return this;
}

Expand All @@ -1939,7 +1941,7 @@ public void commit() {
private void commit(State state) {
// Use the calendarDayToShow to determine which date to focus on for the case of switching between month and week views
CalendarDay calendarDayToShow = null;
if (adapter != null && state.saveCurrentPosition) {
if (adapter != null && state.cacheCurrentPosition) {
calendarDayToShow = adapter.getItem(pager.getCurrentItem());
if (calendarMode != state.calendarMode) {
CalendarDay currentlySelectedDate = getSelectedDate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void onClick(DialogInterface dialog, int which, boolean isChecked) {
@OnCheckedChanged(R.id.enable_save_current_position)
void onSaveCurrentPositionChecked(boolean checked) {
widget.state().edit()
.setSaveCurrentPosition(checked)
.isCacheCalendarPositionEnabled(checked)
.commit();
}

Expand Down

0 comments on commit c210955

Please sign in to comment.