show a more specific message if no new events have been found
This commit is contained in:
parent
43baadd28a
commit
9fa0c1f20d
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue