add some ics file format checking
This commit is contained in:
parent
7e8bc89eeb
commit
56e7929466
15 changed files with 45 additions and 10 deletions
|
@ -28,6 +28,7 @@ import com.simplemobiletools.calendar.views.MyScrollView
|
|||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
import com.simplemobiletools.commons.extensions.checkWhatsNew
|
||||
import com.simplemobiletools.commons.extensions.hasReadStoragePermission
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.commons.helpers.LICENSE_JODA
|
||||
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
|
||||
|
@ -157,8 +158,16 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
|
|||
|
||||
private fun importEvents() {
|
||||
FilePickerDialog(this) {
|
||||
ImportEventsDialog(this, it) {
|
||||
|
||||
if (it.toLowerCase().endsWith(".ics")) {
|
||||
ImportEventsDialog(this, it) {
|
||||
if (it) {
|
||||
toast(R.string.events_imported_successfully)
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toast(R.string.invalid_file_format)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,17 +8,14 @@ import android.widget.AdapterView
|
|||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.extensions.getDefaultReminderTypeIndex
|
||||
import com.simplemobiletools.calendar.extensions.setupReminderPeriod
|
||||
import com.simplemobiletools.calendar.helpers.DAY_MINS
|
||||
import com.simplemobiletools.calendar.helpers.HOUR_MINS
|
||||
import com.simplemobiletools.calendar.helpers.REMINDER_AT_START
|
||||
import com.simplemobiletools.calendar.helpers.REMINDER_OFF
|
||||
import com.simplemobiletools.calendar.helpers.*
|
||||
import com.simplemobiletools.commons.extensions.humanizePath
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.extensions.showKeyboard
|
||||
import com.simplemobiletools.commons.extensions.value
|
||||
import kotlinx.android.synthetic.main.dialog_import_events.view.*
|
||||
|
||||
class ImportEventsDialog(val activity: Activity, val path: String, val callback: () -> Unit) : AlertDialog.Builder(activity) {
|
||||
class ImportEventsDialog(val activity: Activity, val path: String, val callback: (success: Boolean) -> Unit) : AlertDialog.Builder(activity) {
|
||||
init {
|
||||
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_import_events, null).apply {
|
||||
import_events_filename.text = activity.humanizePath(path)
|
||||
|
@ -52,6 +49,13 @@ class ImportEventsDialog(val activity: Activity, val path: String, val callback:
|
|||
1 -> REMINDER_AT_START
|
||||
else -> getReminderMinutes(view)
|
||||
}
|
||||
|
||||
try {
|
||||
IcsParser.parseIcs(context, minutes, path)
|
||||
callback.invoke(true)
|
||||
} catch (e: Exception) {
|
||||
callback.invoke(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ object IcsParser {
|
|||
var curTitle = ""
|
||||
var curDescription = ""
|
||||
|
||||
fun parseIcs(context: Context) {
|
||||
fun parseIcs(context: Context, reminderMinutes: Int, path: String) {
|
||||
val inputStream = context.resources.openRawResource(R.raw.sample)
|
||||
|
||||
inputStream.bufferedReader().use {
|
||||
|
@ -41,7 +41,7 @@ object IcsParser {
|
|||
if (curTitle.isEmpty() || curStart == -1 || curEnd == -1)
|
||||
continue
|
||||
|
||||
val event = Event(0, curStart, curEnd, curTitle, curDescription)
|
||||
val event = Event(0, curStart, curEnd, curTitle, curDescription, reminderMinutes)
|
||||
resetValues()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/import_events"
|
||||
android:title="@string/import_events"
|
||||
android:title="@string/import_events_from_ics"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/settings"
|
||||
|
|
|
@ -44,8 +44,10 @@
|
|||
|
||||
<!-- Importing -->
|
||||
<string name="import_events">Import events</string>
|
||||
<string name="import_events_from_ics">Import events from an .ics file</string>
|
||||
<string name="event_reminder">Event reminder</string>
|
||||
<string name="events_imported_successfully">Events imported successfully</string>
|
||||
<string name="invalid_file_format">Invalid file format</string>
|
||||
|
||||
<!-- Day details -->
|
||||
<string name="details">Details</string>
|
||||
|
|
|
@ -44,8 +44,10 @@
|
|||
|
||||
<!-- Importing -->
|
||||
<string name="import_events">Import events</string>
|
||||
<string name="import_events_from_ics">Import events from an .ics file</string>
|
||||
<string name="event_reminder">Event reminder</string>
|
||||
<string name="events_imported_successfully">Events imported successfully</string>
|
||||
<string name="invalid_file_format">Invalid file format</string>
|
||||
|
||||
<!-- Day details -->
|
||||
<string name="details">Detalles</string>
|
||||
|
|
|
@ -44,8 +44,10 @@
|
|||
|
||||
<!-- Importing -->
|
||||
<string name="import_events">Import events</string>
|
||||
<string name="import_events_from_ics">Import events from an .ics file</string>
|
||||
<string name="event_reminder">Event reminder</string>
|
||||
<string name="events_imported_successfully">Events imported successfully</string>
|
||||
<string name="invalid_file_format">Invalid file format</string>
|
||||
|
||||
<!-- Day details -->
|
||||
<string name="details">Détails</string>
|
||||
|
|
|
@ -44,8 +44,10 @@
|
|||
|
||||
<!-- Importing -->
|
||||
<string name="import_events">Import events</string>
|
||||
<string name="import_events_from_ics">Import events from an .ics file</string>
|
||||
<string name="event_reminder">Event reminder</string>
|
||||
<string name="events_imported_successfully">Events imported successfully</string>
|
||||
<string name="invalid_file_format">Invalid file format</string>
|
||||
|
||||
<!-- Day details -->
|
||||
<string name="details">विवरण</string>
|
||||
|
|
|
@ -44,8 +44,10 @@
|
|||
|
||||
<!-- Importing -->
|
||||
<string name="import_events">Import events</string>
|
||||
<string name="import_events_from_ics">Import events from an .ics file</string>
|
||||
<string name="event_reminder">Event reminder</string>
|
||||
<string name="events_imported_successfully">Events imported successfully</string>
|
||||
<string name="invalid_file_format">Invalid file format</string>
|
||||
|
||||
<!-- Day details -->
|
||||
<string name="details">Részletek</string>
|
||||
|
|
|
@ -44,8 +44,10 @@
|
|||
|
||||
<!-- Importing -->
|
||||
<string name="import_events">Import events</string>
|
||||
<string name="import_events_from_ics">Import events from an .ics file</string>
|
||||
<string name="event_reminder">Event reminder</string>
|
||||
<string name="events_imported_successfully">Events imported successfully</string>
|
||||
<string name="invalid_file_format">Invalid file format</string>
|
||||
|
||||
<!-- Day details -->
|
||||
<string name="details">Dettagli</string>
|
||||
|
|
|
@ -44,8 +44,10 @@
|
|||
|
||||
<!-- Importing -->
|
||||
<string name="import_events">Import events</string>
|
||||
<string name="import_events_from_ics">Import events from an .ics file</string>
|
||||
<string name="event_reminder">Event reminder</string>
|
||||
<string name="events_imported_successfully">Events imported successfully</string>
|
||||
<string name="invalid_file_format">Invalid file format</string>
|
||||
|
||||
<!-- Day details -->
|
||||
<string name="details">詳細</string>
|
||||
|
|
|
@ -44,8 +44,10 @@
|
|||
|
||||
<!-- Importing -->
|
||||
<string name="import_events">Import events</string>
|
||||
<string name="import_events_from_ics">Import events from an .ics file</string>
|
||||
<string name="event_reminder">Event reminder</string>
|
||||
<string name="events_imported_successfully">Events imported successfully</string>
|
||||
<string name="invalid_file_format">Invalid file format</string>
|
||||
|
||||
<!-- Day details -->
|
||||
<string name="details">Detalhes</string>
|
||||
|
|
|
@ -44,8 +44,10 @@
|
|||
|
||||
<!-- Importing -->
|
||||
<string name="import_events">Import events</string>
|
||||
<string name="import_events_from_ics">Import events from an .ics file</string>
|
||||
<string name="event_reminder">Event reminder</string>
|
||||
<string name="events_imported_successfully">Events imported successfully</string>
|
||||
<string name="invalid_file_format">Invalid file format</string>
|
||||
|
||||
<!-- Day details -->
|
||||
<string name="details">Подробности</string>
|
||||
|
|
|
@ -44,8 +44,10 @@
|
|||
|
||||
<!-- Importing -->
|
||||
<string name="import_events">Import events</string>
|
||||
<string name="import_events_from_ics">Import events from an .ics file</string>
|
||||
<string name="event_reminder">Event reminder</string>
|
||||
<string name="events_imported_successfully">Events imported successfully</string>
|
||||
<string name="invalid_file_format">Invalid file format</string>
|
||||
|
||||
<!-- Day details -->
|
||||
<string name="details">Detaljer</string>
|
||||
|
|
|
@ -44,8 +44,10 @@
|
|||
|
||||
<!-- Importing -->
|
||||
<string name="import_events">Import events</string>
|
||||
<string name="import_events_from_ics">Import events from an .ics file</string>
|
||||
<string name="event_reminder">Event reminder</string>
|
||||
<string name="events_imported_successfully">Events imported successfully</string>
|
||||
<string name="invalid_file_format">Invalid file format</string>
|
||||
|
||||
<!-- Day details -->
|
||||
<string name="details">Details</string>
|
||||
|
|
Loading…
Reference in a new issue