Skip to content

Commit

Permalink
Merge pull request #154 from jonas-w/fix/google_pixel_bug
Browse files Browse the repository at this point in the history
Fix google pixel month view
  • Loading branch information
naveensingh authored Mar 10, 2024
2 parents f6da127 + 9a0b350 commit f70268b
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions app/src/main/kotlin/org/fossify/calendar/views/MonthViewWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MonthViewWrapper(context: Context, attrs: AttributeSet, defStyle: Int) : F

child.layout(childLeft.toInt(), childTop.toInt(), childRight.toInt(), childBottom.toInt())

if (curLeft + childWidth < end) {
if (curLeft + childWidth <= end) {
curLeft += childWidth
x++
} else {
Expand Down Expand Up @@ -107,41 +107,29 @@ class MonthViewWrapper(context: Context, attrs: AttributeSet, defStyle: Int) : F
}

private fun measureSizes() {
dayWidth = (width - horizontalOffset) / 7f
dayHeight = (height - weekDaysLetterHeight) / 6f
dayWidth = (width - horizontalOffset) / COLUMN_COUNT.toFloat()
dayHeight = (height - weekDaysLetterHeight) / ROW_COUNT.toFloat()
}

private fun addClickableBackgrounds() {
removeAllViews()
binding = MonthViewBinding.inflate(inflater, this, true)
wereViewsAdded = true
var curId = 0
for (y in 0 until ROW_COUNT) {
for (x in 0 until COLUMN_COUNT) {
val day = days.getOrNull(curId)
if (day != null) {
addViewBackground(x, y, day)
}
curId++
}
days.forEachIndexed { index, day ->
addViewBackground(index % COLUMN_COUNT, index / COLUMN_COUNT, day)
}

}

private fun addViewBackground(viewX: Int, viewY: Int, day: DayMonthly) {
val xPos = viewX * dayWidth + horizontalOffset
val yPos = viewY * dayHeight + weekDaysLetterHeight

MonthViewBackgroundBinding.inflate(inflater, this, false).root.apply {
if (isMonthDayView) {
background = null
}
//Accessible label composed by day and month
contentDescription = "${day.value} ${Formatter.getMonthName(context, Formatter.getDateTimeFromCode(day.code).monthOfYear)}"
contentDescription = "${day.value} ${Formatter.getMonthName(context, Formatter.getDateTimeFromCode(day.code).monthOfYear)}"

layoutParams.width = dayWidth.toInt()
layoutParams.height = dayHeight.toInt()
x = xPos
y = yPos
setOnClickListener {
dayClickCallback?.invoke(day)

Expand Down

0 comments on commit f70268b

Please sign in to comment.