tweaking event exporting a bit

This commit is contained in:
tibbi
2020-03-17 17:00:42 +01:00
parent dabbe0dff1
commit a9a2c22292
3 changed files with 28 additions and 22 deletions

View File

@ -48,6 +48,7 @@ import kotlinx.android.synthetic.main.activity_main.*
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import java.io.FileOutputStream
import java.io.OutputStream
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList
@ -784,13 +785,20 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
handlePermission(PERMISSION_WRITE_STORAGE) {
if (it) {
ExportEventsDialog(this, config.lastExportPath, false) { file, eventTypes ->
ensureBackgroundThread {
val events = eventsHelper.getEventsToExport(config.exportPastEvents, eventTypes)
getFileOutputStream(file.toFileDirItem(this), true) {
exportEventsTo(eventTypes, it)
}
}
}
}
}
private fun exportEventsTo(eventTypes: ArrayList<Long>, outputStream: OutputStream?) {
val events = eventsHelper.getEventsToExport(eventTypes)
if (events.isEmpty()) {
toast(R.string.no_entries_for_exporting)
} else {
getFileOutputStream(file.toFileDirItem(this), true) {
IcsExporter().exportEvents(this, it, events, true) {
IcsExporter().exportEvents(this, outputStream, events, true) {
toast(when (it) {
IcsExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
IcsExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed
@ -799,11 +807,6 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
}
}
}
}
}
}
}
private fun launchSettings() {
startActivity(Intent(applicationContext, SettingsActivity::class.java))

View File

@ -10,6 +10,7 @@ import com.simplemobiletools.calendar.pro.extensions.config
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import kotlinx.android.synthetic.main.dialog_export_events.view.*
import java.io.File
import java.util.*
@ -68,6 +69,7 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val hid
return@setOnClickListener
}
ensureBackgroundThread {
config.lastExportPath = file.absolutePath.getParentPath()
config.exportPastEvents = view.export_events_checkbox.isChecked
@ -75,6 +77,7 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val hid
callback(file, eventTypes)
dismiss()
}
}
else -> activity.toast(R.string.invalid_name)
}
}

View File

@ -401,10 +401,10 @@ class EventsHelper(val context: Context) {
return events
}
fun getEventsToExport(includePast: Boolean, eventTypes: ArrayList<Long>): ArrayList<Event> {
fun getEventsToExport(eventTypes: ArrayList<Long>): ArrayList<Event> {
val currTS = getNowSeconds()
var events = ArrayList<Event>()
if (includePast) {
if (config.exportPastEvents) {
events.addAll(eventsDB.getAllEventsWithTypes(eventTypes))
} else {
events.addAll(eventsDB.getOneTimeFutureEventsWithTypes(currTS, eventTypes))