Skip to content

Commit

Permalink
Set fixed height by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
kizitonwose committed Jun 11, 2020
1 parent 6be23be commit 1785628
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ open class CalendarView : RecyclerView {

private fun init(attributeSet: AttributeSet, defStyleAttr: Int, defStyleRes: Int) {
if (isInEditMode) return
setHasFixedSize(true)
val a = context.obtainStyledAttributes(attributeSet, R.styleable.CalendarView, defStyleAttr, defStyleRes)
dayViewResource = a.getResourceId(R.styleable.CalendarView_cv_dayViewResource, dayViewResource)
monthHeaderResource = a.getResourceId(R.styleable.CalendarView_cv_monthHeaderResource, monthHeaderResource)
Expand All @@ -251,7 +252,7 @@ open class CalendarView : RecyclerView {
}

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
if (autoSize && isInEditMode.not()) {
if (autoSize && !isInEditMode) {
val widthMode = MeasureSpec.getMode(widthMeasureSpec)
val widthSize = MeasureSpec.getSize(widthMeasureSpec)
val heightMode = MeasureSpec.getMode(heightMeasureSpec)
Expand Down Expand Up @@ -284,7 +285,7 @@ open class CalendarView : RecyclerView {
var dayWidth: Int = DAY_SIZE_SQUARE
set(value) {
field = value
if (sizedInternally.not()) {
if (!sizedInternally) {
autoSize = value == DAY_SIZE_SQUARE
invalidateViewHolders()
}
Expand All @@ -301,7 +302,7 @@ open class CalendarView : RecyclerView {
var dayHeight: Int = DAY_SIZE_SQUARE
set(value) {
field = value
if (sizedInternally.not()) {
if (!sizedInternally) {
autoSize = value == DAY_SIZE_SQUARE
invalidateViewHolders()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal class DayHolder(private val config: DayConfig) {

fun bindDayView(currentDay: CalendarDay?) {
this.day = currentDay
if (::viewContainer.isInitialized.not()) {
if (!::viewContainer.isInitialized) {
viewContainer = config.viewBinder.create(dateView)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,4 @@ internal class WeekHolder(dayConfig: DayConfig) {
holder.bindDayView(daysOfWeek.getOrNull(index))
}
}

fun reloadDay(day: CalendarDay) {
dayHolders.first { it.day == day }.reloadView()
}
}

0 comments on commit 1785628

Please sign in to comment.