Skip to content

Commit

Permalink
Remove deprecated properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
kizitonwose committed Nov 8, 2020
1 parent 7fc0947 commit 66263da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 162 deletions.
157 changes: 14 additions & 143 deletions library/src/main/java/com/kizitonwose/calendarview/CalendarView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.annotation.Px
import androidx.core.content.withStyledAttributes
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.kizitonwose.calendarview.CalendarView.Companion.DAY_SIZE_SQUARE
import com.kizitonwose.calendarview.model.*
import com.kizitonwose.calendarview.ui.*
import com.kizitonwose.calendarview.utils.Size
Expand Down Expand Up @@ -235,7 +234,7 @@ open class CalendarView : RecyclerView {
private var firstDayOfWeek: DayOfWeek? = null

private var autoSize = true
private var autoSizeHeight = DAY_SIZE_SQUARE
private var autoSizeHeight = SQUARE
private var sizedInternally = false

internal val isVertical: Boolean
Expand Down Expand Up @@ -291,7 +290,7 @@ open class CalendarView : RecyclerView {
// +0.5 => round to the nearest pixel
val size = (((widthSize - (monthPaddingStart + monthPaddingEnd)) / 7f) + 0.5).toInt()

val height = if (autoSizeHeight == DAY_SIZE_SQUARE) size else autoSizeHeight
val height = if (autoSizeHeight == SQUARE) size else autoSizeHeight
val computedSize = daySize.copy(width = size, height = height)
if (daySize != computedSize) {
sizedInternally = true
Expand All @@ -303,43 +302,6 @@ open class CalendarView : RecyclerView {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
}

/**
* The width, in pixels for each day cell view.
* Set this to [DAY_SIZE_SQUARE] to have a nice
* square item view.
*
* @see [DAY_SIZE_SQUARE]
*/
@Px
@Deprecated(
"The new `daySize` property clarifies how cell sizing should be done.",
replaceWith = ReplaceWith("daySize")
)
var dayWidth: Int = DAY_SIZE_SQUARE
get() = daySize.width
set(value) {
field = value
daySize = Size(field, dayHeight)
}

/**
* The height, in pixels for each day cell view.
* Set this to [DAY_SIZE_SQUARE] to have a nice
* square item view.
*
* @see [DAY_SIZE_SQUARE]
*/
@Px
@Deprecated(
"The new `daySize` property clarifies how cell sizing should be done.",
replaceWith = ReplaceWith("daySize")
)
var dayHeight: Int = DAY_SIZE_SQUARE
get() = daySize.height
set(value) {
field = value
daySize = Size(dayWidth, field)
}

/**
* The size in pixels for each day cell view.
Expand All @@ -352,7 +314,7 @@ open class CalendarView : RecyclerView {
set(value) {
field = value
if (!sizedInternally) {
autoSize = value == SIZE_SQUARE || value.width == DAY_SIZE_SQUARE
autoSize = value == SIZE_SQUARE || value.width == SQUARE
autoSizeHeight = value.height
invalidateViewHolders()
}
Expand All @@ -364,119 +326,63 @@ 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()
}
private set

/**
* The padding, in pixels to be applied
* to the end of each month view.
*/
@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()
}
private set

/**
* The padding, in pixels to be applied
* to the top of each month view.
*/
@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()
}
private set

/**
* The padding, in pixels to be applied
* to the bottom of each month view.
*/
@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()
}
private set

/**
* The margin, in pixels to be applied
* to the start of each month view.
*/
@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()
}
private set

/**
* The margin, in pixels to be applied
* to the end of each month view.
*/
@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()
}
private set

/**
* The margin, in pixels to be applied
* to the top of each month view.
*/
@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()
}
private set

/**
* The margin, in pixels to be applied
* to the bottom of each month view.
*/
@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()
}
private set

private val calendarLayoutManager: CalendarLayoutManager
get() = layoutManager as CalendarLayoutManager
Expand Down Expand Up @@ -585,12 +491,10 @@ open class CalendarView : RecyclerView {
@Px end: Int = monthPaddingEnd,
@Px bottom: Int = monthPaddingBottom
) {
internalConfigUpdate = true
monthPaddingStart = start
monthPaddingTop = top
monthPaddingEnd = end
monthPaddingBottom = bottom
internalConfigUpdate = false
invalidateViewHolders()
}

Expand All @@ -605,12 +509,10 @@ open class CalendarView : RecyclerView {
@Px end: Int = monthMarginEnd,
@Px bottom: Int = monthMarginBottom
) {
internalConfigUpdate = true
monthMarginStart = start
monthMarginTop = top
monthMarginEnd = end
monthMarginBottom = bottom
internalConfigUpdate = false
invalidateViewHolders()
}

