diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt index a79e6df7..a3db1421 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt @@ -520,19 +520,18 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { } private fun exportContacts() { - FilePickerDialog(this, pickFile = false, showFAB = true) { - ExportContactsDialog(this, it) { file, ignoredContactSources -> - ContactsHelper(this).getContacts(true, ignoredContactSources) { contacts -> - if (contacts.isEmpty()) { - toast(R.string.no_entries_for_exporting) - } else { - VcfExporter().exportContacts(this, file, contacts, true) { result -> - toast(when (result) { - VcfExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful - VcfExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed - else -> R.string.exporting_failed - }) - } + ExportContactsDialog(this, config.lastExportPath) { file, ignoredContactSources -> + config.lastExportPath = file.absolutePath.getParentPath() + ContactsHelper(this).getContacts(true, ignoredContactSources) { contacts -> + if (contacts.isEmpty()) { + toast(R.string.no_entries_for_exporting) + } else { + VcfExporter().exportContacts(this, file, contacts, true) { result -> + toast(when (result) { + VcfExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful + VcfExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed + else -> R.string.exporting_failed + }) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ExportContactsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ExportContactsDialog.kt index 7939b743..6adf8143 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ExportContactsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ExportContactsDialog.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.contacts.pro.dialogs import android.view.ViewGroup import androidx.appcompat.app.AlertDialog +import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.contacts.pro.R @@ -17,12 +18,21 @@ import java.util.* class ExportContactsDialog(val activity: SimpleActivity, val path: String, private val callback: (file: File, ignoredContactSources: HashSet) -> Unit) { private var contactSources = ArrayList() private var ignoreClicks = false + private var realPath = if (path.isEmpty()) activity.internalStoragePath else path init { val view = (activity.layoutInflater.inflate(R.layout.dialog_export_contacts, null) as ViewGroup).apply { - export_contacts_folder.text = activity.humanizePath(path) + export_contacts_folder.text = activity.humanizePath(realPath) export_contacts_filename.setText("contacts_${activity.getCurrentFormattedDateTime()}") + export_contacts_folder.setOnClickListener { + activity.hideKeyboard(export_contacts_filename) + FilePickerDialog(activity, realPath, false, showFAB = true) { + export_contacts_folder.text = activity.humanizePath(it) + realPath = it + } + } + ContactsHelper(activity).getContactSources { it.mapTo(contactSources) { it.copy() } activity.runOnUiThread { @@ -45,7 +55,7 @@ class ExportContactsDialog(val activity: SimpleActivity, val path: String, priva when { filename.isEmpty() -> activity.toast(R.string.empty_name) filename.isAValidFilename() -> { - val file = File(path, "$filename.vcf") + val file = File(realPath, "$filename.vcf") if (file.exists()) { activity.toast(R.string.name_taken) return@setOnClickListener diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Config.kt index 7905d19b..d3e75cf3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Config.kt @@ -60,6 +60,10 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(SHOW_DIALPAD_LETTERS, true) set(showDialpadLetters) = prefs.edit().putBoolean(SHOW_DIALPAD_LETTERS, showDialpadLetters).apply() + var lastExportPath: String + get() = prefs.getString(LAST_EXPORT_PATH, "")!! + set(lastExportPath) = prefs.edit().putString(LAST_EXPORT_PATH, lastExportPath).apply() + var speedDial: String get() = prefs.getString(SPEED_DIAL, "")!! set(speedDial) = prefs.edit().putString(SPEED_DIAL, speedDial).apply() diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt index 6bbad364..583a80db 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt @@ -22,6 +22,7 @@ const val SHOW_CALL_CONFIRMATION = "show_call_confirmation" const val SHOW_DIALPAD_BUTTON = "show_dialpad_button" const val SHOW_DIALPAD_LETTERS = "show_dialpad_letters" const val SPEED_DIAL = "speed_dial" +const val LAST_EXPORT_PATH = "last_export_path" const val CONTACT_ID = "contact_id" const val SMT_PRIVATE = "smt_private" // used at the contact source of local contacts hidden from other apps