Skip to content

Commit

Permalink
Clean up code.
Browse files Browse the repository at this point in the history
  • Loading branch information
kizitonwose committed Jul 26, 2020
1 parent 4cd3cdb commit bf58e14
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
56 changes: 41 additions & 15 deletions library/src/main/java/com/kizitonwose/calendarview/CalendarView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ open class CalendarView : RecyclerView {
*/
@Px
@Deprecated(
"Will be removed to clean up the library's API.",
"The new `daySize` property clarifies how cell sizing should be done.",
replaceWith = ReplaceWith("daySize")
)
var dayWidth: Int = DAY_SIZE_SQUARE
Expand All @@ -327,7 +327,7 @@ open class CalendarView : RecyclerView {
*/
@Px
@Deprecated(
"Will be removed to clean up the library's API.",
"The new `daySize` property clarifies how cell sizing should be done.",
replaceWith = ReplaceWith("daySize")
)
var dayHeight: Int = DAY_SIZE_SQUARE
Expand Down Expand Up @@ -358,6 +358,10 @@ open class CalendarView : RecyclerView {
*/
@Px
var monthPaddingStart = 0
@Deprecated(
"Directly setting this along with related properties causes repeated invalidation of view holders.",
replaceWith = ReplaceWith("setMonthPadding")
)
set(value) {
field = value
invalidateViewHolders()
Expand All @@ -369,6 +373,10 @@ open class CalendarView : RecyclerView {
*/
@Px
var monthPaddingEnd = 0
@Deprecated(
"Directly setting this along with related properties causes repeated invalidation of view holders.",
replaceWith = ReplaceWith("setMonthPadding")
)
set(value) {
field = value
invalidateViewHolders()
Expand All @@ -380,6 +388,10 @@ open class CalendarView : RecyclerView {
*/
@Px
var monthPaddingTop = 0
@Deprecated(
"Directly setting this along with related properties causes repeated invalidation of view holders.",
replaceWith = ReplaceWith("setMonthPadding")
)
set(value) {
field = value
invalidateViewHolders()
Expand All @@ -391,6 +403,10 @@ open class CalendarView : RecyclerView {
*/
@Px
var monthPaddingBottom = 0
@Deprecated(
"Directly setting this along with related properties causes repeated invalidation of view holders.",
replaceWith = ReplaceWith("setMonthPadding")
)
set(value) {
field = value
invalidateViewHolders()
Expand All @@ -402,6 +418,10 @@ open class CalendarView : RecyclerView {
*/
@Px
var monthMarginStart = 0
@Deprecated(
"Directly setting this along with related properties causes repeated invalidation of view holders.",
replaceWith = ReplaceWith("setMonthMargins")
)
set(value) {
field = value
invalidateViewHolders()
Expand All @@ -413,6 +433,10 @@ open class CalendarView : RecyclerView {
*/
@Px
var monthMarginEnd = 0
@Deprecated(
"Directly setting this along with related properties causes repeated invalidation of view holders.",
replaceWith = ReplaceWith("setMonthMargins")
)
set(value) {
field = value
invalidateViewHolders()
Expand All @@ -424,6 +448,10 @@ open class CalendarView : RecyclerView {
*/
@Px
var monthMarginTop = 0
@Deprecated(
"Directly setting this along with related properties causes repeated invalidation of view holders.",
replaceWith = ReplaceWith("setMonthMargins")
)
set(value) {
field = value
invalidateViewHolders()
Expand All @@ -435,6 +463,10 @@ open class CalendarView : RecyclerView {
*/
@Px
var monthMarginBottom = 0
@Deprecated(
"Directly setting this along with related properties causes repeated invalidation of view holders.",
replaceWith = ReplaceWith("setMonthMargins")
)
set(value) {
field = value
invalidateViewHolders()
Expand Down Expand Up @@ -794,9 +826,8 @@ open class CalendarView : RecyclerView {
* See [updateEndMonth] and [updateMonthRange].
*/
@Deprecated(
"Will be removed to clean up the library's API.",
ReplaceWith("updateMonthRange()"),
DeprecationLevel.ERROR
"This helper method will be removed to clean up the library's API.",
ReplaceWith("updateMonthRange()")
)
fun updateStartMonth(startMonth: YearMonth) = updateMonthRange(startMonth, requireEndMonth())

Expand All @@ -806,9 +837,8 @@ open class CalendarView : RecyclerView {
* See [updateStartMonth] and [updateMonthRange].
*/
@Deprecated(
"This will be removed in the future to clean up the library's API.",
ReplaceWith("updateMonthRange()"),
DeprecationLevel.ERROR
"This helper method will be removed to clean up the library's API.",
ReplaceWith("updateMonthRange()")
)
fun updateEndMonth(endMonth: YearMonth) = updateMonthRange(requireStartMonth(), endMonth)

Expand Down Expand Up @@ -898,15 +928,15 @@ open class CalendarView : RecyclerView {
)
}

fun requireStartMonth(): YearMonth {
private fun requireStartMonth(): YearMonth {
return startMonth ?: throw IllegalStateException("`startMonth` is not set. Have you called `setup()`?")
}

fun requireEndMonth(): YearMonth {
private fun requireEndMonth(): YearMonth {
return endMonth ?: throw IllegalStateException("`endMonth` is not set. Have you called `setup()`?")
}

fun requireFirstDayOfWeek(): DayOfWeek {
private fun requireFirstDayOfWeek(): DayOfWeek {
return firstDayOfWeek ?: throw IllegalStateException("`firstDayOfWeek` is not set. Have you called `setup()`?")
}

Expand All @@ -916,10 +946,6 @@ open class CalendarView : RecyclerView {
* cells should have equal width and height. Each view's width and height
* will be the width of the calender divided by 7.
*/
@Deprecated(
"Will be removed to clean up the library's API.",
replaceWith = ReplaceWith("CalendarView.SIZE_SQUARE")
)
const val DAY_SIZE_SQUARE = Int.MIN_VALUE

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ class Example6Fragment : BaseFragment(R.layout.example_6_fragment), HasBackButto
// Add margins around our card view.
val horizontalMargin = dpToPx(8, requireContext())
val verticalMargin = dpToPx(14, requireContext())
monthMarginStart = horizontalMargin
monthMarginEnd = horizontalMargin
monthMarginTop = verticalMargin
monthMarginBottom = verticalMargin
setMonthMargins(start = horizontalMargin, end = horizontalMargin, top = verticalMargin, bottom = verticalMargin)
}

class DayViewContainer(view: View) : ViewContainer(view) {
Expand Down

0 comments on commit bf58e14

Please sign in to comment.