display an error toast at importing ics events time parsing

This commit is contained in:
tibbi
2017-12-04 12:15:47 +01:00
parent b736132f90
commit 426313bb17
3 changed files with 5 additions and 4 deletions

View File

@@ -301,7 +301,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
val eventType = EventType(0, holidays, resources.getColor(R.color.default_holidays_color)) val eventType = EventType(0, holidays, resources.getColor(R.color.default_holidays_color))
eventTypeId = dbHelper.insertEventType(eventType) eventTypeId = dbHelper.insertEventType(eventType)
} }
val result = IcsImporter().importEvents(this, it as String, eventTypeId) val result = IcsImporter(this).importEvents(it as String, eventTypeId)
handleParseResult(result) handleParseResult(result)
if (result != IcsImporter.ImportResult.IMPORT_FAIL) { if (result != IcsImporter.ImportResult.IMPORT_FAIL) {
runOnUiThread { runOnUiThread {

View File

@@ -36,7 +36,7 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
activity.toast(R.string.importing) activity.toast(R.string.importing)
Thread { Thread {
val result = IcsImporter().importEvents(activity, path, currEventTypeId) val result = IcsImporter(activity).importEvents(path, currEventTypeId)
handleParseResult(result) handleParseResult(result)
dismiss() dismiss()
}.start() }.start()

View File

@@ -12,7 +12,7 @@ import com.simplemobiletools.commons.extensions.areDigitsOnly
import com.simplemobiletools.commons.extensions.showErrorToast import com.simplemobiletools.commons.extensions.showErrorToast
import java.io.File import java.io.File
class IcsImporter { class IcsImporter(val activity: SimpleActivity) {
enum class ImportResult { enum class ImportResult {
IMPORT_FAIL, IMPORT_OK, IMPORT_PARTIAL IMPORT_FAIL, IMPORT_OK, IMPORT_PARTIAL
} }
@@ -39,7 +39,7 @@ class IcsImporter {
private var eventsImported = 0 private var eventsImported = 0
private var eventsFailed = 0 private var eventsFailed = 0
fun importEvents(activity: SimpleActivity, path: String, defaultEventType: Int): ImportResult { fun importEvents(path: String, defaultEventType: Int): ImportResult {
try { try {
val existingEvents = activity.dbHelper.getEventsWithImportIds() val existingEvents = activity.dbHelper.getEventsWithImportIds()
var prevLine = "" var prevLine = ""
@@ -172,6 +172,7 @@ class IcsImporter {
Parser().parseDateTimeValue(fullString.substring(1)) Parser().parseDateTimeValue(fullString.substring(1))
} }
} catch (e: Exception) { } catch (e: Exception) {
activity.showErrorToast(e, Toast.LENGTH_LONG)
eventsFailed++ eventsFailed++
-1 -1
} }