mark the currently selected day with a circle stroke
This commit is contained in:
parent
3dc2bf7979
commit
5a015b2100
|
@ -3,6 +3,8 @@ package com.simplemobiletools.calendar.pro.helpers
|
|||
const val LOW_ALPHA = .3f
|
||||
const val MEDIUM_ALPHA = .6f
|
||||
const val STORED_LOCALLY_ONLY = 0
|
||||
const val ROW_COUNT = 6
|
||||
const val COLUMN_COUNT = 7
|
||||
|
||||
const val DAY_CODE = "day_code"
|
||||
const val YEAR_LABEL = "year"
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.simplemobiletools.calendar.pro.views
|
|||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Point
|
||||
import android.graphics.RectF
|
||||
import android.text.TextPaint
|
||||
import android.text.TextUtils
|
||||
|
@ -12,10 +13,7 @@ import android.view.View
|
|||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.seconds
|
||||
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
||||
import com.simplemobiletools.calendar.pro.helpers.LOW_ALPHA
|
||||
import com.simplemobiletools.calendar.pro.helpers.MEDIUM_ALPHA
|
||||
import com.simplemobiletools.calendar.pro.helpers.isWeekend
|
||||
import com.simplemobiletools.calendar.pro.helpers.*
|
||||
import com.simplemobiletools.calendar.pro.models.DayMonthly
|
||||
import com.simplemobiletools.calendar.pro.models.Event
|
||||
import com.simplemobiletools.calendar.pro.models.MonthViewEvent
|
||||
|
@ -29,11 +27,11 @@ import org.joda.time.Days
|
|||
// 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
|
||||
private val ROW_COUNT = 6
|
||||
|
||||
private var textPaint: Paint
|
||||
private var eventTitlePaint: TextPaint
|
||||
private var gridPaint: Paint
|
||||
private var circleStrokePaint: Paint
|
||||
private var config = context.config
|
||||
private var dayWidth = 0f
|
||||
private var dayHeight = 0f
|
||||
|
@ -56,6 +54,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
private var dayLetters = ArrayList<String>()
|
||||
private var days = ArrayList<DayMonthly>()
|
||||
private var dayVerticalOffsets = SparseIntArray()
|
||||
private var selectedDayCoords = Point(-1, -1)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
|
||||
|
||||
|
@ -81,6 +80,12 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
color = textColor.adjustAlpha(LOW_ALPHA)
|
||||
}
|
||||
|
||||
circleStrokePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
style = Paint.Style.STROKE
|
||||
strokeWidth = resources.getDimension(R.dimen.circle_stroke_width)
|
||||
color = primaryColor
|
||||
}
|
||||
|
||||
val smallerTextSize = resources.getDimensionPixelSize(R.dimen.smaller_text_size)
|
||||
eventTitleHeight = smallerTextSize
|
||||
eventTitlePaint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
|
@ -142,7 +147,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
|
||||
var curId = 0
|
||||
for (y in 0 until ROW_COUNT) {
|
||||
for (x in 0..6) {
|
||||
for (x in 0 until COLUMN_COUNT) {
|
||||
val day = days.getOrNull(curId)
|
||||
if (day != null) {
|
||||
dayVerticalOffsets.put(day.indexOnMonthView, dayVerticalOffsets[day.indexOnMonthView] + weekDaysLetterHeight)
|
||||
|
@ -150,7 +155,10 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
val xPos = x * dayWidth + horizontalOffset
|
||||
val yPos = y * dayHeight + verticalOffset
|
||||
val xPosCenter = xPos + dayWidth / 2
|
||||
if (day.isToday && !isPrintVersion) {
|
||||
|
||||
if (selectedDayCoords.x != -1 && x == selectedDayCoords.x && y == selectedDayCoords.y) {
|
||||
canvas.drawCircle(xPosCenter, yPos + textPaint.textSize * 0.7f, textPaint.textSize * 0.8f, circleStrokePaint)
|
||||
} else if (day.isToday && !isPrintVersion) {
|
||||
canvas.drawCircle(xPosCenter, yPos + textPaint.textSize * 0.7f, textPaint.textSize * 0.75f, getCirclePaint(day))
|
||||
}
|
||||
|
||||
|
@ -170,7 +178,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
|
||||
private fun drawGrid(canvas: Canvas) {
|
||||
// vertical lines
|
||||
for (i in 0..6) {
|
||||
for (i in 0 until COLUMN_COUNT) {
|
||||
var lineX = i * dayWidth
|
||||
if (showWeekNumbers) {
|
||||
lineX += horizontalOffset
|
||||
|
@ -180,13 +188,13 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
|
||||
// horizontal lines
|
||||
canvas.drawLine(0f, 0f, canvas.width.toFloat(), 0f, gridPaint)
|
||||
for (i in 0..5) {
|
||||
for (i in 0 until ROW_COUNT) {
|
||||
canvas.drawLine(0f, i * dayHeight + weekDaysLetterHeight, canvas.width.toFloat(), i * dayHeight + weekDaysLetterHeight, gridPaint)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addWeekDayLetters(canvas: Canvas) {
|
||||
for (i in 0..6) {
|
||||
for (i in 0 until COLUMN_COUNT) {
|
||||
val xPos = horizontalOffset + (i + 1) * dayWidth - dayWidth / 2
|
||||
var weekDayLetterPaint = textPaint
|
||||
if (i == currDayOfWeek && !isPrintVersion) {
|
||||
|
@ -373,4 +381,9 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
invalidate()
|
||||
initWeekDayLetters()
|
||||
}
|
||||
|
||||
fun updateCurrentlySelectedDay(x: Int, y: Int) {
|
||||
selectedDayCoords = Point(x, y)
|
||||
invalidate()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import android.view.LayoutInflater
|
|||
import android.widget.FrameLayout
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.helpers.COLUMN_COUNT
|
||||
import com.simplemobiletools.calendar.pro.helpers.ROW_COUNT
|
||||
import com.simplemobiletools.calendar.pro.models.DayMonthly
|
||||
import com.simplemobiletools.commons.extensions.onGlobalLayout
|
||||
import kotlinx.android.synthetic.main.month_view.view.*
|
||||
|
@ -74,20 +76,21 @@ class MonthViewWrapper(context: Context, attrs: AttributeSet, defStyle: Int) : F
|
|||
monthView = inflater.inflate(R.layout.month_view, this).month_view
|
||||
wereViewsAdded = true
|
||||
var curId = 0
|
||||
for (y in 0..5) {
|
||||
for (x in 0..6) {
|
||||
for (y in 0 until ROW_COUNT) {
|
||||
for (x in 0 until COLUMN_COUNT) {
|
||||
val day = days.getOrNull(curId)
|
||||
if (day != null) {
|
||||
val xPos = x * dayWidth + horizontalOffset
|
||||
val yPos = y * dayHeight + weekDaysLetterHeight
|
||||
addViewBackground(xPos, yPos, day)
|
||||
addViewBackground(x, y, day)
|
||||
}
|
||||
curId++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addViewBackground(xPos: Float, yPos: Float, day: DayMonthly) {
|
||||
private fun addViewBackground(viewX: Int, viewY: Int, day: DayMonthly) {
|
||||
val xPos = viewX * dayWidth + horizontalOffset
|
||||
val yPos = viewY * dayHeight + weekDaysLetterHeight
|
||||
|
||||
inflater.inflate(R.layout.month_view_background, this, false).apply {
|
||||
if (isMonthDayView) {
|
||||
background = null
|
||||
|
@ -99,6 +102,7 @@ class MonthViewWrapper(context: Context, attrs: AttributeSet, defStyle: Int) : F
|
|||
y = yPos
|
||||
setOnClickListener {
|
||||
dayClickCallback?.invoke(day)
|
||||
monthView.updateCurrentlySelectedDay(viewX, viewY)
|
||||
}
|
||||
addView(this)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<dimen name="yearly_padding_side">10dp</dimen>
|
||||
<dimen name="yearly_padding_half">3dp</dimen>
|
||||
<dimen name="yearly_padding_full">6dp</dimen>
|
||||
<dimen name="circle_stroke_width">2dp</dimen>
|
||||
|
||||
<dimen name="monthly_day_height">40dp</dimen>
|
||||
|
||||
|
|
Loading…
Reference in New Issue