make the error reporting at ics file importing more verbose

This commit is contained in:
tibbi 2017-09-02 00:20:02 +02:00
parent d62e565874
commit 929dbf6e60
3 changed files with 14 additions and 10 deletions

View File

@ -264,7 +264,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
val eventType = EventType(0, holidays, config.primaryColor)
eventTypeId = dbHelper.insertEventType(eventType)
}
val result = IcsImporter().importEvents(applicationContext, it as String, eventTypeId)
val result = IcsImporter().importEvents(this, it as String, eventTypeId)
handleParseResult(result)
}).start()
}

View File

@ -1,9 +1,9 @@
package com.simplemobiletools.calendar.dialogs
import android.app.Activity
import android.support.v7.app.AlertDialog
import android.view.ViewGroup
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.helpers.DBHelper
@ -14,7 +14,7 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.toast
import kotlinx.android.synthetic.main.dialog_import_events.view.*
class ImportEventsDialog(val activity: Activity, val path: String, val callback: (refreshView: Boolean) -> Unit) : AlertDialog.Builder(activity) {
class ImportEventsDialog(val activity: SimpleActivity, val path: String, val callback: (refreshView: Boolean) -> Unit) : AlertDialog.Builder(activity) {
var currEventTypeId = DBHelper.REGULAR_EVENT_TYPE_ID
init {
@ -36,7 +36,7 @@ class ImportEventsDialog(val activity: Activity, val path: String, val callback:
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
activity.toast(R.string.importing)
Thread({
val result = IcsImporter().importEvents(context, path, currEventTypeId)
val result = IcsImporter().importEvents(activity, path, currEventTypeId)
handleParseResult(result)
dismiss()
}).start()

View File

@ -1,11 +1,14 @@
package com.simplemobiletools.calendar.helpers
import android.content.Context
import android.widget.Toast
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.helpers.IcsImporter.ImportResult.*
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.models.EventType
import com.simplemobiletools.commons.extensions.showErrorToast
import java.io.File
class IcsImporter {
@ -32,15 +35,15 @@ class IcsImporter {
var eventsImported = 0
var eventsFailed = 0
fun importEvents(context: Context, path: String, defaultEventType: Int): ImportResult {
fun importEvents(activity: SimpleActivity, path: String, defaultEventType: Int): ImportResult {
try {
val importIDs = context.dbHelper.getImportIds()
val importIDs = activity.dbHelper.getImportIds()
var prevLine = ""
val inputStream = if (path.contains("/")) {
File(path).inputStream()
} else {
context.assets.open(path)
activity.assets.open(path)
}
inputStream.bufferedReader().use {
@ -84,7 +87,7 @@ class IcsImporter {
curReminderMinutes.add(Parser().parseDurationSeconds(line.substring(TRIGGER.length)) / 60)
} else if (line.startsWith(CATEGORIES)) {
val categories = line.substring(CATEGORIES.length)
tryAddCategories(categories, context)
tryAddCategories(categories, activity)
} else if (line.startsWith(LAST_MODIFIED)) {
curLastModified = getTimestamp(line.substring(LAST_MODIFIED.length)) * 1000L
} else if (line.startsWith(EXDATE)) {
@ -105,9 +108,9 @@ class IcsImporter {
event.endTS -= DAY
}
context.dbHelper.insert(event, true) {
activity.dbHelper.insert(event, true) {
for (exceptionTS in curRepeatExceptions) {
context.dbHelper.addEventRepeatException(it, exceptionTS)
activity.dbHelper.addEventRepeatException(it, exceptionTS)
}
eventsImported++
resetValues()
@ -117,6 +120,7 @@ class IcsImporter {
}
}
} catch (e: Exception) {
activity.showErrorToast(e.toString(), Toast.LENGTH_LONG)
eventsFailed++
}