diff --git a/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java b/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java index e55c99c5..bf6d0b6c 100644 --- a/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java +++ b/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java @@ -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; } @@ -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); @@ -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); @@ -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 CREATOR @@ -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; } } @@ -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; } /** @@ -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() { } @@ -1843,7 +1843,7 @@ private StateBuilder(final State state) { firstDayOfWeek = state.firstDayOfWeek; minDate = state.minDate; maxDate = state.maxDate; - saveCurrentPosition = state.saveCurrentPosition; + cacheCurrentPosition = state.cacheCurrentPosition; } /** @@ -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; } @@ -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(); diff --git a/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/DynamicSettersActivity.java b/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/DynamicSettersActivity.java index 3df72d9a..cceedebc 100644 --- a/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/DynamicSettersActivity.java +++ b/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/DynamicSettersActivity.java @@ -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(); }