Skip to content

Commit

Permalink
Allow to opt out of restoring number of days
Browse files Browse the repository at this point in the history
  • Loading branch information
thellmund committed May 17, 2019
1 parent a5d2042 commit f375a2b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion library/src/main/java/com/alamkanak/weekview/WeekView.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ protected Parcelable onSaveInstanceState() {
protected void onRestoreInstanceState(Parcelable state) {
SavedState savedState = (SavedState) state;
super.onRestoreInstanceState(savedState.getSuperState());
configWrapper.setNumberOfVisibleDays(savedState.numberOfVisibleDays);

if (configWrapper.getRestoreNumberOfVisibleDays()) {
configWrapper.setNumberOfVisibleDays(savedState.numberOfVisibleDays);
}

Calendar firstVisibleDay = toCalendar(savedState.firstVisibleDate);
goToDate(firstVisibleDay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal class WeekViewConfig(context: Context, attrs: AttributeSet) {
// Calendar configuration
var firstDayOfWeek: Int = 0
var numberOfVisibleDays: Int = 0
var restoreNumberOfVisibleDays: Boolean = true
var showFirstDayOfWeekFirst: Boolean = false
var showCurrentTimeFirst: Boolean = false

Expand Down Expand Up @@ -108,6 +109,7 @@ internal class WeekViewConfig(context: Context, attrs: AttributeSet) {
// Calendar configuration
firstDayOfWeek = a.getInteger(R.styleable.WeekView_firstDayOfWeek, DayOfWeek.MONDAY.value)
numberOfVisibleDays = a.getInteger(R.styleable.WeekView_numberOfVisibleDays, 3)
restoreNumberOfVisibleDays = a.getBoolean(R.styleable.WeekView_restoreNumberOfVisibleDays, true)
showFirstDayOfWeekFirst = a.getBoolean(R.styleable.WeekView_showFirstDayOfWeekFirst, false)
showCurrentTimeFirst = a.getBoolean(R.styleable.WeekView_showCurrentTimeFirst, false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ internal class WeekViewConfigWrapper(
config.numberOfVisibleDays = value
}

val restoreNumberOfVisibleDays: Boolean
get() = config.restoreNumberOfVisibleDays

var hourHeight: Float
get() = config.hourHeight
set(value) {
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<enum name="sunday" value="7" />
</attr>
<attr name="numberOfVisibleDays" format="integer" />
<attr name="restoreNumberOfVisibleDays" format="boolean" />
<attr name="showFirstDayOfWeekFirst" format="boolean" />
<attr name="showCurrentTimeFirst" format="boolean" />

Expand Down

0 comments on commit f375a2b

Please sign in to comment.