Skip to content

Commit c210955

Browse files
authored
Merge pull request #515 from prolificinteractive/qc_naming_documentation
Fix - Naming for saveCurrentPosition to cacheCurrentPosition
2 parents 30da68b + 6fb9730 commit c210955

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java

+24-22
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ protected Parcelable onSaveInstanceState() {
10821082
ss.calendarMode = calendarMode;
10831083
ss.dynamicHeightEnabled = mDynamicHeightEnabled;
10841084
ss.currentMonth = currentMonth;
1085-
ss.saveCurrentPosition = state.saveCurrentPosition;
1085+
ss.cacheCurrentPosition = state.cacheCurrentPosition;
10861086
return ss;
10871087
}
10881088

@@ -1095,7 +1095,7 @@ protected void onRestoreInstanceState(Parcelable state) {
10951095
.setCalendarDisplayMode(ss.calendarMode)
10961096
.setMinimumDate(ss.minDate)
10971097
.setMaximumDate(ss.maxDate)
1098-
.setSaveCurrentPosition(ss.saveCurrentPosition)
1098+
.isCacheCalendarPositionEnabled(ss.cacheCurrentPosition)
10991099
.commit();
11001100

11011101
setSelectionColor(ss.color);
@@ -1157,7 +1157,7 @@ public static class SavedState extends BaseSavedState {
11571157
boolean dynamicHeightEnabled = false;
11581158
CalendarMode calendarMode = CalendarMode.MONTHS;
11591159
CalendarDay currentMonth = null;
1160-
boolean saveCurrentPosition;
1160+
boolean cacheCurrentPosition;
11611161

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

11891189
public static final Parcelable.Creator<SavedState> CREATOR
@@ -1217,7 +1217,7 @@ private SavedState(Parcel in) {
12171217
dynamicHeightEnabled = in.readInt() == 1;
12181218
calendarMode = in.readInt() == 1 ? CalendarMode.WEEKS : CalendarMode.MONTHS;
12191219
currentMonth = in.readParcelable(loader);
1220-
saveCurrentPosition = in.readByte() != 0;
1220+
cacheCurrentPosition = in.readByte() != 0;
12211221
}
12221222
}
12231223

@@ -1805,18 +1805,18 @@ public StateBuilder newState() {
18051805
}
18061806

18071807
public class State {
1808-
public final CalendarMode calendarMode;
1809-
public final int firstDayOfWeek;
1810-
public final CalendarDay minDate;
1811-
public final CalendarDay maxDate;
1812-
public final boolean saveCurrentPosition;
1808+
private final CalendarMode calendarMode;
1809+
private final int firstDayOfWeek;
1810+
private final CalendarDay minDate;
1811+
private final CalendarDay maxDate;
1812+
private final boolean cacheCurrentPosition;
18131813

1814-
public State(StateBuilder builder) {
1814+
private State(final StateBuilder builder) {
18151815
calendarMode = builder.calendarMode;
18161816
firstDayOfWeek = builder.firstDayOfWeek;
18171817
minDate = builder.minDate;
18181818
maxDate = builder.maxDate;
1819-
saveCurrentPosition = builder.saveCurrentPosition;
1819+
cacheCurrentPosition = builder.cacheCurrentPosition;
18201820
}
18211821

18221822
/**
@@ -1831,9 +1831,9 @@ public StateBuilder edit() {
18311831
public class StateBuilder {
18321832
private CalendarMode calendarMode = CalendarMode.MONTHS;
18331833
private int firstDayOfWeek = Calendar.getInstance().getFirstDayOfWeek();
1834-
public CalendarDay minDate = null;
1835-
public CalendarDay maxDate = null;
1836-
public boolean saveCurrentPosition = false;
1834+
private boolean cacheCurrentPosition = false;
1835+
private CalendarDay minDate = null;
1836+
private CalendarDay maxDate = null;
18371837

18381838
public StateBuilder() {
18391839
}
@@ -1843,7 +1843,7 @@ private StateBuilder(final State state) {
18431843
firstDayOfWeek = state.firstDayOfWeek;
18441844
minDate = state.minDate;
18451845
maxDate = state.maxDate;
1846-
saveCurrentPosition = state.saveCurrentPosition;
1846+
cacheCurrentPosition = state.cacheCurrentPosition;
18471847
}
18481848

18491849
/**
@@ -1921,13 +1921,15 @@ public StateBuilder setMaximumDate(@Nullable CalendarDay calendar) {
19211921
}
19221922

19231923
/**
1924-
* Use this method to enable saving the current position when switching
1925-
* between week and month mode.
1924+
* Use this method to enable saving the current position when switching
1925+
* between week and month mode. By default, the calendar update to the latest selected date
1926+
* or the current date. When set to true, the view will used the month that the calendar is
1927+
* currently on.
19261928
*
1927-
* @param saveCurrentPosition Set to true to save the current position, false otherwise.
1929+
* @param cacheCurrentPosition Set to true to cache the current position, false otherwise.
19281930
*/
1929-
public StateBuilder setSaveCurrentPosition(final boolean saveCurrentPosition) {
1930-
this.saveCurrentPosition = saveCurrentPosition;
1931+
public StateBuilder isCacheCalendarPositionEnabled(final boolean cacheCurrentPosition) {
1932+
this.cacheCurrentPosition = cacheCurrentPosition;
19311933
return this;
19321934
}
19331935

@@ -1939,7 +1941,7 @@ public void commit() {
19391941
private void commit(State state) {
19401942
// Use the calendarDayToShow to determine which date to focus on for the case of switching between month and week views
19411943
CalendarDay calendarDayToShow = null;
1942-
if (adapter != null && state.saveCurrentPosition) {
1944+
if (adapter != null && state.cacheCurrentPosition) {
19431945
calendarDayToShow = adapter.getItem(pager.getCurrentItem());
19441946
if (calendarMode != state.calendarMode) {
19451947
CalendarDay currentlySelectedDate = getSelectedDate();

sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/DynamicSettersActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void onClick(DialogInterface dialog, int which, boolean isChecked) {
102102
@OnCheckedChanged(R.id.enable_save_current_position)
103103
void onSaveCurrentPositionChecked(boolean checked) {
104104
widget.state().edit()
105-
.setSaveCurrentPosition(checked)
105+
.isCacheCalendarPositionEnabled(checked)
106106
.commit();
107107
}
108108

0 commit comments

Comments
 (0)