mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
tweaking event exporting a bit
This commit is contained in:
@@ -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,13 +785,20 @@ 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun exportEventsTo(eventTypes: ArrayList<Long>, outputStream: OutputStream?) {
|
||||||
|
val events = eventsHelper.getEventsToExport(eventTypes)
|
||||||
if (events.isEmpty()) {
|
if (events.isEmpty()) {
|
||||||
toast(R.string.no_entries_for_exporting)
|
toast(R.string.no_entries_for_exporting)
|
||||||
} else {
|
} else {
|
||||||
getFileOutputStream(file.toFileDirItem(this), true) {
|
IcsExporter().exportEvents(this, outputStream, events, true) {
|
||||||
IcsExporter().exportEvents(this, it, events, true) {
|
|
||||||
toast(when (it) {
|
toast(when (it) {
|
||||||
IcsExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
|
IcsExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
|
||||||
IcsExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed
|
IcsExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed
|
||||||
@@ -799,11 +807,6 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun launchSettings() {
|
private fun launchSettings() {
|
||||||
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
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.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,6 +69,7 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val hid
|
|||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ensureBackgroundThread {
|
||||||
config.lastExportPath = file.absolutePath.getParentPath()
|
config.lastExportPath = file.absolutePath.getParentPath()
|
||||||
config.exportPastEvents = view.export_events_checkbox.isChecked
|
config.exportPastEvents = view.export_events_checkbox.isChecked
|
||||||
|
|
||||||
@@ -75,6 +77,7 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val hid
|
|||||||
callback(file, eventTypes)
|
callback(file, eventTypes)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else -> activity.toast(R.string.invalid_name)
|
else -> activity.toast(R.string.invalid_name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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))
|
||||||
|
Reference in New Issue
Block a user