mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
dim past events on the monthly views when appropriate
This commit is contained in:
@ -63,6 +63,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
private var mStoredDayCode = ""
|
private var mStoredDayCode = ""
|
||||||
private var mStoredIsSundayFirst = false
|
private var mStoredIsSundayFirst = false
|
||||||
private var mStoredUse24HourFormat = false
|
private var mStoredUse24HourFormat = false
|
||||||
|
private var mStoredDimPastEvents = true
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -103,7 +104,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
if (mStoredTextColor != config.textColor || mStoredBackgroundColor != config.backgroundColor || mStoredPrimaryColor != config.primaryColor
|
if (mStoredTextColor != config.textColor || mStoredBackgroundColor != config.backgroundColor || mStoredPrimaryColor != config.primaryColor
|
||||||
|| mStoredDayCode != Formatter.getTodayCode(applicationContext)) {
|
|| mStoredDayCode != Formatter.getTodayCode(applicationContext) || mStoredDimPastEvents != config.dimPastEvents) {
|
||||||
updateViewPager()
|
updateViewPager()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,6 +200,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
mStoredPrimaryColor = primaryColor
|
mStoredPrimaryColor = primaryColor
|
||||||
mStoredBackgroundColor = backgroundColor
|
mStoredBackgroundColor = backgroundColor
|
||||||
mStoredUse24HourFormat = use24HourFormat
|
mStoredUse24HourFormat = use24HourFormat
|
||||||
|
mStoredDimPastEvents = dimPastEvents
|
||||||
}
|
}
|
||||||
mStoredDayCode = Formatter.getTodayCode(applicationContext)
|
mStoredDayCode = Formatter.getTodayCode(applicationContext)
|
||||||
}
|
}
|
||||||
|
@ -674,7 +674,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
|
|
||||||
events.addAll(getRepeatableEventsFor(fromTS, toTS, eventId))
|
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>
|
val filtered = events.distinct().filterNot { it.ignoreEventOccurrences.contains(Formatter.getDayCodeFromTS(it.startTS).toInt()) } as MutableList<Event>
|
||||||
callback(filtered)
|
callback(filtered)
|
||||||
@ -709,11 +709,11 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
if (event.repeatInterval.isXWeeklyRepetition()) {
|
if (event.repeatInterval.isXWeeklyRepetition()) {
|
||||||
if (event.startTS.isTsOnProperDay(event)) {
|
if (event.startTS.isTsOnProperDay(event)) {
|
||||||
if (isOnProperWeek(event, startTimes)) {
|
if (isOnProperWeek(event, startTimes)) {
|
||||||
events.add(event.copy())
|
events.add(event.copy(isPastEvent = event.getIsPastEvent()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} 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.repeatInterval.isXWeeklyRepetition()) {
|
||||||
if (event.endTS >= toTS && event.startTS.isTsOnProperDay(event)) {
|
if (event.endTS >= toTS && event.startTS.isTsOnProperDay(event)) {
|
||||||
if (isOnProperWeek(event, startTimes)) {
|
if (isOnProperWeek(event, startTimes)) {
|
||||||
events.add(event.copy())
|
events.add(event.copy(isPastEvent = event.getIsPastEvent()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val dayCode = Formatter.getDayCodeFromTS(fromTS)
|
val dayCode = Formatter.getDayCodeFromTS(fromTS)
|
||||||
val endDayCode = Formatter.getDayCodeFromTS(event.endTS)
|
val endDayCode = Formatter.getDayCodeFromTS(event.endTS)
|
||||||
if (dayCode == endDayCode) {
|
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 (event.startTS.isTsOnProperDay(event)) {
|
||||||
if (isOnProperWeek(event, startTimes)) {
|
if (isOnProperWeek(event, startTimes)) {
|
||||||
if (event.endTS >= fromTS) {
|
if (event.endTS >= fromTS) {
|
||||||
events.add(event.copy())
|
events.add(event.copy(isPastEvent = event.getIsPastEvent()))
|
||||||
}
|
}
|
||||||
event.repeatLimit++
|
event.repeatLimit++
|
||||||
}
|
}
|
||||||
@ -757,7 +757,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
val dayCode = Formatter.getDayCodeFromTS(fromTS)
|
val dayCode = Formatter.getDayCodeFromTS(fromTS)
|
||||||
val endDayCode = Formatter.getDayCodeFromTS(event.endTS)
|
val endDayCode = Formatter.getDayCodeFromTS(event.endTS)
|
||||||
if (dayCode == endDayCode) {
|
if (dayCode == endDayCode) {
|
||||||
events.add(event.copy())
|
events.add(event.copy(isPastEvent = event.getIsPastEvent()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event.repeatLimit++
|
event.repeatLimit++
|
||||||
@ -767,7 +767,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
return events
|
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>()
|
val events = ArrayList<Event>()
|
||||||
var selection = "($COL_FLAGS & $FLAG_ALL_DAY) != 0"
|
var selection = "($COL_FLAGS & $FLAG_ALL_DAY) != 0"
|
||||||
if (eventId != -1)
|
if (eventId != -1)
|
||||||
@ -914,9 +914,11 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
repeatRule = REPEAT_MONTH_SAME_DAY
|
repeatRule = REPEAT_MONTH_SAME_DAY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val isPastEvent = endTS < System.currentTimeMillis() / 1000
|
||||||
|
|
||||||
val event = Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes,
|
val event = Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes,
|
||||||
repeatInterval, importId, flags, repeatLimit, repeatRule, eventType, ignoreEventOccurrences, offset, isDstIncluded,
|
repeatInterval, importId, flags, repeatLimit, repeatRule, eventType, ignoreEventOccurrences, offset, isDstIncluded,
|
||||||
0, lastUpdated, source, color, location)
|
0, lastUpdated, source, color, location, isPastEvent)
|
||||||
|
|
||||||
events.add(event)
|
events.add(event)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
|
@ -84,6 +84,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
|
|||||||
private fun updateDays(context: Context, views: RemoteViews, days: List<DayMonthly>) {
|
private fun updateDays(context: Context, views: RemoteViews, days: List<DayMonthly>) {
|
||||||
val displayWeekNumbers = context.config.showWeekNumbers
|
val displayWeekNumbers = context.config.showWeekNumbers
|
||||||
val textColor = context.config.widgetTextColor
|
val textColor = context.config.widgetTextColor
|
||||||
|
val dimPastEvents = context.config.dimPastEvents
|
||||||
val smallerFontSize = context.config.getFontSize() - 3f
|
val smallerFontSize = context.config.getFontSize() - 3f
|
||||||
val res = context.resources
|
val res = context.resources
|
||||||
val len = days.size
|
val len = days.size
|
||||||
@ -117,7 +118,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
|
|||||||
var backgroundColor = it.color
|
var backgroundColor = it.color
|
||||||
var eventTextColor = backgroundColor.getContrastColor()
|
var eventTextColor = backgroundColor.getContrastColor()
|
||||||
|
|
||||||
if (!day.isThisMonth) {
|
if (!day.isThisMonth || (dimPastEvents && it.getIsPastEvent())) {
|
||||||
eventTextColor = eventTextColor.adjustAlpha(0.25f)
|
eventTextColor = eventTextColor.adjustAlpha(0.25f)
|
||||||
backgroundColor = backgroundColor.adjustAlpha(0.25f)
|
backgroundColor = backgroundColor.adjustAlpha(0.25f)
|
||||||
}
|
}
|
||||||
|
@ -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>,
|
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) {
|
var indexOnMonthView: Int) {
|
||||||
|
|
||||||
fun hasEvent() = dayEvents.isNotEmpty()
|
|
||||||
}
|
}
|
||||||
|
@ -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 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 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 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 {
|
companion object {
|
||||||
private val serialVersionUID = -32456795132345616L
|
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 getCalDAVCalendarId() = if (source.startsWith(CALDAV)) (source.split("-").lastOrNull() ?: "0").toString().toInt() else 0
|
||||||
|
|
||||||
|
fun getIsPastEvent() = endTS < System.currentTimeMillis() / 1000
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.simplemobiletools.calendar.models
|
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,
|
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)
|
||||||
|
@ -43,6 +43,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||||||
private var maxEventsPerDay = 0
|
private var maxEventsPerDay = 0
|
||||||
private var horizontalOffset = 0
|
private var horizontalOffset = 0
|
||||||
private var showWeekNumbers = false
|
private var showWeekNumbers = false
|
||||||
|
private var dimPastEvents = true
|
||||||
private var allEvents = ArrayList<MonthViewEvent>()
|
private var allEvents = ArrayList<MonthViewEvent>()
|
||||||
private var bgRectF = RectF()
|
private var bgRectF = RectF()
|
||||||
private var dayLetters = ArrayList<String>()
|
private var dayLetters = ArrayList<String>()
|
||||||
@ -55,6 +56,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||||||
primaryColor = context.getAdjustedPrimaryColor()
|
primaryColor = context.getAdjustedPrimaryColor()
|
||||||
textColor = context.config.textColor
|
textColor = context.config.textColor
|
||||||
showWeekNumbers = context.config.showWeekNumbers
|
showWeekNumbers = context.config.showWeekNumbers
|
||||||
|
dimPastEvents = context.config.dimPastEvents
|
||||||
|
|
||||||
smallPadding = resources.displayMetrics.density.toInt()
|
smallPadding = resources.displayMetrics.density.toInt()
|
||||||
val normalTextSize = resources.getDimensionPixelSize(R.dimen.normal_text_size)
|
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)
|
val daysCnt = getEventLastingDaysCount(event)
|
||||||
if (lastEvent == null || lastEvent.startDayIndex + daysCnt <= day.indexOnMonthView) {
|
if (lastEvent == null || lastEvent.startDayIndex + daysCnt <= day.indexOnMonthView) {
|
||||||
val monthViewEvent = MonthViewEvent(event.id, event.title, event.startTS, event.color, 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)
|
allEvents.add(monthViewEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,16 +238,16 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||||||
bgRectF.set(bgLeft, bgTop, bgRight, bgBottom)
|
bgRectF.set(bgLeft, bgTop, bgRight, bgBottom)
|
||||||
canvas.drawRoundRect(bgRectF, BG_CORNER_RADIUS, BG_CORNER_RADIUS, getEventBackgroundColor(event, startDayIndex, endDayIndex))
|
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)) {
|
for (i in 0 until Math.min(event.daysCnt, 7 - event.startDayIndex % 7)) {
|
||||||
dayVerticalOffsets.put(event.startDayIndex + i, verticalOffset + eventTitleHeight + smallPadding * 2)
|
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) {
|
private fun drawEventTitle(event: MonthViewEvent, canvas: Canvas, x: Float, y: Float, availableWidth: Float, startDay: DayMonthly, endDay: DayMonthly) {
|
||||||
val ellipsized = TextUtils.ellipsize(title, eventTitlePaint, availableWidth - smallPadding, TextUtils.TruncateAt.END)
|
val ellipsized = TextUtils.ellipsize(event.title, eventTitlePaint, availableWidth - smallPadding, TextUtils.TruncateAt.END)
|
||||||
canvas.drawText(title, 0, ellipsized.length, x + smallPadding * 2, y, getEventTitlePaint(eventColor, startDay, endDay))
|
canvas.drawText(event.title, 0, ellipsized.length, x + smallPadding * 2, y, getEventTitlePaint(event, startDay, endDay))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTextPaint(startDay: DayMonthly): Paint {
|
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 {
|
private fun getEventBackgroundColor(event: MonthViewEvent, startDay: DayMonthly, endDay: DayMonthly): Paint {
|
||||||
var paintColor = event.color
|
var paintColor = event.color
|
||||||
if (!startDay.isThisMonth && !endDay.isThisMonth) {
|
if ((!startDay.isThisMonth && !endDay.isThisMonth) || (dimPastEvents && event.isPastEvent)) {
|
||||||
paintColor = paintColor.adjustAlpha(LOW_ALPHA)
|
paintColor = paintColor.adjustAlpha(LOW_ALPHA)
|
||||||
}
|
}
|
||||||
|
|
||||||
return getColoredPaint(paintColor)
|
return getColoredPaint(paintColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getEventTitlePaint(color: Int, startDay: DayMonthly, endDay: DayMonthly): Paint {
|
private fun getEventTitlePaint(event: MonthViewEvent, startDay: DayMonthly, endDay: DayMonthly): Paint {
|
||||||
var paintColor = color.getContrastColor()
|
var paintColor = event.color.getContrastColor()
|
||||||
if (!startDay.isThisMonth && !endDay.isThisMonth) {
|
if ((!startDay.isThisMonth && !endDay.isThisMonth) || (dimPastEvents && event.isPastEvent)) {
|
||||||
paintColor = paintColor.adjustAlpha(LOW_ALPHA)
|
paintColor = paintColor.adjustAlpha(LOW_ALPHA)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -681,7 +681,7 @@
|
|||||||
android:layout_marginLeft="@dimen/bigger_margin"
|
android:layout_marginLeft="@dimen/bigger_margin"
|
||||||
android:layout_marginStart="@dimen/bigger_margin"
|
android:layout_marginStart="@dimen/bigger_margin"
|
||||||
android:layout_marginTop="@dimen/activity_margin"
|
android:layout_marginTop="@dimen/activity_margin"
|
||||||
android:text="@string/event_reminders"
|
android:text="@string/events"
|
||||||
android:textAllCaps="true"
|
android:textAllCaps="true"
|
||||||
android:textSize="@dimen/smaller_text_size"/>
|
android:textSize="@dimen/smaller_text_size"/>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user