use different day colors depending on the event types at yearly view
This commit is contained in:
parent
0dd4d04f43
commit
39437ee906
5 changed files with 41 additions and 21 deletions
|
@ -14,6 +14,7 @@ import com.simplemobiletools.calendar.helpers.YEAR_LABEL
|
|||
import com.simplemobiletools.calendar.helpers.YearlyCalendarImpl
|
||||
import com.simplemobiletools.calendar.interfaces.NavigationListener
|
||||
import com.simplemobiletools.calendar.interfaces.YearlyCalendar
|
||||
import com.simplemobiletools.calendar.models.DayYearly
|
||||
import com.simplemobiletools.calendar.views.SmallMonthView
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import kotlinx.android.synthetic.main.fragment_year.view.*
|
||||
|
@ -89,7 +90,7 @@ class YearFragment : Fragment(), YearlyCalendar {
|
|||
mListener = listener
|
||||
}
|
||||
|
||||
override fun updateYearlyCalendar(events: SparseArray<ArrayList<Int>>) {
|
||||
override fun updateYearlyCalendar(events: SparseArray<ArrayList<DayYearly>>) {
|
||||
if (!isAdded)
|
||||
return
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.simplemobiletools.calendar.extensions.dbHelper
|
|||
import com.simplemobiletools.calendar.extensions.getFilteredEvents
|
||||
import com.simplemobiletools.calendar.extensions.seconds
|
||||
import com.simplemobiletools.calendar.interfaces.YearlyCalendar
|
||||
import com.simplemobiletools.calendar.models.DayYearly
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
import org.joda.time.DateTime
|
||||
import java.util.*
|
||||
|
@ -23,34 +24,38 @@ class YearlyCalendarImpl(val callback: YearlyCalendar, val context: Context, val
|
|||
|
||||
private fun gotEvents(events: MutableList<Event>) {
|
||||
val filtered = context.getFilteredEvents(events)
|
||||
val arr = SparseArray<ArrayList<Int>>(12)
|
||||
val arr = SparseArray<ArrayList<DayYearly>>(12)
|
||||
|
||||
for ((id, startTS, endTS) in filtered) {
|
||||
val startDateTime = Formatter.getDateTimeFromTS(startTS)
|
||||
markDay(arr, startDateTime)
|
||||
filtered.forEach {
|
||||
val startDateTime = Formatter.getDateTimeFromTS(it.startTS)
|
||||
markDay(arr, startDateTime, it)
|
||||
|
||||
val startCode = Formatter.getDayCodeFromDateTime(startDateTime)
|
||||
val endDateTime = Formatter.getDateTimeFromTS(endTS)
|
||||
val endDateTime = Formatter.getDateTimeFromTS(it.endTS)
|
||||
val endCode = Formatter.getDayCodeFromDateTime(endDateTime)
|
||||
if (startCode != endCode) {
|
||||
var currDateTime = startDateTime
|
||||
while (Formatter.getDayCodeFromDateTime(currDateTime) != endCode) {
|
||||
currDateTime = currDateTime.plusDays(1)
|
||||
markDay(arr, currDateTime)
|
||||
markDay(arr, currDateTime, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
callback.updateYearlyCalendar(arr)
|
||||
}
|
||||
|
||||
private fun markDay(arr: SparseArray<ArrayList<Int>>, dateTime: DateTime) {
|
||||
private fun markDay(arr: SparseArray<ArrayList<DayYearly>>, dateTime: DateTime, event: Event) {
|
||||
val month = dateTime.monthOfYear
|
||||
val day = dateTime.dayOfMonth
|
||||
|
||||
if (arr[month] == null)
|
||||
if (arr[month] == null) {
|
||||
arr.put(month, ArrayList())
|
||||
for (i in 1..32)
|
||||
arr.get(month).add(DayYearly())
|
||||
}
|
||||
|
||||
if (dateTime.year == year)
|
||||
arr.get(month).add(day)
|
||||
if (dateTime.year == year) {
|
||||
arr.get(month)[day].addColor(event.color)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package com.simplemobiletools.calendar.interfaces
|
||||
|
||||
import android.util.SparseArray
|
||||
import com.simplemobiletools.calendar.models.DayYearly
|
||||
import java.util.*
|
||||
|
||||
interface YearlyCalendar {
|
||||
fun updateYearlyCalendar(events: SparseArray<ArrayList<Int>>)
|
||||
fun updateYearlyCalendar(events: SparseArray<ArrayList<DayYearly>>)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package com.simplemobiletools.calendar.models
|
||||
|
||||
data class DayYearly(var eventColors: HashSet<Int> = HashSet()) {
|
||||
fun addColor(color: Int) = eventColors.add(color)
|
||||
}
|
|
@ -9,18 +9,18 @@ import android.view.View
|
|||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.extensions.config
|
||||
import com.simplemobiletools.calendar.helpers.MEDIUM_ALPHA
|
||||
import com.simplemobiletools.calendar.models.DayYearly
|
||||
import com.simplemobiletools.commons.extensions.adjustAlpha
|
||||
import java.util.*
|
||||
|
||||
class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) {
|
||||
private var paint: Paint
|
||||
private var coloredPaint: Paint
|
||||
private var todayCirclePaint: Paint
|
||||
private var dayWidth = 0f
|
||||
private var textColor = 0
|
||||
private var coloredTextColor = 0
|
||||
private var days = 31
|
||||
private var isLandscape = false
|
||||
private var mEvents: ArrayList<Int>? = null
|
||||
private var mEvents: ArrayList<DayYearly>? = null
|
||||
|
||||
var firstDay = 0
|
||||
var todaysId = 0
|
||||
|
@ -32,7 +32,7 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||
invalidate()
|
||||
}
|
||||
|
||||
fun setEvents(events: ArrayList<Int>?) {
|
||||
fun setEvents(events: ArrayList<DayYearly>?) {
|
||||
mEvents = events
|
||||
post { invalidate() }
|
||||
}
|
||||
|
@ -51,7 +51,6 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||
|
||||
val baseColor = context.config.textColor
|
||||
textColor = baseColor.adjustAlpha(MEDIUM_ALPHA)
|
||||
coloredTextColor = context.config.primaryColor.adjustAlpha(MEDIUM_ALPHA)
|
||||
|
||||
paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = textColor
|
||||
|
@ -59,8 +58,8 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||
textAlign = Paint.Align.RIGHT
|
||||
}
|
||||
|
||||
coloredPaint = Paint(paint)
|
||||
coloredPaint.color = coloredTextColor
|
||||
todayCirclePaint = Paint(paint)
|
||||
todayCirclePaint.color = context.config.primaryColor.adjustAlpha(MEDIUM_ALPHA)
|
||||
isLandscape = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||
}
|
||||
|
||||
|
@ -82,7 +81,7 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||
|
||||
if (curId == todaysId) {
|
||||
val dividerConstant = if (isLandscape) 6 else 4
|
||||
canvas.drawCircle(x * dayWidth - dayWidth / dividerConstant, y * dayWidth - dayWidth / dividerConstant, dayWidth * 0.41f, coloredPaint)
|
||||
canvas.drawCircle(x * dayWidth - dayWidth / dividerConstant, y * dayWidth - dayWidth / dividerConstant, dayWidth * 0.41f, todayCirclePaint)
|
||||
}
|
||||
}
|
||||
curId++
|
||||
|
@ -90,5 +89,14 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
|||
}
|
||||
}
|
||||
|
||||
private fun getPaint(curId: Int) = if (mEvents?.contains(curId) == true) coloredPaint else paint
|
||||
private fun getPaint(curId: Int): Paint {
|
||||
val colors = mEvents?.get(curId)?.eventColors ?: HashSet()
|
||||
if (colors.isNotEmpty()) {
|
||||
val curPaint = Paint(paint)
|
||||
curPaint.color = colors.first()
|
||||
return curPaint
|
||||
}
|
||||
|
||||
return paint
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue