Update Import and Export to account for missing year

- Add custom ics tag Constants.MISSING_YEAR that would be set to 1 if an event has the Constants.MISSING_YEAR_FLAG
- While Importing, check for the presence of the custom tag. If it is present and set to 1, add the Constants.MISSING_YEAR_FLAG to the event
This commit is contained in:
Paul Akhamiogu 2021-08-12 06:20:55 +01:00
parent fa45ef98e9
commit 1f0ae80d73
6 changed files with 10 additions and 3 deletions

View File

@ -628,7 +628,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
val flags = if(format in yearDateFormats){ val flags = if(format in yearDateFormats){
FLAG_ALL_DAY FLAG_ALL_DAY
}else { }else {
FLAG_ALL_DAY or FLAG_MISSING_YEAR_EVENT FLAG_ALL_DAY or FLAG_MISSING_YEAR
} }
val timestamp = date.time / 1000L val timestamp = date.time / 1000L

View File

@ -93,7 +93,7 @@ const val REPEAT_ORDER_WEEKDAY = 4 // i.e. every 4th sunday
// special event flags // special event flags
const val FLAG_ALL_DAY = 1 const val FLAG_ALL_DAY = 1
const val FLAG_IS_PAST_EVENT = 2 const val FLAG_IS_PAST_EVENT = 2
const val FLAG_MISSING_YEAR_EVENT = 4 const val FLAG_MISSING_YEAR = 4
// constants related to ICS file exporting / importing // constants related to ICS file exporting / importing
const val BEGIN_CALENDAR = "BEGIN:VCALENDAR" const val BEGIN_CALENDAR = "BEGIN:VCALENDAR"
@ -130,6 +130,7 @@ const val SEQUENCE = "SEQUENCE"
// this tag isn't a standard ICS tag, but there's no official way of adding a category color in an ics file // this tag isn't a standard ICS tag, but there's no official way of adding a category color in an ics file
const val CATEGORY_COLOR = "X-SMT-CATEGORY-COLOR:" const val CATEGORY_COLOR = "X-SMT-CATEGORY-COLOR:"
const val CATEGORY_COLOR_LEGACY = "CATEGORY_COLOR:" const val CATEGORY_COLOR_LEGACY = "CATEGORY_COLOR:"
const val MISSING_YEAR = "X-SMT-MISSING-YEAR:"
const val DISPLAY = "DISPLAY" const val DISPLAY = "DISPLAY"
const val EMAIL = "EMAIL" const val EMAIL = "EMAIL"

View File

@ -307,7 +307,7 @@ class EventsHelper(val context: Context) {
(anniversaryEventId != -1L && it.eventType == anniversaryEventId)){ (anniversaryEventId != -1L && it.eventType == anniversaryEventId)){
val eventStartDate = Formatter.getDateFromTS(it.startTS) val eventStartDate = Formatter.getDateFromTS(it.startTS)
val originalEventStartDate = Formatter.getDateFromTS(originalEvent.startTS) val originalEventStartDate = Formatter.getDateFromTS(originalEvent.startTS)
if(it.flags and FLAG_MISSING_YEAR_EVENT == 0){ if(it.hasMissingYear().not()){
val years = (eventStartDate.year - originalEventStartDate.year).coerceAtLeast(0) val years = (eventStartDate.year - originalEventStartDate.year).coerceAtLeast(0)
if(years > 0){ if(years > 0){
it.title = "${it.title} ($years)" it.title = "${it.title} ($years)"

View File

@ -58,6 +58,7 @@ class IcsExporter {
event.startTS.let { out.writeLn("$DTSTART:${Formatter.getExportedTime(it * 1000L)}") } event.startTS.let { out.writeLn("$DTSTART:${Formatter.getExportedTime(it * 1000L)}") }
event.endTS.let { out.writeLn("$DTEND:${Formatter.getExportedTime(it * 1000L)}") } event.endTS.let { out.writeLn("$DTEND:${Formatter.getExportedTime(it * 1000L)}") }
} }
event.hasMissingYear().let { out.writeLn("$MISSING_YEAR${if(it) 1 else 0}") }
out.writeLn("$DTSTAMP$exportTime") out.writeLn("$DTSTAMP$exportTime")
out.writeLn("$STATUS$CONFIRMED") out.writeLn("$STATUS$CONFIRMED")

View File

@ -128,6 +128,10 @@ class IcsImporter(val activity: SimpleActivity) {
if (color.trimStart('-').areDigitsOnly()) { if (color.trimStart('-').areDigitsOnly()) {
curCategoryColor = Integer.parseInt(color) curCategoryColor = Integer.parseInt(color)
} }
} else if (line.startsWith(MISSING_YEAR)) {
if (line.substring(MISSING_YEAR.length) == "1") {
curFlags = curFlags or FLAG_MISSING_YEAR
}
} else if (line.startsWith(CATEGORIES) && !overrideFileEventTypes) { } else if (line.startsWith(CATEGORIES) && !overrideFileEventTypes) {
val categories = line.substring(CATEGORIES.length) val categories = line.substring(CATEGORIES.length)
tryAddCategories(categories) tryAddCategories(categories)

View File

@ -138,6 +138,7 @@ data class Event(
} }
fun getIsAllDay() = flags and FLAG_ALL_DAY != 0 fun getIsAllDay() = flags and FLAG_ALL_DAY != 0
fun hasMissingYear() = flags and FLAG_MISSING_YEAR != 0
fun getReminders() = setOf( fun getReminders() = setOf(
Reminder(reminder1Minutes, reminder1Type), Reminder(reminder1Minutes, reminder1Type),