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.DateTime
import org.joda.time.DateTimeZone import org.joda.time.DateTimeZone
import java.io.FileOutputStream import java.io.FileOutputStream
import java.io.OutputStream
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
@@ -784,27 +785,29 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
handlePermission(PERMISSION_WRITE_STORAGE) { handlePermission(PERMISSION_WRITE_STORAGE) {
if (it) { if (it) {
ExportEventsDialog(this, config.lastExportPath, false) { file, eventTypes -> ExportEventsDialog(this, config.lastExportPath, false) { file, eventTypes ->
ensureBackgroundThread { getFileOutputStream(file.toFileDirItem(this), true) {
val events = eventsHelper.getEventsToExport(config.exportPastEvents, eventTypes) exportEventsTo(eventTypes, it)
if (events.isEmpty()) {
toast(R.string.no_entries_for_exporting)
} else {
getFileOutputStream(file.toFileDirItem(this), true) {
IcsExporter().exportEvents(this, it, events, true) {
toast(when (it) {
IcsExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
IcsExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed
else -> R.string.exporting_failed
})
}
}
}
} }
} }
} }
} }
} }
private fun exportEventsTo(eventTypes: ArrayList<Long>, outputStream: OutputStream?) {
val events = eventsHelper.getEventsToExport(eventTypes)
if (events.isEmpty()) {
toast(R.string.no_entries_for_exporting)
} else {
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
else -> R.string.exporting_failed
})
}
}
}
private fun launchSettings() { private fun launchSettings() {
startActivity(Intent(applicationContext, SettingsActivity::class.java)) 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.calendar.pro.extensions.eventsHelper
import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import kotlinx.android.synthetic.main.dialog_export_events.view.* import kotlinx.android.synthetic.main.dialog_export_events.view.*
import java.io.File import java.io.File
import java.util.* import java.util.*
@@ -68,12 +69,14 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val hid
return@setOnClickListener return@setOnClickListener
} }
config.lastExportPath = file.absolutePath.getParentPath() ensureBackgroundThread {
config.exportPastEvents = view.export_events_checkbox.isChecked config.lastExportPath = file.absolutePath.getParentPath()
config.exportPastEvents = view.export_events_checkbox.isChecked
val eventTypes = (view.export_events_types_list.adapter as FilterEventTypeAdapter).getSelectedItemsList() val eventTypes = (view.export_events_types_list.adapter as FilterEventTypeAdapter).getSelectedItemsList()
callback(file, eventTypes) callback(file, eventTypes)
dismiss() dismiss()
}
} }
else -> activity.toast(R.string.invalid_name) else -> activity.toast(R.string.invalid_name)
} }

View File

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