export only events belonging to the selected event types

This commit is contained in:
tibbi 2017-05-18 22:23:29 +02:00
parent 25e22a67e6
commit 71bf88bfa3
2 changed files with 13 additions and 7 deletions

View File

@ -27,6 +27,7 @@ import com.simplemobiletools.calendar.fragments.WeekFragment
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.models.EventType
import com.simplemobiletools.calendar.views.MyScrollView
import com.simplemobiletools.commons.dialogs.FilePickerDialog
@ -41,6 +42,7 @@ import kotlinx.android.synthetic.main.activity_main.*
import org.joda.time.DateTime
import java.io.FileOutputStream
import java.util.*
import kotlin.collections.ArrayList
class MainActivity : SimpleActivity(), NavigationListener {
private val PREFILLED_MONTHS = 73
@ -320,16 +322,18 @@ class MainActivity : SimpleActivity(), NavigationListener {
private fun exportEvents() {
FilePickerDialog(this, pickFile = false) {
val path = it
ExportEventsDialog(this, path) { exportPastEvents, file ->
ExportEventsDialog(this, path) { exportPastEvents, file, eventTypes ->
Thread({
val events = dbHelper.getEventsToExport(exportPastEvents)
val events = dbHelper.getEventsToExport(exportPastEvents).filter { eventTypes.contains(it.eventType.toString()) }
if (events.isEmpty()) {
runOnUiThread {
toast(R.string.no_events_for_exporting)
}
} else {
toast(R.string.exporting)
IcsExporter().exportEvents(this, file, events) {
runOnUiThread {
toast(R.string.exporting)
}
IcsExporter().exportEvents(this, file, events as ArrayList<Event>) {
runOnUiThread {
toast(when (it) {
IcsExporter.ExportResult.EXPORT_OK -> R.string.events_exported_successfully

View File

@ -11,7 +11,8 @@ import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.dialog_export_events.view.*
import java.io.File
class ExportEventsDialog(val activity: SimpleActivity, val path: String, val callback: (exportPastEvents: Boolean, file: File) -> Unit) : AlertDialog.Builder(activity) {
class ExportEventsDialog(val activity: SimpleActivity, val path: String, val callback: (exportPastEvents: Boolean, file: File, eventTypes: HashSet<String>) -> Unit)
: AlertDialog.Builder(activity) {
init {
val view = (activity.layoutInflater.inflate(R.layout.dialog_export_events, null) as ViewGroup).apply {
export_events_folder.text = activity.humanizePath(path)
@ -22,9 +23,9 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val cal
it.mapTo(eventTypes, { it.id.toString() })
activity.runOnUiThread {
export_events_types_list.adapter = FilterEventTypeAdapter(activity, it, eventTypes)
if (it.size > 1) {
export_events_pick_types.beVisible()
export_events_types_list.adapter = FilterEventTypeAdapter(activity, it, eventTypes)
val margin = activity.resources.getDimension(R.dimen.normal_margin).toInt()
(export_events_checkbox.layoutParams as LinearLayout.LayoutParams).leftMargin = margin
@ -49,7 +50,8 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val cal
return@setOnClickListener
}
callback(view.export_events_checkbox.isChecked, file)
val eventTypes = (view.export_events_types_list.adapter as FilterEventTypeAdapter).getSelectedItemsSet()
callback(view.export_events_checkbox.isChecked, file, eventTypes)
dismiss()
} else {
context.toast(R.string.invalid_name)