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))
eventTypeId = dbHelper.insertEventType(eventType)
}
val result = IcsImporter().importEvents(this, it as String, eventTypeId)
val result = IcsImporter(this).importEvents(it as String, eventTypeId)
handleParseResult(result)
if (result != IcsImporter.ImportResult.IMPORT_FAIL) {
runOnUiThread {

View File

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

View File

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