remember last used data used at exporting events

This commit is contained in:
tibbi 2020-03-17 16:37:42 +01:00
parent 233fff3850
commit a7d8c88174
4 changed files with 41 additions and 17 deletions

View File

@ -789,21 +789,19 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
} }
private fun exportEvents() { private fun exportEvents() {
FilePickerDialog(this, pickFile = false, showFAB = true) { ExportEventsDialog(this, config.lastExportPath, false) { exportPastEvents, file, eventTypes ->
ExportEventsDialog(this, it, false) { exportPastEvents, file, eventTypes -> ensureBackgroundThread {
ensureBackgroundThread { val events = eventsHelper.getEventsToExport(exportPastEvents, eventTypes)
val events = eventsHelper.getEventsToExport(exportPastEvents, 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) {
getFileOutputStream(file.toFileDirItem(this), true) { IcsExporter().exportEvents(this, it, 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 else -> R.string.exporting_failed
else -> R.string.exporting_failed })
})
}
} }
} }
} }

View File

@ -6,7 +6,9 @@ import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.SimpleActivity import com.simplemobiletools.calendar.pro.activities.SimpleActivity
import com.simplemobiletools.calendar.pro.adapters.FilterEventTypeAdapter import com.simplemobiletools.calendar.pro.adapters.FilterEventTypeAdapter
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.extensions.* import com.simplemobiletools.commons.extensions.*
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
@ -14,15 +16,26 @@ import java.util.*
class ExportEventsDialog(val activity: SimpleActivity, val path: String, val hidePath: Boolean, class ExportEventsDialog(val activity: SimpleActivity, val path: String, val hidePath: Boolean,
val callback: (exportPastEvents: Boolean, file: File, eventTypes: ArrayList<Long>) -> Unit) { val callback: (exportPastEvents: Boolean, file: File, eventTypes: ArrayList<Long>) -> Unit) {
private var realPath = if (path.isEmpty()) activity.internalStoragePath else path
val config = activity.config
init { init {
val view = (activity.layoutInflater.inflate(R.layout.dialog_export_events, null) as ViewGroup).apply { 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_filename.setText("${activity.getString(R.string.events)}_${activity.getCurrentFormattedDateTime()}")
export_events_checkbox.isChecked = config.exportPastEvents
if (hidePath) { if (hidePath) {
export_events_folder_label.beGone() export_events_folder_label.beGone()
export_events_folder.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) { activity.eventsHelper.getEventTypes(activity, false) {
@ -49,12 +62,15 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val hid
when { when {
filename.isEmpty() -> activity.toast(R.string.empty_name) filename.isEmpty() -> activity.toast(R.string.empty_name)
filename.isAValidFilename() -> { filename.isAValidFilename() -> {
val file = File(path, "$filename.ics") val file = File(realPath, "$filename.ics")
if (file.exists()) { if (file.exists()) {
activity.toast(R.string.name_taken) activity.toast(R.string.name_taken)
return@setOnClickListener 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() val eventTypes = (view.export_events_types_list.adapter as FilterEventTypeAdapter).getSelectedItemsList()
callback(view.export_events_checkbox.isChecked, file, eventTypes) callback(view.export_events_checkbox.isChecked, file, eventTypes)
dismiss() dismiss()

View File

@ -174,4 +174,12 @@ class Config(context: Context) : BaseConfig(context) {
var allowChangingTimeZones: Boolean var allowChangingTimeZones: Boolean
get() = prefs.getBoolean(ALLOW_CHANGING_TIME_ZONES, false) get() = prefs.getBoolean(ALLOW_CHANGING_TIME_ZONES, false)
set(allowChangingTimeZones) = prefs.edit().putBoolean(ALLOW_CHANGING_TIME_ZONES, allowChangingTimeZones).apply() 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()
} }

View File

@ -73,6 +73,8 @@ const val DEFAULT_START_TIME = "default_start_time"
const val DEFAULT_DURATION = "default_duration" const val DEFAULT_DURATION = "default_duration"
const val DEFAULT_EVENT_TYPE_ID = "default_event_type_id" const val DEFAULT_EVENT_TYPE_ID = "default_event_type_id"
const val ALLOW_CHANGING_TIME_ZONES = "allow_changing_time_zones" 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 // repeat_rule for monthly and yearly repetition
const val REPEAT_SAME_DAY = 1 // i.e. 25th every month, or 3rd june (if yearly repetition) const val REPEAT_SAME_DAY = 1 // i.e. 25th every month, or 3rd june (if yearly repetition)