dim past events on the monthly views when appropriate

This commit is contained in:
tibbi 2018-05-04 21:36:28 +02:00
parent 135d2bc8c2
commit 0a8606c373
8 changed files with 33 additions and 25 deletions

View file

@ -63,6 +63,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private var mStoredDayCode = ""
private var mStoredIsSundayFirst = false
private var mStoredUse24HourFormat = false
private var mStoredDimPastEvents = true
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -103,7 +104,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
override fun onResume() {
super.onResume()
if (mStoredTextColor != config.textColor || mStoredBackgroundColor != config.backgroundColor || mStoredPrimaryColor != config.primaryColor
|| mStoredDayCode != Formatter.getTodayCode(applicationContext)) {
|| mStoredDayCode != Formatter.getTodayCode(applicationContext) || mStoredDimPastEvents != config.dimPastEvents) {
updateViewPager()
}
@ -199,6 +200,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
mStoredPrimaryColor = primaryColor
mStoredBackgroundColor = backgroundColor
mStoredUse24HourFormat = use24HourFormat
mStoredDimPastEvents = dimPastEvents
}
mStoredDayCode = Formatter.getTodayCode(applicationContext)
}

View file

@ -674,7 +674,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
events.addAll(getRepeatableEventsFor(fromTS, toTS, eventId))
events.addAll(getAllDayEvents(fromTS, toTS, eventId))
events.addAll(getAllDayEvents(fromTS, eventId))
val filtered = events.distinct().filterNot { it.ignoreEventOccurrences.contains(Formatter.getDayCodeFromTS(it.startTS).toInt()) } as MutableList<Event>
callback(filtered)
@ -709,11 +709,11 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
if (event.repeatInterval.isXWeeklyRepetition()) {
if (event.startTS.isTsOnProperDay(event)) {
if (isOnProperWeek(event, startTimes)) {
events.add(event.copy())
events.add(event.copy(isPastEvent = event.getIsPastEvent()))
}
}
} else {
events.add(event.copy())
events.add(event.copy(isPastEvent = event.getIsPastEvent()))
}
}
@ -721,14 +721,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
if (event.repeatInterval.isXWeeklyRepetition()) {
if (event.endTS >= toTS && event.startTS.isTsOnProperDay(event)) {
if (isOnProperWeek(event, startTimes)) {
events.add(event.copy())
events.add(event.copy(isPastEvent = event.getIsPastEvent()))
}
}
} else {
val dayCode = Formatter.getDayCodeFromTS(fromTS)
val endDayCode = Formatter.getDayCodeFromTS(event.endTS)
if (dayCode == endDayCode) {
events.add(event.copy())
events.add(event.copy(isPastEvent = event.getIsPastEvent()))
}
}
}
@ -745,7 +745,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
if (event.startTS.isTsOnProperDay(event)) {
if (isOnProperWeek(event, startTimes)) {
if (event.endTS >= fromTS) {
events.add(event.copy())
events.add(event.copy(isPastEvent = event.getIsPastEvent()))
}
event.repeatLimit++
}
@ -757,7 +757,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
val dayCode = Formatter.getDayCodeFromTS(fromTS)
val endDayCode = Formatter.getDayCodeFromTS(event.endTS)
if (dayCode == endDayCode) {
events.add(event.copy())
events.add(event.copy(isPastEvent = event.getIsPastEvent()))
}
}
event.repeatLimit++
@ -767,7 +767,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
return events
}
private fun getAllDayEvents(fromTS: Int, toTS: Int, eventId: Int = -1): List<Event> {
private fun getAllDayEvents(fromTS: Int, eventId: Int = -1): List<Event> {
val events = ArrayList<Event>()
var selection = "($COL_FLAGS & $FLAG_ALL_DAY) != 0"
if (eventId != -1)
@ -914,9 +914,11 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
repeatRule = REPEAT_MONTH_SAME_DAY
}
val isPastEvent = endTS < System.currentTimeMillis() / 1000
val event = Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes,
repeatInterval, importId, flags, repeatLimit, repeatRule, eventType, ignoreEventOccurrences, offset, isDstIncluded,
0, lastUpdated, source, color, location)
0, lastUpdated, source, color, location, isPastEvent)
events.add(event)
} while (cursor.moveToNext())

View file

@ -84,6 +84,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
private fun updateDays(context: Context, views: RemoteViews, days: List<DayMonthly>) {
val displayWeekNumbers = context.config.showWeekNumbers
val textColor = context.config.widgetTextColor
val dimPastEvents = context.config.dimPastEvents
val smallerFontSize = context.config.getFontSize() - 3f
val res = context.resources
val len = days.size
@ -117,7 +118,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
var backgroundColor = it.color
var eventTextColor = backgroundColor.getContrastColor()
if (!day.isThisMonth) {
if (!day.isThisMonth || (dimPastEvents && it.getIsPastEvent())) {
eventTextColor = eventTextColor.adjustAlpha(0.25f)
backgroundColor = backgroundColor.adjustAlpha(0.25f)
}

View file

@ -2,6 +2,4 @@ package com.simplemobiletools.calendar.models
data class DayMonthly(val value: Int, val isThisMonth: Boolean, val isToday: Boolean, val code: String, val weekOfYear: Int, var dayEvents: ArrayList<Event>,
var indexOnMonthView: Int) {
fun hasEvent() = dayEvents.isNotEmpty()
}

View file

@ -12,7 +12,8 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
var importId: String = "", var flags: Int = 0, var repeatLimit: Int = 0, var repeatRule: Int = 0,
var eventType: Int = DBHelper.REGULAR_EVENT_TYPE_ID, var ignoreEventOccurrences: ArrayList<Int> = ArrayList(),
var offset: String = "", var isDstIncluded: Boolean = false, var parentId: Int = 0, var lastUpdated: Long = 0L,
var source: String = SOURCE_SIMPLE_CALENDAR, var color: Int = 0, var location: String = "") : Serializable {
var source: String = SOURCE_SIMPLE_CALENDAR, var color: Int = 0, var location: String = "", var isPastEvent: Boolean = false)
: Serializable {
companion object {
private val serialVersionUID = -32456795132345616L
@ -111,4 +112,6 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
}
fun getCalDAVCalendarId() = if (source.startsWith(CALDAV)) (source.split("-").lastOrNull() ?: "0").toString().toInt() else 0
fun getIsPastEvent() = endTS < System.currentTimeMillis() / 1000
}

View file

@ -1,4 +1,4 @@
package com.simplemobiletools.calendar.models
data class MonthViewEvent(val id: Int, val title: String, val startTS: Int, val color: Int, val startDayIndex: Int, val daysCnt: Int, val originalStartDayIndex: Int,
val isAllDay: Boolean)
val isAllDay: Boolean, val isPastEvent: Boolean)

