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