diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt index 7f2e65fc6..3ce1819e2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt @@ -789,21 +789,19 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { } private fun exportEvents() { - FilePickerDialog(this, pickFile = false, showFAB = true) { - ExportEventsDialog(this, it, false) { exportPastEvents, file, eventTypes -> - ensureBackgroundThread { - val events = eventsHelper.getEventsToExport(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 - }) - } + ExportEventsDialog(this, config.lastExportPath, false) { exportPastEvents, file, eventTypes -> + ensureBackgroundThread { + val events = eventsHelper.getEventsToExport(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 + }) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ExportEventsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ExportEventsDialog.kt index d79b90b96..5469f5038 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ExportEventsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ExportEventsDialog.kt @@ -6,7 +6,9 @@ import androidx.appcompat.app.AlertDialog import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.activities.SimpleActivity import com.simplemobiletools.calendar.pro.adapters.FilterEventTypeAdapter +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 kotlinx.android.synthetic.main.dialog_export_events.view.* import java.io.File @@ -14,15 +16,26 @@ import java.util.* class ExportEventsDialog(val activity: SimpleActivity, val path: String, val hidePath: Boolean, val callback: (exportPastEvents: Boolean, file: File, eventTypes: ArrayList) -> Unit) { + private var realPath = if (path.isEmpty()) activity.internalStoragePath else path + val config = activity.config init { val view = (activity.layoutInflater.inflate(R.layout.dialog_export_events, null) as ViewGroup).apply { - export_events_folder.text = activity.humanizePath(path) + export_events_folder.text = activity.humanizePath(realPath) export_events_filename.setText("${activity.getString(R.string.events)}_${activity.getCurrentFormattedDateTime()}") + export_events_checkbox.isChecked = config.exportPastEvents if (hidePath) { export_events_folder_label.beGone() export_events_folder.beGone() + } else { + export_events_folder.setOnClickListener { + activity.hideKeyboard(export_events_filename) + FilePickerDialog(activity, realPath, false, showFAB = true) { + export_events_folder.text = activity.humanizePath(it) + realPath = it + } + } } activity.eventsHelper.getEventTypes(activity, false) { @@ -49,12 +62,15 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val hid when { filename.isEmpty() -> activity.toast(R.string.empty_name) filename.isAValidFilename() -> { - val file = File(path, "$filename.ics") + val file = File(realPath, "$filename.ics") if (file.exists()) { activity.toast(R.string.name_taken) return@setOnClickListener } + config.lastExportPath = file.absolutePath.getParentPath() + config.exportPastEvents = view.export_events_checkbox.isChecked + val eventTypes = (view.export_events_types_list.adapter as FilterEventTypeAdapter).getSelectedItemsList() callback(view.export_events_checkbox.isChecked, file, eventTypes) dismiss() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt index 43f0667ed..df066e846 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt @@ -174,4 +174,12 @@ class Config(context: Context) : BaseConfig(context) { var allowChangingTimeZones: Boolean get() = prefs.getBoolean(ALLOW_CHANGING_TIME_ZONES, false) set(allowChangingTimeZones) = prefs.edit().putBoolean(ALLOW_CHANGING_TIME_ZONES, allowChangingTimeZones).apply() + + var lastExportPath: String + get() = prefs.getString(LAST_EXPORT_PATH, "")!! + set(lastExportPath) = prefs.edit().putString(LAST_EXPORT_PATH, lastExportPath).apply() + + var exportPastEvents: Boolean + get() = prefs.getBoolean(EXPORT_PAST_EVENTS, false) + set(exportPastEvents) = prefs.edit().putBoolean(EXPORT_PAST_EVENTS, exportPastEvents).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt index eedbdb6cc..715435756 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt @@ -73,6 +73,8 @@ const val DEFAULT_START_TIME = "default_start_time" const val DEFAULT_DURATION = "default_duration" const val DEFAULT_EVENT_TYPE_ID = "default_event_type_id" const val ALLOW_CHANGING_TIME_ZONES = "allow_changing_time_zones" +const val LAST_EXPORT_PATH = "last_export_path" +const val EXPORT_PAST_EVENTS = "export_past_events" // repeat_rule for monthly and yearly repetition const val REPEAT_SAME_DAY = 1 // i.e. 25th every month, or 3rd june (if yearly repetition)