diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt index 24873d87a..710f41ada 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt @@ -514,6 +514,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { private fun handleParseResult(result: IcsImporter.ImportResult) { toast(when (result) { + IcsImporter.ImportResult.IMPORT_NOTHING_NEW -> R.string.no_new_items IcsImporter.ImportResult.IMPORT_OK -> R.string.holidays_imported_successfully IcsImporter.ImportResult.IMPORT_PARTIAL -> R.string.importing_some_holidays_failed else -> R.string.importing_holidays_failed diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ImportEventsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ImportEventsDialog.kt index f4ff29e81..0a65e2144 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ImportEventsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ImportEventsDialog.kt @@ -92,6 +92,7 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal private fun handleParseResult(result: IcsImporter.ImportResult) { activity.toast(when (result) { + IMPORT_NOTHING_NEW -> R.string.no_new_items IMPORT_OK -> R.string.importing_successful IMPORT_PARTIAL -> R.string.importing_some_entries_failed else -> R.string.importing_failed diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt index 43a7f96e2..9c7e342f9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt @@ -15,7 +15,7 @@ import java.io.File class IcsImporter(val activity: SimpleActivity) { enum class ImportResult { - IMPORT_FAIL, IMPORT_OK, IMPORT_PARTIAL + IMPORT_FAIL, IMPORT_OK, IMPORT_PARTIAL, IMPORT_NOTHING_NEW } private var curStart = -1L @@ -45,6 +45,7 @@ class IcsImporter(val activity: SimpleActivity) { private var eventsImported = 0 private var eventsFailed = 0 + private var eventsAlreadyExist = 0 fun importEvents(path: String, defaultEventTypeId: Long, calDAVCalendarId: Int, overrideFileEventTypes: Boolean): ImportResult { try { @@ -152,6 +153,7 @@ class IcsImporter(val activity: SimpleActivity) { // repeating event exceptions can have the same import id as their parents, so pick the latest event to update val eventToUpdate = existingEvents.filter { curImportId.isNotEmpty() && curImportId == it.importId }.sortedByDescending { it.lastUpdated }.firstOrNull() if (eventToUpdate != null && eventToUpdate.lastUpdated >= curLastModified) { + eventsAlreadyExist++ continue } @@ -175,6 +177,7 @@ class IcsImporter(val activity: SimpleActivity) { if (event.importId.isEmpty()) { event.importId = event.hashCode().toString() if (existingEvents.map { it.importId }.contains(event.importId)) { + eventsAlreadyExist++ continue } } @@ -216,7 +219,13 @@ class IcsImporter(val activity: SimpleActivity) { } return when { - eventsImported == 0 -> IMPORT_FAIL + eventsImported == 0 -> { + if (eventsAlreadyExist > 0) { + IMPORT_NOTHING_NEW + } else { + IMPORT_FAIL + } + } eventsFailed > 0 -> IMPORT_PARTIAL else -> IMPORT_OK }