create the selector selecting events for exporting
This commit is contained in:
parent
33d8da8919
commit
f753bdd613
|
@ -263,7 +263,8 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||
val path = it
|
||||
ExportEventsDialog(this, path) {
|
||||
Thread({
|
||||
val result = IcsExporter().exportEvents(this, path)
|
||||
val events = dbHelper.getEventsToExport(it)
|
||||
val result = IcsExporter().exportEvents(this, path, events)
|
||||
runOnUiThread {
|
||||
toast(when (result) {
|
||||
IcsExporter.ExportResult.EXPORT_OK -> R.string.events_exported_successfully
|
||||
|
|
|
@ -435,7 +435,23 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
return fillEvents(cursor)
|
||||
}
|
||||
|
||||
private fun getEventsCursor(selection: String, selectionArgs: Array<String>?): Cursor? {
|
||||
fun getEventsToExport(includePast: Boolean): ArrayList<Event> {
|
||||
val events = ArrayList<Event>()
|
||||
|
||||
val cursor = if (includePast) {
|
||||
getEventsCursor()
|
||||
} else {
|
||||
val endTime = (System.currentTimeMillis() / 1000).toString()
|
||||
val selection = "$COL_END_TS > ?"
|
||||
val selectionArgs = arrayOf(endTime)
|
||||
getEventsCursor(selection, selectionArgs)
|
||||
}
|
||||
|
||||
events.addAll(fillEvents(cursor))
|
||||
return events
|
||||
}
|
||||
|
||||
private fun getEventsCursor(selection: String = "", selectionArgs: Array<String>? = null): Cursor? {
|
||||
val builder = SQLiteQueryBuilder()
|
||||
builder.tables = "$MAIN_TABLE_NAME LEFT OUTER JOIN $META_TABLE_NAME ON $COL_EVENT_ID = $MAIN_TABLE_NAME.$COL_ID"
|
||||
val projection = allColumns
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.simplemobiletools.calendar.helpers
|
|||
import android.content.Context
|
||||
import com.simplemobiletools.calendar.extensions.writeLn
|
||||
import com.simplemobiletools.calendar.helpers.IcsExporter.ExportResult.*
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
import java.io.File
|
||||
|
||||
class IcsExporter {
|
||||
|
@ -13,7 +14,7 @@ class IcsExporter {
|
|||
var eventsExported = 0
|
||||
var eventsFailed = 0
|
||||
|
||||
fun exportEvents(context: Context, path: String): ExportResult {
|
||||
fun exportEvents(context: Context, path: String, events: ArrayList<Event>): ExportResult {
|
||||
File(path, "events_${System.currentTimeMillis() / 1000}.ics").bufferedWriter().use { out ->
|
||||
out.writeLn(BEGIN_CALENDAR)
|
||||
out.writeLn(END_CALENDAR)
|
||||
|
|
Loading…
Reference in New Issue