Add flag to account for missing year for imported contact
- this avoids wrongly calculating the age/anniversary years when there was no year specified in the contact data
This commit is contained in:
parent
178a60c658
commit
1c30f0e6c6
|
@ -606,6 +606,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
val selectionArgs = arrayOf(CommonDataKinds.Event.CONTENT_ITEM_TYPE, type.toString())
|
||||
|
||||
val dateFormats = getDateFormats()
|
||||
val yearDateFormats = getDateFormatsWithYear()
|
||||
val existingEvents = if (birthdays) eventsDB.getBirthdays() else eventsDB.getAnniversaries()
|
||||
val importIDs = HashMap<String, Long>()
|
||||
existingEvents.forEach {
|
||||
|
@ -624,15 +625,17 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
try {
|
||||
val formatter = SimpleDateFormat(format, Locale.getDefault())
|
||||
val date = formatter.parse(startDate)
|
||||
if (date.year < 70) {
|
||||
date.year = 70
|
||||
val flags = if(format in yearDateFormats){
|
||||
FLAG_ALL_DAY
|
||||
}else {
|
||||
FLAG_ALL_DAY or FLAG_MISSING_YEAR_EVENT
|
||||
}
|
||||
|
||||
val timestamp = date.time / 1000L
|
||||
val lastUpdated = cursor.getLongValue(CommonDataKinds.Event.CONTACT_LAST_UPDATED_TIMESTAMP)
|
||||
val event = Event(
|
||||
null, timestamp, timestamp, name, reminder1Minutes = reminders[0], reminder2Minutes = reminders[1],
|
||||
reminder3Minutes = reminders[2], importId = contactId, timeZone = DateTimeZone.getDefault().id, flags = FLAG_ALL_DAY,
|
||||
reminder3Minutes = reminders[2], importId = contactId, timeZone = DateTimeZone.getDefault().id, flags = flags,
|
||||
repeatInterval = YEAR, repeatRule = REPEAT_SAME_DAY, eventType = eventTypeId, source = source, lastUpdated = lastUpdated
|
||||
)
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@ const val REPEAT_ORDER_WEEKDAY = 4 // i.e. every 4th sunday
|
|||
// special event flags
|
||||
const val FLAG_ALL_DAY = 1
|
||||
const val FLAG_IS_PAST_EVENT = 2
|
||||
const val FLAG_MISSING_YEAR_EVENT = 4
|
||||
|
||||
// constants related to ICS file exporting / importing
|
||||
const val BEGIN_CALENDAR = "BEGIN:VCALENDAR"
|
||||
|
@ -174,3 +175,13 @@ fun isWeekend(i: Int, isSundayFirst: Boolean): Boolean {
|
|||
i == 5 || i == 6 || i == 12 || i == 13
|
||||
}
|
||||
}
|
||||
|
||||
fun getDateFormatsWithYear() = arrayListOf(
|
||||
"yyyy-MM-dd",
|
||||
"yyyyMMdd",
|
||||
"yyyy.MM.dd",
|
||||
"yy-MM-dd",
|
||||
"yyMMdd",
|
||||
"yy.MM.dd",
|
||||
"yy/MM/dd",
|
||||
)
|
||||
|
|
|
@ -307,11 +307,12 @@ class EventsHelper(val context: Context) {
|
|||
(anniversaryEventId != -1L && it.eventType == anniversaryEventId)){
|
||||
val eventStartDate = Formatter.getDateFromTS(it.startTS)
|
||||
val originalEventStartDate = Formatter.getDateFromTS(originalEvent.startTS)
|
||||
if(it.flags and FLAG_MISSING_YEAR_EVENT == 0){
|
||||
val years = (eventStartDate.year - originalEventStartDate.year).coerceAtLeast(0)
|
||||
if(years > 0){
|
||||
it.title = "${it.title} ($years)"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
it.color = eventTypeColors.get(it.eventType) ?: config.primaryColor
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue