mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-17 12:20:51 +01:00
do the file parsing on a background thread
This commit is contained in:
parent
dd8386d5f3
commit
83ebb68f54
@ -160,10 +160,12 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
|
||||
FilePickerDialog(this) {
|
||||
if (it.toLowerCase().endsWith(".ics")) {
|
||||
ImportEventsDialog(this, it) {
|
||||
if (it) {
|
||||
toast(R.string.events_imported_successfully)
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
runOnUiThread {
|
||||
if (it) {
|
||||
toast(R.string.events_imported_successfully)
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -51,8 +51,10 @@ class ImportEventsDialog(val activity: Activity, val path: String, val callback:
|
||||
}
|
||||
|
||||
try {
|
||||
IcsParser.parseIcs(context, minutes, path)
|
||||
callback.invoke(true)
|
||||
Thread({
|
||||
IcsParser.parseIcs(context, minutes, path)
|
||||
callback.invoke(true)
|
||||
}).start()
|
||||
} catch (e: Exception) {
|
||||
callback.invoke(false)
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.simplemobiletools.calendar.helpers
|
||||
|
||||
import android.content.Context
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.extensions.seconds
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
import org.joda.time.DateTimeZone
|
||||
import org.joda.time.format.DateTimeFormat
|
||||
import java.io.File
|
||||
|
||||
object IcsParser {
|
||||
private val BEGIN_EVENT = "BEGIN:VEVENT"
|
||||
@ -22,7 +22,7 @@ object IcsParser {
|
||||
var curDescription = ""
|
||||
|
||||
fun parseIcs(context: Context, reminderMinutes: Int, path: String) {
|
||||
val inputStream = context.resources.openRawResource(R.raw.sample)
|
||||
val inputStream = File(path).inputStream()
|
||||
|
||||
inputStream.bufferedReader().use {
|
||||
while (true) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user