Make age calculation dynamic based on current calendar date and original event start date

This commit is contained in:
Paul Akhamiogu 2021-08-10 01:36:37 +01:00
parent e20d8aa616
commit 178a60c658
1 changed files with 12 additions and 3 deletions

View File

@ -10,6 +10,8 @@ import com.simplemobiletools.calendar.pro.models.EventType
import com.simplemobiletools.commons.helpers.CHOPPED_LIST_DEFAULT_SIZE import com.simplemobiletools.commons.helpers.CHOPPED_LIST_DEFAULT_SIZE
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import java.util.Date import java.util.Date
import org.joda.time.DateTime
import org.joda.time.LocalDateTime
class EventsHelper(val context: Context) { class EventsHelper(val context: Context) {
private val config = context.config private val config = context.config
@ -299,10 +301,17 @@ class EventsHelper(val context: Context) {
events.forEach { events.forEach {
it.updateIsPastEvent() it.updateIsPastEvent()
if((birthDayEventId != -1L && it.eventType == birthDayEventId) or val originalEvent = eventsDB.getEventWithId(it.id!!)
if(originalEvent != null &&
(birthDayEventId != -1L && it.eventType == birthDayEventId) or
(anniversaryEventId != -1L && it.eventType == anniversaryEventId)){ (anniversaryEventId != -1L && it.eventType == anniversaryEventId)){
val years = Date().year - Date(it.startTS).year val eventStartDate = Formatter.getDateFromTS(it.startTS)
it.title = "${it.title} ($years)" val originalEventStartDate = Formatter.getDateFromTS(originalEvent.startTS)
val years = (eventStartDate.year - originalEventStartDate.year).coerceAtLeast(0)
if(years > 0){
it.title = "${it.title} ($years)"
}
} }
it.color = eventTypeColors.get(it.eventType) ?: config.primaryColor it.color = eventTypeColors.get(it.eventType) ?: config.primaryColor
} }