From 712a55286eae11f8a690598c6d7c7ba8203c79dc Mon Sep 17 00:00:00 2001 From: Juniper Berry <6226784+themangosteen@users.noreply.github.com> Date: Sun, 7 Jan 2024 17:42:58 +0100 Subject: [PATCH 1/6] MonthDayView draw dot for each event instead of just one dot. --- .../org/fossify/calendar/views/MonthView.kt | 43 ++++++++++++++++--- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt b/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt index ccdfca28c..b0c82aa08 100644 --- a/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt +++ b/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt @@ -32,6 +32,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con private var eventTitlePaint: TextPaint private var gridPaint: Paint private var circleStrokePaint: Paint + private var plusSymbolTextPaint: Paint private var config = context.config private var dayWidth = 0f private var dayHeight = 0f @@ -79,6 +80,13 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con textAlign = Paint.Align.CENTER } + plusSymbolTextPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { + color = textColor + alpha = 175 + textSize = normalTextSize.toFloat() + textAlign = Paint.Align.CENTER + } + gridPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = textColor.adjustAlpha(LOWER_ALPHA) } @@ -190,16 +198,37 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con canvas.drawCircle(xPosCenter, yPos + textPaint.textSize * 0.7f, textPaint.textSize * 0.8f, getCirclePaint(day)) } - // mark days with events with a dot + // mark days with a dot for each event if (isMonthDayView && day.dayEvents.isNotEmpty()) { getCirclePaint(day).getTextBounds(dayNumber, 0, dayNumber.length, dayTextRect) val height = dayTextRect.height() * 1.25f - canvas.drawCircle( - xPosCenter, - yPos + height + textPaint.textSize / 2, - textPaint.textSize * 0.2f, - getDayEventColor(day.dayEvents.first()) - ) + val eventCount = day.dayEvents.count() + val radiusDot = textPaint.textSize * 0.2f + val stepSize = radiusDot * 2.5f + val dotsPerRow = 4 + var xDot = xPosCenter + var yDot = yPos + height + textPaint.textSize / 2 + val dayEventsSorted = day.dayEvents.asSequence().sortedWith( + compareBy({ it.startTS }, { it.endTS }, { it.title }) + ).toMutableList() as ArrayList + var indexInRow = 0 + for ((index, event) in dayEventsSorted.withIndex()) { + indexInRow = index % dotsPerRow + xDot = xPosCenter + stepSize * (indexInRow - (min(eventCount, dotsPerRow)) / 2) + if (eventCount % 2 == 0) { // center even number of dots + xDot += stepSize / 2 + } + if (index > 0 && indexInRow == 0) { // next row of dots + yDot += stepSize + } + if (index >= dotsPerRow * 2 - 1) { // draw + if too many events + plusSymbolTextPaint.textSize = stepSize * 1.5f + canvas.drawText("+", xDot, yDot + radiusDot * 1.2f, plusSymbolTextPaint) + break + } else { + canvas.drawCircle(xDot, yDot, radiusDot, getDayEventColor(event)) + } + } } canvas.drawText(dayNumber, xPosCenter, yPos + textPaint.textSize, textPaint) From dd76be63d09b81b2a95ce4faf68160c68df026d1 Mon Sep 17 00:00:00 2001 From: Naveen Date: Mon, 11 Mar 2024 21:44:33 +0530 Subject: [PATCH 2/6] Update event dot row and column count --- .../org/fossify/calendar/views/MonthView.kt | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt b/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt index b0c82aa08..41dee26a1 100644 --- a/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt +++ b/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt @@ -26,7 +26,11 @@ import kotlin.math.min // used in the Monthly view fragment, 1 view per screen class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) { - private val BG_CORNER_RADIUS = 8f + companion object { + private const val BG_CORNER_RADIUS = 8f + private const val EVENT_DOT_COLUMN_COUNT = 3 + private const val EVENT_DOT_ROW_COUNT = 1 + } private var textPaint: Paint private var eventTitlePaint: TextPaint @@ -203,30 +207,37 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con getCirclePaint(day).getTextBounds(dayNumber, 0, dayNumber.length, dayTextRect) val height = dayTextRect.height() * 1.25f val eventCount = day.dayEvents.count() - val radiusDot = textPaint.textSize * 0.2f - val stepSize = radiusDot * 2.5f - val dotsPerRow = 4 - var xDot = xPosCenter + val dotRadius = textPaint.textSize * 0.2f + val stepSize = dotRadius * 2.5f + val columnCount = EVENT_DOT_COLUMN_COUNT + + val dayEventsSorted = day.dayEvents + .asSequence() + .sortedWith( + comparator = compareBy({ it.startTS }, { it.endTS }, { it.title }) + ) + + var xDot: Float var yDot = yPos + height + textPaint.textSize / 2 - val dayEventsSorted = day.dayEvents.asSequence().sortedWith( - compareBy({ it.startTS }, { it.endTS }, { it.title }) - ).toMutableList() as ArrayList - var indexInRow = 0 + var indexInRow: Int for ((index, event) in dayEventsSorted.withIndex()) { - indexInRow = index % dotsPerRow - xDot = xPosCenter + stepSize * (indexInRow - (min(eventCount, dotsPerRow)) / 2) + indexInRow = index % columnCount + xDot = xPosCenter + stepSize * (indexInRow - (min(eventCount, columnCount)) / 2) + if (eventCount % 2 == 0) { // center even number of dots xDot += stepSize / 2 } + if (index > 0 && indexInRow == 0) { // next row of dots yDot += stepSize } - if (index >= dotsPerRow * 2 - 1) { // draw + if too many events + + if (index >= columnCount * EVENT_DOT_ROW_COUNT - 1) { // draw + if too many events plusSymbolTextPaint.textSize = stepSize * 1.5f - canvas.drawText("+", xDot, yDot + radiusDot * 1.2f, plusSymbolTextPaint) + canvas.drawText("+", xDot, yDot + dotRadius * 1.2f, plusSymbolTextPaint) break } else { - canvas.drawCircle(xDot, yDot, radiusDot, getDayEventColor(event)) + canvas.drawCircle(xDot, yDot, dotRadius, getDayEventColor(event)) } } } From ee9e9912d68facda56d1076cd744f7c19440b824 Mon Sep 17 00:00:00 2001 From: Naveen Date: Mon, 11 Mar 2024 21:59:08 +0530 Subject: [PATCH 3/6] Only draw dots with unique event colors --- app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt b/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt index 41dee26a1..5b453bc93 100644 --- a/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt +++ b/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt @@ -216,6 +216,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con .sortedWith( comparator = compareBy({ it.startTS }, { it.endTS }, { it.title }) ) + .distinctBy { it.color } var xDot: Float var yDot = yPos + height + textPaint.textSize / 2 @@ -232,7 +233,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con yDot += stepSize } - if (index >= columnCount * EVENT_DOT_ROW_COUNT - 1) { // draw + if too many events + if (eventCount - 1 != index && index >= columnCount * EVENT_DOT_ROW_COUNT - 1) { // draw + if too many events plusSymbolTextPaint.textSize = stepSize * 1.5f canvas.drawText("+", xDot, yDot + dotRadius * 1.2f, plusSymbolTextPaint) break From 32cdc34db7fe76dc121d38810540117de91c4ce5 Mon Sep 17 00:00:00 2001 From: Naveen Date: Mon, 11 Mar 2024 22:07:06 +0530 Subject: [PATCH 4/6] Disable event dots on highlighted dates --- .../main/kotlin/org/fossify/calendar/views/MonthView.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt b/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt index 5b453bc93..15bbec85c 100644 --- a/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt +++ b/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt @@ -193,7 +193,8 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con val dayNumber = day.value.toString() val textPaint = getTextPaint(day) - if (selectedDayCoords.x != -1 && x == selectedDayCoords.x && y == selectedDayCoords.y) { + val isDaySelected = selectedDayCoords.x != -1 && x == selectedDayCoords.x && y == selectedDayCoords.y + if (isDaySelected) { canvas.drawCircle(xPosCenter, yPos + textPaint.textSize * 0.7f, textPaint.textSize * 0.8f, circleStrokePaint) if (day.isToday) { textPaint.color = textColor @@ -203,10 +204,10 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con } // mark days with a dot for each event - if (isMonthDayView && day.dayEvents.isNotEmpty()) { + if (isMonthDayView && !isDaySelected && !day.isToday && day.dayEvents.isNotEmpty()) { getCirclePaint(day).getTextBounds(dayNumber, 0, dayNumber.length, dayTextRect) val height = dayTextRect.height() * 1.25f - val eventCount = day.dayEvents.count() + val eventCount = day.dayEvents.size val dotRadius = textPaint.textSize * 0.2f val stepSize = dotRadius * 2.5f val columnCount = EVENT_DOT_COLUMN_COUNT From b3a9bc61d30ab8d3e18403368199fe63843aef7b Mon Sep 17 00:00:00 2001 From: Naveen Date: Mon, 11 Mar 2024 22:15:54 +0530 Subject: [PATCH 5/6] Reuse paint object --- .../org/fossify/calendar/views/MonthView.kt | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt b/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt index 15bbec85c..abe3ac477 100644 --- a/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt +++ b/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt @@ -36,7 +36,8 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con private var eventTitlePaint: TextPaint private var gridPaint: Paint private var circleStrokePaint: Paint - private var plusSymbolTextPaint: Paint + private var plusTextPaint: Paint + private var eventDotPaint: Paint private var config = context.config private var dayWidth = 0f private var dayHeight = 0f @@ -84,7 +85,8 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con textAlign = Paint.Align.CENTER } - plusSymbolTextPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { + eventDotPaint = Paint(Paint.ANTI_ALIAS_FLAG) + plusTextPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = textColor alpha = 175 textSize = normalTextSize.toFloat() @@ -235,11 +237,12 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con } if (eventCount - 1 != index && index >= columnCount * EVENT_DOT_ROW_COUNT - 1) { // draw + if too many events - plusSymbolTextPaint.textSize = stepSize * 1.5f - canvas.drawText("+", xDot, yDot + dotRadius * 1.2f, plusSymbolTextPaint) + plusTextPaint.textSize = stepSize * 1.5f + canvas.drawText("+", xDot, yDot + dotRadius * 1.2f, plusTextPaint) break } else { - canvas.drawCircle(xDot, yDot, dotRadius, getDayEventColor(event)) + val paint = eventDotPaint.apply { color = event.color } + canvas.drawCircle(xDot, yDot, dotRadius, paint) } } } @@ -437,12 +440,6 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con return curPaint } - private fun getDayEventColor(event: Event): Paint { - val curPaint = Paint(Paint.ANTI_ALIAS_FLAG) - curPaint.color = event.color - return curPaint - } - private fun initWeekDayLetters() { dayLetters = context.withFirstDayOfWeekToFront(context.resources.getStringArray(org.fossify.commons.R.array.week_day_letters).toList()) } From bd8c7f6539ca987431b8ba9d211fb05161d07161 Mon Sep 17 00:00:00 2001 From: Naveen Date: Mon, 11 Mar 2024 22:41:34 +0530 Subject: [PATCH 6/6] Remove unecessary line --- app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt b/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt index abe3ac477..885255567 100644 --- a/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt +++ b/app/src/main/kotlin/org/fossify/calendar/views/MonthView.kt @@ -227,7 +227,6 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con for ((index, event) in dayEventsSorted.withIndex()) { indexInRow = index % columnCount xDot = xPosCenter + stepSize * (indexInRow - (min(eventCount, columnCount)) / 2) - if (eventCount % 2 == 0) { // center even number of dots xDot += stepSize / 2 }