mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-17 12:20:51 +01:00
allow overriding the CATEGORIES field at ics events
This commit is contained in:
parent
154e466989
commit
52c6864a70
@ -380,7 +380,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
eventTypeId = dbHelper.insertEventType(eventType)
|
||||
}
|
||||
|
||||
val result = IcsImporter(this).importEvents(it as String, eventTypeId, 0)
|
||||
val result = IcsImporter(this).importEvents(it as String, eventTypeId, 0, false)
|
||||
handleParseResult(result)
|
||||
if (result != IcsImporter.ImportResult.IMPORT_FAIL) {
|
||||
runOnUiThread {
|
||||
|
@ -60,7 +60,8 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
activity.toast(R.string.importing)
|
||||
Thread {
|
||||
val result = IcsImporter(activity).importEvents(path, currEventTypeId, currEventTypeCalDAVCalendarId)
|
||||
val overrideFileEventTypes = view.import_events_checkbox.isChecked
|
||||
val result = IcsImporter(activity).importEvents(path, currEventTypeId, currEventTypeCalDAVCalendarId, overrideFileEventTypes)
|
||||
handleParseResult(result)
|
||||
dismiss()
|
||||
}.start()
|
||||
|
@ -28,7 +28,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||
private var curRepeatInterval = 0
|
||||
private var curRepeatLimit = 0
|
||||
private var curRepeatRule = 0
|
||||
private var curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
|
||||
private var curEventTypeId = DBHelper.REGULAR_EVENT_TYPE_ID
|
||||
private var curLastModified = 0L
|
||||
private var curLocation = ""
|
||||
private var curCategoryColor = -2
|
||||
@ -40,8 +40,9 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||
private var eventsImported = 0
|
||||
private var eventsFailed = 0
|
||||
|
||||
fun importEvents(path: String, defaultEventType: Int, calDAVCalendarId: Int): ImportResult {
|
||||
fun importEvents(path: String, defaultEventTypeId: Int, calDAVCalendarId: Int, overrideFileEventTypes: Boolean): ImportResult {
|
||||
try {
|
||||
val eventTypes = activity.dbHelper.getEventTypesSync()
|
||||
val existingEvents = activity.dbHelper.getEventsWithImportIds()
|
||||
val eventsToInsert = ArrayList<Event>()
|
||||
var prevLine = ""
|
||||
@ -74,7 +75,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||
|
||||
if (line == BEGIN_EVENT) {
|
||||
resetValues()
|
||||
curEventType = defaultEventType
|
||||
curEventTypeId = defaultEventTypeId
|
||||
} else if (line.startsWith(DTSTART)) {
|
||||
curStart = getTimestamp(line.substring(DTSTART.length))
|
||||
} else if (line.startsWith(DTEND)) {
|
||||
@ -105,7 +106,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||
if (color.trimStart('-').areDigitsOnly()) {
|
||||
curCategoryColor = Integer.parseInt(color)
|
||||
}
|
||||
} else if (line.startsWith(CATEGORIES)) {
|
||||
} else if (line.startsWith(CATEGORIES) && !overrideFileEventTypes) {
|
||||
val categories = line.substring(CATEGORIES.length)
|
||||
tryAddCategories(categories, activity)
|
||||
} else if (line.startsWith(LAST_MODIFIED)) {
|
||||
@ -137,10 +138,11 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||
continue
|
||||
}
|
||||
|
||||
val source = if (calDAVCalendarId == 0) SOURCE_IMPORTED_ICS else "$CALDAV-$calDAVCalendarId"
|
||||
val eventType = eventTypes.firstOrNull { it.id == curEventTypeId }
|
||||
val source = if (calDAVCalendarId == 0 || eventType?.isSyncedEventType() == false) SOURCE_IMPORTED_ICS else "$CALDAV-$calDAVCalendarId"
|
||||
val event = Event(0, curStart, curEnd, curTitle, curDescription, curReminderMinutes.getOrElse(0, { -1 }),
|
||||
curReminderMinutes.getOrElse(1, { -1 }), curReminderMinutes.getOrElse(2, { -1 }), curRepeatInterval,
|
||||
curImportId, curFlags, curRepeatLimit, curRepeatRule, curEventType, lastUpdated = curLastModified,
|
||||
curImportId, curFlags, curRepeatLimit, curRepeatRule, curEventTypeId, lastUpdated = curLastModified,
|
||||
source = source, location = curLocation)
|
||||
|
||||
if (event.getIsAllDay() && curEnd > curStart) {
|
||||
@ -209,7 +211,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||
}
|
||||
|
||||
val eventId = context.dbHelper.getEventTypeIdWithTitle(eventTypeTitle)
|
||||
curEventType = if (eventId == -1) {
|
||||
curEventTypeId = if (eventId == -1) {
|
||||
val newTypeColor = if (curCategoryColor == -2) context.resources.getColor(R.color.color_primary) else curCategoryColor
|
||||
val eventType = EventType(0, eventTypeTitle, newTypeColor)
|
||||
context.dbHelper.insertEventType(eventType)
|
||||
@ -238,7 +240,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||
curRepeatInterval = 0
|
||||
curRepeatLimit = 0
|
||||
curRepeatRule = 0
|
||||
curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
|
||||
curEventTypeId = DBHelper.REGULAR_EVENT_TYPE_ID
|
||||
curLastModified = 0L
|
||||
curCategoryColor = -2
|
||||
curLocation = ""
|
||||
|
@ -2,4 +2,6 @@ package com.simplemobiletools.calendar.models
|
||||
|
||||
data class EventType(var id: Int = 0, var title: String, var color: Int, var caldavCalendarId: Int = 0, var caldavDisplayName: String = "", var caldavEmail: String = "") {
|
||||
fun getDisplayTitle() = if (caldavCalendarId == 0) title else "$caldavDisplayName ($caldavEmail)"
|
||||
|
||||
fun isSyncedEventType() = caldavCalendarId != 0
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin">
|
||||
|
||||
@ -13,6 +12,7 @@
|
||||
android:id="@+id/import_events_event_type_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/activity_margin"
|
||||
android:text="@string/default_event_type"
|
||||
android:textSize="@dimen/smaller_text_size"/>
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
android:id="@+id/import_event_type_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/activity_margin"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:padding="@dimen/small_margin">
|
||||
|
||||
@ -42,4 +43,14 @@
|
||||
android:clickable="false"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||
android:id="@+id/import_events_checkbox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/normal_margin"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/override_event_types"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user