From 8aff26c4b004eab74af6c57b5fb6da4cd66fa34b Mon Sep 17 00:00:00 2001 From: Quentin Colle Date: Tue, 14 Feb 2017 17:00:37 -0500 Subject: [PATCH 1/2] Update naming for caching position when switching mock mode --- .../MaterialCalendarView.java | 36 ++++++++++--------- .../sample/DynamicSettersActivity.java | 2 +- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java b/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java index dee79995..faabdfe0 100644 --- a/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java +++ b/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java @@ -1097,7 +1097,7 @@ protected void onRestoreInstanceState(Parcelable state) { .setCalendarDisplayMode(ss.calendarMode) .setMinimumDate(ss.minDate) .setMaximumDate(ss.maxDate) - .setSaveCurrentPosition(ss.saveCurrentPosition) + .isCacheCalendarPositionEnabled(ss.saveCurrentPosition) .commit(); setSelectionColor(ss.color); @@ -1798,18 +1798,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 saveCurrentPosition; - public State(StateBuilder builder) { + private State(final StateBuilder builder) { calendarMode = builder.calendarMode; firstDayOfWeek = builder.firstDayOfWeek; minDate = builder.minDate; maxDate = builder.maxDate; - saveCurrentPosition = builder.saveCurrentPosition; + saveCurrentPosition = builder.cacheCurrentPosition; } /** @@ -1824,9 +1824,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() { } @@ -1836,7 +1836,7 @@ private StateBuilder(final State state) { firstDayOfWeek = state.firstDayOfWeek; minDate = state.minDate; maxDate = state.maxDate; - saveCurrentPosition = state.saveCurrentPosition; + cacheCurrentPosition = state.saveCurrentPosition; } /** @@ -1914,13 +1914,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; } 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 1966607a..dce09447 100644 --- a/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/DynamicSettersActivity.java +++ b/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/DynamicSettersActivity.java @@ -93,7 +93,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(); } From 57ee7b1ab3d91e9cebe729716f1f3699e277ea7a Mon Sep 17 00:00:00 2001 From: Quentin Colle Date: Tue, 14 Feb 2017 17:02:51 -0500 Subject: [PATCH 2/2] Forgotten saveCurrentPosition renamed --- .../MaterialCalendarView.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java b/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java index faabdfe0..b1523631 100644 --- a/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java +++ b/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java @@ -1084,7 +1084,7 @@ protected Parcelable onSaveInstanceState() { ss.calendarMode = calendarMode; ss.dynamicHeightEnabled = mDynamicHeightEnabled; ss.currentMonth = currentMonth; - ss.saveCurrentPosition = state.saveCurrentPosition; + ss.cacheCurrentPosition = state.cacheCurrentPosition; return ss; } @@ -1097,7 +1097,7 @@ protected void onRestoreInstanceState(Parcelable state) { .setCalendarDisplayMode(ss.calendarMode) .setMinimumDate(ss.minDate) .setMaximumDate(ss.maxDate) - .isCacheCalendarPositionEnabled(ss.saveCurrentPosition) + .isCacheCalendarPositionEnabled(ss.cacheCurrentPosition) .commit(); setSelectionColor(ss.color); @@ -1159,7 +1159,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); @@ -1185,7 +1185,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 @@ -1219,7 +1219,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; } } @@ -1802,14 +1802,14 @@ public class State { private final int firstDayOfWeek; private final CalendarDay minDate; private final CalendarDay maxDate; - private final boolean saveCurrentPosition; + private final boolean cacheCurrentPosition; private State(final StateBuilder builder) { calendarMode = builder.calendarMode; firstDayOfWeek = builder.firstDayOfWeek; minDate = builder.minDate; maxDate = builder.maxDate; - saveCurrentPosition = builder.cacheCurrentPosition; + cacheCurrentPosition = builder.cacheCurrentPosition; } /** @@ -1836,7 +1836,7 @@ private StateBuilder(final State state) { firstDayOfWeek = state.firstDayOfWeek; minDate = state.minDate; maxDate = state.maxDate; - cacheCurrentPosition = state.saveCurrentPosition; + cacheCurrentPosition = state.cacheCurrentPosition; } /** @@ -1934,7 +1934,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();