Expand Down Expand Up @@ -829,28 +731,6 @@ open class CalendarView : RecyclerView {
)
}

/**
* Update the CalendarView's start month.
* This can be called only if you have called [setup] in the past.
* See [updateEndMonth] and [updateMonthRange].
*/
@Deprecated(
"This helper method will be removed to clean up the library's API.",
ReplaceWith("updateMonthRange()")
)
fun updateStartMonth(startMonth: YearMonth) = updateMonthRange(startMonth, requireEndMonth())

/**
* Update the CalendarView's end month.
* This can be called only if you have called [setup] in the past.
* See [updateStartMonth] and [updateMonthRange].
*/
@Deprecated(
"This helper method will be removed to clean up the library's API.",
ReplaceWith("updateMonthRange()")
)
fun updateEndMonth(endMonth: YearMonth) = updateMonthRange(requireStartMonth(), endMonth)

/**
* Update the CalendarView's start and end months.
* This can be called only if you have called [setup] or [setupAsync] in the past.
Expand Down Expand Up @@ -950,28 +830,19 @@ open class CalendarView : RecyclerView {
}

companion object {
/**
* A value for [dayWidth] and [dayHeight] which indicates that the day
* cells should have equal width and height. Each view's width and height
* will be the width of the calender divided by 7.
*/
@Deprecated(
"The new `daySize` property clarifies how cell sizing should be done.",
replaceWith = ReplaceWith("CalendarView.SIZE_SQUARE")
)
const val DAY_SIZE_SQUARE = Int.MIN_VALUE
private const val SQUARE = Int.MIN_VALUE

/**
* A value for [daySize] which indicates that the day cells should
* have equal width and height. Each view's width and height will
* be the width of the calender divided by 7.
*/
val SIZE_SQUARE = Size(DAY_SIZE_SQUARE, DAY_SIZE_SQUARE)
val SIZE_SQUARE = Size(SQUARE, SQUARE)

/**
* A value for [daySize] which indicates that the day cells should
* have width of the calender divided by 7 and provided height.
*/
fun sizeAutoWidth(@Px height: Int) = Size(DAY_SIZE_SQUARE, height)
fun sizeAutoWidth(@Px height: Int) = Size(SQUARE, height)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ internal class CalendarAdapter(
rootLayout.addView(monthHeaderView)
}

@Suppress("UNCHECKED_CAST") val dayConfig = DayConfig(
@Suppress("UNCHECKED_CAST")
val dayConfig = DayConfig(
calView.daySize, viewConfig.dayViewRes,
calView.dayBinder as DayBinder<ViewContainer>
)
Expand Down Expand Up @@ -212,11 +213,11 @@ internal class CalendarAdapter(
val visibleVH =
calView.findViewHolderForAdapterPosition(visibleItemPos) as? MonthViewHolder ?: return
val newHeight = visibleVH.headerView?.height.orZero() +
// visibleVH.bodyLayout.height` won't not give us the right height as it differs
// depending on row count in the month. So we calculate the appropriate height
// by checking the number of visible(non-empty) rows.
visibleMonth.weekDays.size * calView.daySize.height +
visibleVH.footerView?.height.orZero()
// visibleVH.bodyLayout.height` won't not give us the right height as it differs
// depending on row count in the month. So we calculate the appropriate height
// by checking the number of visible(non-empty) rows.
visibleMonth.weekDays.size * calView.daySize.height +
visibleVH.footerView?.height.orZero()
if (calView.height != newHeight) {
ValueAnimator.ofInt(calView.height, newHeight).apply {
// Don't animate when the view is shown initially.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,19 +346,6 @@ class CalenderViewTests {
sleep(3000)
}

@Test
fun deprecatedWidthAndHeightPropertiesWorkAsExpected() {
val calendarView = CalendarView(homeScreenRule.activity)
calendarView.dayWidth = 7
calendarView.dayHeight = 8
assertEquals(calendarView.daySize, Size(7, 8))

val calendarView2 = CalendarView(homeScreenRule.activity)
calendarView2.daySize = Size(10, 20)
assertEquals(calendarView2.dayWidth, calendarView2.daySize.width)
assertEquals(calendarView2.dayHeight, calendarView2.daySize.height)
}

private inline fun <reified T : Fragment> findFragment(): T {
return homeScreenRule.activity.supportFragmentManager
.findFragmentByTag(T::class.java.simpleName) as T
Expand Down

0 comments on commit 66263da

Please sign in to comment.