View file

@ -43,6 +43,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
private var maxEventsPerDay = 0
private var horizontalOffset = 0
private var showWeekNumbers = false
private var dimPastEvents = true
private var allEvents = ArrayList<MonthViewEvent>()
private var bgRectF = RectF()
private var dayLetters = ArrayList<String>()
@ -55,6 +56,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
primaryColor = context.getAdjustedPrimaryColor()
textColor = context.config.textColor
showWeekNumbers = context.config.showWeekNumbers
dimPastEvents = context.config.dimPastEvents
smallPadding = resources.displayMetrics.density.toInt()
val normalTextSize = resources.getDimensionPixelSize(R.dimen.normal_text_size)
@ -103,7 +105,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
val daysCnt = getEventLastingDaysCount(event)
if (lastEvent == null || lastEvent.startDayIndex + daysCnt <= day.indexOnMonthView) {
val monthViewEvent = MonthViewEvent(event.id, event.title, event.startTS, event.color, day.indexOnMonthView,
daysCnt, day.indexOnMonthView, event.getIsAllDay())
daysCnt, day.indexOnMonthView, event.getIsAllDay(), event.isPastEvent)
allEvents.add(monthViewEvent)
}
}
@ -236,16 +238,16 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
bgRectF.set(bgLeft, bgTop, bgRight, bgBottom)
canvas.drawRoundRect(bgRectF, BG_CORNER_RADIUS, BG_CORNER_RADIUS, getEventBackgroundColor(event, startDayIndex, endDayIndex))
drawEventTitle(event.title, canvas, xPos, yPos + verticalOffset, bgRight - bgLeft - smallPadding, event.color, startDayIndex, endDayIndex)
drawEventTitle(event, canvas, xPos, yPos + verticalOffset, bgRight - bgLeft - smallPadding, startDayIndex, endDayIndex)
for (i in 0 until Math.min(event.daysCnt, 7 - event.startDayIndex % 7)) {
dayVerticalOffsets.put(event.startDayIndex + i, verticalOffset + eventTitleHeight + smallPadding * 2)
}
}
private fun drawEventTitle(title: String, canvas: Canvas, x: Float, y: Float, availableWidth: Float, eventColor: Int, startDay: DayMonthly, endDay: DayMonthly) {
val ellipsized = TextUtils.ellipsize(title, eventTitlePaint, availableWidth - smallPadding, TextUtils.TruncateAt.END)
canvas.drawText(title, 0, ellipsized.length, x + smallPadding * 2, y, getEventTitlePaint(eventColor, startDay, endDay))
private fun drawEventTitle(event: MonthViewEvent, canvas: Canvas, x: Float, y: Float, availableWidth: Float, startDay: DayMonthly, endDay: DayMonthly) {
val ellipsized = TextUtils.ellipsize(event.title, eventTitlePaint, availableWidth - smallPadding, TextUtils.TruncateAt.END)
canvas.drawText(event.title, 0, ellipsized.length, x + smallPadding * 2, y, getEventTitlePaint(event, startDay, endDay))
}
private fun getTextPaint(startDay: DayMonthly): Paint {
@ -269,16 +271,16 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
private fun getEventBackgroundColor(event: MonthViewEvent, startDay: DayMonthly, endDay: DayMonthly): Paint {
var paintColor = event.color
if (!startDay.isThisMonth && !endDay.isThisMonth) {
if ((!startDay.isThisMonth && !endDay.isThisMonth) || (dimPastEvents && event.isPastEvent)) {
paintColor = paintColor.adjustAlpha(LOW_ALPHA)
}
return getColoredPaint(paintColor)
}
private fun getEventTitlePaint(color: Int, startDay: DayMonthly, endDay: DayMonthly): Paint {
var paintColor = color.getContrastColor()
if (!startDay.isThisMonth && !endDay.isThisMonth) {
private fun getEventTitlePaint(event: MonthViewEvent, startDay: DayMonthly, endDay: DayMonthly): Paint {
var paintColor = event.color.getContrastColor()
if ((!startDay.isThisMonth && !endDay.isThisMonth) || (dimPastEvents && event.isPastEvent)) {
paintColor = paintColor.adjustAlpha(LOW_ALPHA)
}

View file

@ -681,7 +681,7 @@
android:layout_marginLeft="@dimen/bigger_margin"
android:layout_marginStart="@dimen/bigger_margin"
android:layout_marginTop="@dimen/activity_margin"
android:text="@string/event_reminders"
android:text="@string/events"
android:textAllCaps="true"
android:textSize="@dimen/smaller_text_size"/>