mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-17 04:10:45 +01:00
color the days with events in the yearly view
This commit is contained in:
parent
caae2d65e5
commit
c406a5b40a
@ -1,5 +1,8 @@
|
||||
package com.simplemobiletools.calendar
|
||||
|
||||
import android.util.SparseArray
|
||||
import java.util.*
|
||||
|
||||
interface YearlyCalendar {
|
||||
fun updateYearlyCalendar(events: MutableList<String>)
|
||||
fun updateYearlyCalendar(events: SparseArray<ArrayList<Int>>)
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
package com.simplemobiletools.calendar
|
||||
|
||||
import android.content.Context
|
||||
import android.util.SparseArray
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
import org.joda.time.DateTime
|
||||
import java.util.*
|
||||
|
||||
class YearlyCalendarImpl(val callback: YearlyCalendar, val context: Context) : DBHelper.GetEventsListener {
|
||||
|
||||
@ -14,6 +16,16 @@ class YearlyCalendarImpl(val callback: YearlyCalendar, val context: Context) : D
|
||||
}
|
||||
|
||||
override fun gotEvents(events: MutableList<Event>) {
|
||||
val arr = SparseArray<ArrayList<Int>>(12)
|
||||
for (e in events) {
|
||||
val dateTime = DateTime().withMillis(e.startTS * 1000L)
|
||||
val month = dateTime.monthOfYear
|
||||
val day = dateTime.dayOfMonth
|
||||
if (arr[month] == null)
|
||||
arr.put(month, ArrayList<Int>())
|
||||
|
||||
arr.get(month).add(day)
|
||||
}
|
||||
callback.updateYearlyCalendar(arr)
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.simplemobiletools.calendar.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.Fragment
|
||||
import android.util.SparseArray
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -9,6 +10,7 @@ import com.simplemobiletools.calendar.*
|
||||
import com.simplemobiletools.calendar.views.SmallMonthView
|
||||
import kotlinx.android.synthetic.main.year_fragment.view.*
|
||||
import org.joda.time.DateTime
|
||||
import java.util.*
|
||||
|
||||
class YearFragment : Fragment(), YearlyCalendar {
|
||||
private var mListener: NavigationListener? = null
|
||||
@ -52,7 +54,7 @@ class YearFragment : Fragment(), YearlyCalendar {
|
||||
|
||||
monthView.setFirstDay(dayOfWeek)
|
||||
monthView.setOnClickListener {
|
||||
mListener?.goToDateTime(DateTime().withDate(mYear, i, 1)
|
||||
mListener?.goToDateTime(DateTime().withDate(mYear, i, 1))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -61,7 +63,15 @@ class YearFragment : Fragment(), YearlyCalendar {
|
||||
mListener = listener
|
||||
}
|
||||
|
||||
override fun updateYearlyCalendar(events: MutableList<String>) {
|
||||
override fun updateYearlyCalendar(events: SparseArray<ArrayList<Int>>) {
|
||||
if (!isAdded)
|
||||
return
|
||||
|
||||
val res = resources
|
||||
|
||||
for (i in 1..12) {
|
||||
val monthView = mView.findViewById(res.getIdentifier("month_$i", "id", context.packageName)) as SmallMonthView
|
||||
monthView.setEvents(events.get(i))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,14 +10,19 @@ import com.simplemobiletools.calendar.Config
|
||||
import com.simplemobiletools.calendar.Constants
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.Utils
|
||||
import java.util.*
|
||||
|
||||
class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) {
|
||||
var mPaint: Paint
|
||||
var mColoredPaint: Paint
|
||||
var mDayWidth = 0f
|
||||
var mTextColor = 0
|
||||
var mColoredTextColor = 0
|
||||
var mDays = 31
|
||||
var mFirstDay = 0
|
||||
|
||||
var mEvents: ArrayList<Int>? = null
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0) {
|
||||
}
|
||||
|
||||
@ -30,6 +35,11 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||
mFirstDay = firstDay
|
||||
}
|
||||
|
||||
fun setEvents(events: ArrayList<Int>?) {
|
||||
mEvents = events
|
||||
post { invalidate() }
|
||||
}
|
||||
|
||||
init {
|
||||
val a = context.theme.obtainStyledAttributes(
|
||||
attrs,
|
||||
@ -44,11 +54,16 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||
|
||||
val baseColor = if (Config.newInstance(context).isDarkTheme) Color.WHITE else Color.BLACK
|
||||
mTextColor = Utils.adjustAlpha(baseColor, Constants.MEDIUM_ALPHA)
|
||||
mColoredTextColor = Utils.adjustAlpha(resources.getColor(R.color.colorPrimary), Constants.MEDIUM_ALPHA)
|
||||
|
||||
mPaint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
mPaint.color = mTextColor
|
||||
mPaint.textSize = resources.getDimensionPixelSize(R.dimen.tiny_text_size).toFloat()
|
||||
mPaint.textAlign = Paint.Align.RIGHT
|
||||
mPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
color = mTextColor
|
||||
textSize = resources.getDimensionPixelSize(R.dimen.tiny_text_size).toFloat()
|
||||
textAlign = Paint.Align.RIGHT
|
||||
}
|
||||
|
||||
mColoredPaint = Paint(mPaint)
|
||||
mColoredPaint.color = mColoredTextColor
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
@ -61,7 +76,10 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
|
||||
for (y in 1..6) {
|
||||
for (x in 1..7) {
|
||||
if (curId > 0 && curId <= mDays) {
|
||||
canvas.drawText(curId.toString(), x * mDayWidth, y * mDayWidth, mPaint)
|
||||
if (mEvents?.contains(curId) == true)
|
||||
canvas.drawText(curId.toString(), x * mDayWidth, y * mDayWidth, mColoredPaint)
|
||||
else
|
||||
canvas.drawText(curId.toString(), x * mDayWidth, y * mDayWidth, mPaint)
|
||||
}
|
||||
curId++
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user