mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-01-05 12:58:17 +01:00
tweaking event exporting a bit
This commit is contained in:
parent
dabbe0dff1
commit
a9a2c22292
@ -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,27 +785,29 @@ 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)
|
||||
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
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
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() {
|
||||
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||
}
|
||||
|
@ -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,12 +69,14 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val hid
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
config.lastExportPath = file.absolutePath.getParentPath()
|
||||
config.exportPastEvents = view.export_events_checkbox.isChecked
|
||||
ensureBackgroundThread {
|
||||
config.lastExportPath = file.absolutePath.getParentPath()
|
||||
config.exportPastEvents = view.export_events_checkbox.isChecked
|
||||
|
||||
val eventTypes = (view.export_events_types_list.adapter as FilterEventTypeAdapter).getSelectedItemsList()
|
||||
callback(file, eventTypes)
|
||||
dismiss()
|
||||
val eventTypes = (view.export_events_types_list.adapter as FilterEventTypeAdapter).getSelectedItemsList()
|
||||
callback(file, eventTypes)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
else -> activity.toast(R.string.invalid_name)
|
||||
}
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user