mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
add some ics file format checking
This commit is contained in:
@@ -28,6 +28,7 @@ import com.simplemobiletools.calendar.views.MyScrollView
|
|||||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||||
import com.simplemobiletools.commons.extensions.checkWhatsNew
|
import com.simplemobiletools.commons.extensions.checkWhatsNew
|
||||||
import com.simplemobiletools.commons.extensions.hasReadStoragePermission
|
import com.simplemobiletools.commons.extensions.hasReadStoragePermission
|
||||||
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||||
import com.simplemobiletools.commons.helpers.LICENSE_JODA
|
import com.simplemobiletools.commons.helpers.LICENSE_JODA
|
||||||
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
|
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
|
||||||
@@ -157,8 +158,16 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
|
|||||||
|
|
||||||
private fun importEvents() {
|
private fun importEvents() {
|
||||||
FilePickerDialog(this) {
|
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.R
|
||||||
import com.simplemobiletools.calendar.extensions.getDefaultReminderTypeIndex
|
import com.simplemobiletools.calendar.extensions.getDefaultReminderTypeIndex
|
||||||
import com.simplemobiletools.calendar.extensions.setupReminderPeriod
|
import com.simplemobiletools.calendar.extensions.setupReminderPeriod
|
||||||
import com.simplemobiletools.calendar.helpers.DAY_MINS
|
import com.simplemobiletools.calendar.helpers.*
|
||||||
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.commons.extensions.humanizePath
|
import com.simplemobiletools.commons.extensions.humanizePath
|
||||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
import com.simplemobiletools.commons.extensions.showKeyboard
|
import com.simplemobiletools.commons.extensions.showKeyboard
|
||||||
import com.simplemobiletools.commons.extensions.value
|
import com.simplemobiletools.commons.extensions.value
|
||||||
import kotlinx.android.synthetic.main.dialog_import_events.view.*
|
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 {
|
init {
|
||||||
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_import_events, null).apply {
|
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_import_events, null).apply {
|
||||||
import_events_filename.text = activity.humanizePath(path)
|
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
|
1 -> REMINDER_AT_START
|
||||||
else -> getReminderMinutes(view)
|
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 curTitle = ""
|
||||||
var curDescription = ""
|
var curDescription = ""
|
||||||
|
|
||||||
fun parseIcs(context: Context) {
|
fun parseIcs(context: Context, reminderMinutes: Int, path: String) {
|
||||||
val inputStream = context.resources.openRawResource(R.raw.sample)
|
val inputStream = context.resources.openRawResource(R.raw.sample)
|
||||||
|
|
||||||
inputStream.bufferedReader().use {
|
inputStream.bufferedReader().use {
|
||||||
@@ -41,7 +41,7 @@ object IcsParser {
|
|||||||
if (curTitle.isEmpty() || curStart == -1 || curEnd == -1)
|
if (curTitle.isEmpty() || curStart == -1 || curEnd == -1)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
val event = Event(0, curStart, curEnd, curTitle, curDescription)
|
val event = Event(0, curStart, curEnd, curTitle, curDescription, reminderMinutes)
|
||||||
resetValues()
|
resetValues()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
app:showAsAction="ifRoom"/>
|
app:showAsAction="ifRoom"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/import_events"
|
android:id="@+id/import_events"
|
||||||
android:title="@string/import_events"
|
android:title="@string/import_events_from_ics"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/settings"
|
android:id="@+id/settings"
|
||||||
|
@@ -44,8 +44,10 @@
|
|||||||
|
|
||||||
<!-- Importing -->
|
<!-- Importing -->
|
||||||
<string name="import_events">Import events</string>
|
<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="event_reminder">Event reminder</string>
|
||||||
<string name="events_imported_successfully">Events imported successfully</string>
|
<string name="events_imported_successfully">Events imported successfully</string>
|
||||||
|
<string name="invalid_file_format">Invalid file format</string>
|
||||||
|
|
||||||
<!-- Day details -->
|
<!-- Day details -->
|
||||||
<string name="details">Details</string>
|
<string name="details">Details</string>
|
||||||
|
@@ -44,8 +44,10 @@
|
|||||||
|
|
||||||
<!-- Importing -->
|
<!-- Importing -->
|
||||||
<string name="import_events">Import events</string>
|
<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="event_reminder">Event reminder</string>
|
||||||
<string name="events_imported_successfully">Events imported successfully</string>
|
<string name="events_imported_successfully">Events imported successfully</string>
|
||||||
|
<string name="invalid_file_format">Invalid file format</string>
|
||||||
|
|
||||||
<!-- Day details -->
|
<!-- Day details -->
|
||||||
<string name="details">Detalles</string>
|
<string name="details">Detalles</string>
|
||||||
|
@@ -44,8 +44,10 @@
|
|||||||
|
|
||||||
<!-- Importing -->
|
<!-- Importing -->
|
||||||
<string name="import_events">Import events</string>
|
<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="event_reminder">Event reminder</string>
|
||||||
<string name="events_imported_successfully">Events imported successfully</string>
|
<string name="events_imported_successfully">Events imported successfully</string>
|
||||||
|
<string name="invalid_file_format">Invalid file format</string>
|
||||||
|
|
||||||
<!-- Day details -->
|
<!-- Day details -->
|
||||||
<string name="details">Détails</string>
|
<string name="details">Détails</string>
|
||||||
|
@@ -44,8 +44,10 @@
|
|||||||
|
|
||||||
<!-- Importing -->
|
<!-- Importing -->
|
||||||
<string name="import_events">Import events</string>
|
<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="event_reminder">Event reminder</string>
|
||||||
<string name="events_imported_successfully">Events imported successfully</string>
|
<string name="events_imported_successfully">Events imported successfully</string>
|
||||||
|
<string name="invalid_file_format">Invalid file format</string>
|
||||||
|
|
||||||
<!-- Day details -->
|
<!-- Day details -->
|
||||||
<string name="details">विवरण</string>
|
<string name="details">विवरण</string>
|
||||||
|
@@ -44,8 +44,10 @@
|
|||||||
|
|
||||||
<!-- Importing -->
|
<!-- Importing -->
|
||||||
<string name="import_events">Import events</string>
|
<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="event_reminder">Event reminder</string>
|
||||||
<string name="events_imported_successfully">Events imported successfully</string>
|
<string name="events_imported_successfully">Events imported successfully</string>
|
||||||
|
<string name="invalid_file_format">Invalid file format</string>
|
||||||
|
|
||||||
<!-- Day details -->
|
<!-- Day details -->
|
||||||
<string name="details">Részletek</string>
|
<string name="details">Részletek</string>
|
||||||
|
@@ -44,8 +44,10 @@
|
|||||||
|
|
||||||
<!-- Importing -->
|
<!-- Importing -->
|
||||||
<string name="import_events">Import events</string>
|
<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="event_reminder">Event reminder</string>
|
||||||
<string name="events_imported_successfully">Events imported successfully</string>
|
<string name="events_imported_successfully">Events imported successfully</string>
|
||||||
|
<string name="invalid_file_format">Invalid file format</string>
|
||||||
|
|
||||||
<!-- Day details -->
|
<!-- Day details -->
|
||||||
<string name="details">Dettagli</string>
|
<string name="details">Dettagli</string>
|
||||||
|
@@ -44,8 +44,10 @@
|
|||||||
|
|
||||||
<!-- Importing -->
|
<!-- Importing -->
|
||||||
<string name="import_events">Import events</string>
|
<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="event_reminder">Event reminder</string>
|
||||||
<string name="events_imported_successfully">Events imported successfully</string>
|
<string name="events_imported_successfully">Events imported successfully</string>
|
||||||
|
<string name="invalid_file_format">Invalid file format</string>
|
||||||
|
|
||||||
<!-- Day details -->
|
<!-- Day details -->
|
||||||
<string name="details">詳細</string>
|
<string name="details">詳細</string>
|
||||||
|
@@ -44,8 +44,10 @@
|
|||||||
|
|
||||||
<!-- Importing -->
|
<!-- Importing -->
|
||||||
<string name="import_events">Import events</string>
|
<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="event_reminder">Event reminder</string>
|
||||||
<string name="events_imported_successfully">Events imported successfully</string>
|
<string name="events_imported_successfully">Events imported successfully</string>
|
||||||
|
<string name="invalid_file_format">Invalid file format</string>
|
||||||
|
|
||||||
<!-- Day details -->
|
<!-- Day details -->
|
||||||
<string name="details">Detalhes</string>
|
<string name="details">Detalhes</string>
|
||||||
|
@@ -44,8 +44,10 @@
|
|||||||
|
|
||||||
<!-- Importing -->
|
<!-- Importing -->
|
||||||
<string name="import_events">Import events</string>
|
<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="event_reminder">Event reminder</string>
|
||||||
<string name="events_imported_successfully">Events imported successfully</string>
|
<string name="events_imported_successfully">Events imported successfully</string>
|
||||||
|
<string name="invalid_file_format">Invalid file format</string>
|
||||||
|
|
||||||
<!-- Day details -->
|
<!-- Day details -->
|
||||||
<string name="details">Подробности</string>
|
<string name="details">Подробности</string>
|
||||||
|
@@ -44,8 +44,10 @@
|
|||||||
|
|
||||||
<!-- Importing -->
|
<!-- Importing -->
|
||||||
<string name="import_events">Import events</string>
|
<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="event_reminder">Event reminder</string>
|
||||||
<string name="events_imported_successfully">Events imported successfully</string>
|
<string name="events_imported_successfully">Events imported successfully</string>
|
||||||
|
<string name="invalid_file_format">Invalid file format</string>
|
||||||
|
|
||||||
<!-- Day details -->
|
<!-- Day details -->
|
||||||
<string name="details">Detaljer</string>
|
<string name="details">Detaljer</string>
|
||||||
|
@@ -44,8 +44,10 @@
|
|||||||
|
|
||||||
<!-- Importing -->
|
<!-- Importing -->
|
||||||
<string name="import_events">Import events</string>
|
<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="event_reminder">Event reminder</string>
|
||||||
<string name="events_imported_successfully">Events imported successfully</string>
|
<string name="events_imported_successfully">Events imported successfully</string>
|
||||||
|
<string name="invalid_file_format">Invalid file format</string>
|
||||||
|
|
||||||
<!-- Day details -->
|
<!-- Day details -->
|
||||||
<string name="details">Details</string>
|
<string name="details">Details</string>
|
||||||
|
Reference in New Issue
Block a user