From 8b29681d7c02d58845b0afa380812656586879a8 Mon Sep 17 00:00:00 2001 From: Kizito Nwose Date: Sun, 26 Jul 2020 15:49:03 +0200 Subject: [PATCH] Update README --- README.md | 49 +++++++++++++------ .../kizitonwose/calendarview/CalendarView.kt | 12 ++--- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 8e0b5e54..1d6f12f2 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,8 @@ calendarView.dayBinder = object : DayBinder { #### Properties +All XML attributes are also available as properties of the CalendarView class via code. So in addition to those, we have: + - **monthScrollListener**: Called when the calendar scrolls to a new month. Mostly beneficial if `scrollMode` is `paged`. - **dayBinder**: An instance of `DayBinder` for managing day cell views. @@ -230,11 +232,9 @@ calendarView.dayBinder = object : DayBinder { - **monthFooterBinder**: An instance of `MonthHeaderFooterBinder` for managing footer views. -- **dayWidth**: The width, in pixels for each day cell view. - -- **dayHeight**: The height, in pixels for each day cell view. +- **daySize**: The size, in pixels for each day cell view. -Note that setting either `dayWidth` or `dayHeight` to `CalendarView.DAY_SIZE_SQUARE` makes the day cells have equal width and height which is basically the width of the calendar divided by 7. `DAY_SIZE_SQUARE` is the default day width and height value. +Note that setting the `daySize` property to `CalendarView.SIZE_SQUARE` makes the day cells have equal width and height which is basically the width of the calendar divided by 7. `SIZE_SQUARE` is the default size value. #### Methods @@ -248,28 +248,47 @@ Note that setting either `dayWidth` or `dayHeight` to `CalendarView.DAY_SIZE_SQU - **notifyCalendarChanged()**: Reload the entire calendar. -There's no need listing all available methods or repeating the documentation here. Please see the [CalendarView](https://github.com/kizitonwose/CalendarView/blob/master/library/src/main/java/com/kizitonwose/calendarview/CalendarView.kt) class for all properties and methods available with proper documentation. +- **findFirstVisibleMonth()** and **findLastVisibleMonth()**: Find the first and last visible months on the CalendarView respectively. + +- **findFirstVisibleDay()** and **findLastVisibleDay()**: Find the first and last visible days on the CalendarView respectively. + +- **setupAsync()**: Setup the CalendarView, *asynchronously*, useful if your `startMonth` and `endMonth` values are *many* years apart. + +- **updateMonthRange()**: Update the CalendarView's `startMonth` and/or `endMonth` values after the initial setup. The currently visible month is preserved. Use `updateMonthRangeAsync()` to do this asynchronously. + +- **updateMonthConfiguration()**: Update `inDateStyle`, `outDateStyle`, `maxRowCount` and `hasBoundaries` properties without generating the underlying calendar data repeatedly. Prefer this if setting more than one of these properties at the same time. Use `updateMonthConfigurationAsync()` to do this asynchronously. + + +There's no need to list all available methods or repeating the documentation here. Please see the [CalendarView](https://github.com/kizitonwose/CalendarView/blob/master/library/src/main/java/com/kizitonwose/calendarview/CalendarView.kt) class for all properties and methods available with proper documentation. ## Week view and Month view This library has no concept of week/month view. You'll need to configure the calendar to mimic this behavior by changing its state between a 6 or 1 row calendar, depending on your needs. This feature can be seen in Example 1 in the sample app. In summary, here's what you need: -```kotlin -// Common configurations for both modes. -calendarView.inDateStyle = InDateStyle.ALL_MONTHS -calendarView.outDateStyle = OutDateStyle.END_OF_ROW -calendarView.scrollMode = ScrollMode.PAGED -calendarView.orientation = RecyclerView.HORIZONTAL +```xml + +app:cv_orientation="horizontal" +app:cv_outDateStyle="endOfRow" +app:cv_inDateStyle="allMonths" +app:cv_scrollMode="paged" +``` +```kotlin val monthToWeek = monthViewCheckBox.isChecked if (monthToWeek) { // One row calendar for week mode - calendarView.maxRowCount = 1 - calendarView.hasBoundaries = false + calendarView.updateMonthConfiguration( + inDateStyle = InDateStyle.ALL_MONTHS, + maxRowCount = 1, + hasBoundaries = false + ) } else { // Six row calendar for month mode - calendarView.maxRowCount = 6 - calendarView.hasBoundaries = true + calendarView.updateMonthConfiguration( + inDateStyle = InDateStyle.FIRST_MONTH, + maxRowCount = 6, + hasBoundaries = true + ) } ``` diff --git a/library/src/main/java/com/kizitonwose/calendarview/CalendarView.kt b/library/src/main/java/com/kizitonwose/calendarview/CalendarView.kt index 0fbfff3b..dc1582db 100644 --- a/library/src/main/java/com/kizitonwose/calendarview/CalendarView.kt +++ b/library/src/main/java/com/kizitonwose/calendarview/CalendarView.kt @@ -146,7 +146,7 @@ open class CalendarView : RecyclerView { * If set to [InDateStyle.NONE], inDates will not be generated, this means there will * be no offset on any month. * - * Note: This causes month data to be regenerated, consider using [updateMonthConfiguration] + * Note: This causes calendar data to be regenerated, consider using [updateMonthConfiguration] * if updating this property alongside [outDateStyle], [maxRowCount] or [hasBoundaries]. */ var inDateStyle = InDateStyle.ALL_MONTHS @@ -166,7 +166,7 @@ open class CalendarView : RecyclerView { * it reaches the end of a 6 x 7 grid. This means that all months will have 6 rows. * If set to [OutDateStyle.NONE], no outDates will be generated. * - * Note: This causes month data to be regenerated, consider using [updateMonthConfiguration] + * Note: This causes calendar data to be regenerated, consider using [updateMonthConfiguration] * if updating this value property [inDateStyle], [maxRowCount] or [hasBoundaries]. */ var outDateStyle = OutDateStyle.END_OF_ROW @@ -183,7 +183,7 @@ open class CalendarView : RecyclerView { * calendar the first one will show 4 rows and the second one will show the remaining 2 rows. * To show a week mode calendar, set this value to 1. * - * Note: This causes month data to be regenerated, consider using [updateMonthConfiguration] + * Note: This causes calendar data to be regenerated, consider using [updateMonthConfiguration] * if updating this property alongside [inDateStyle], [outDateStyle] or [hasBoundaries]. */ var maxRowCount = 6 @@ -208,7 +208,7 @@ open class CalendarView : RecyclerView { * - If [OutDateStyle] is [OutDateStyle.END_OF_GRID], outDates are generated for the last index until it * satisfies the [maxRowCount] requirement. * - * Note: This causes month data to be regenerated, consider using [updateMonthConfiguration] + * Note: This causes calendar data to be regenerated, consider using [updateMonthConfiguration] * if updating this property alongside [inDateStyle], [outDateStyle] or [maxRowCount]. */ var hasBoundaries = true @@ -520,7 +520,7 @@ open class CalendarView : RecyclerView { /** * Update [inDateStyle], [outDateStyle], [maxRowCount] and [hasBoundaries] - * without generating the underlying month data multiple times. + * without generating the underlying calendar data multiple times. * See [updateMonthConfigurationAsync] if you wish to do this asynchronously. */ fun updateMonthConfiguration( @@ -541,7 +541,7 @@ open class CalendarView : RecyclerView { /** * Update [inDateStyle], [outDateStyle], [maxRowCount] and [hasBoundaries] - * asynchronously without generating the underlying month data multiple times. + * asynchronously without generating the underlying calendar data multiple times. * Useful if your [startMonth] and [endMonth] values are many years apart. * See [updateMonthConfiguration] if you wish to do this synchronously. */