diff --git a/app/build.gradle b/app/build.gradle index 948575b3..663494c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,7 +41,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.7.2' + implementation 'com.simplemobiletools:commons:3.7.3' implementation 'joda-time:joda-time:2.9.9' debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion" diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt index ccb8b040..f37a138a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt @@ -17,6 +17,7 @@ import com.simplemobiletools.contacts.BuildConfig import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.adapters.ViewPagerAdapter import com.simplemobiletools.contacts.dialogs.ChangeSortingDialog +import com.simplemobiletools.contacts.dialogs.ExportContactsDialog import com.simplemobiletools.contacts.dialogs.FilterContactSourcesDialog import com.simplemobiletools.contacts.dialogs.ImportContactsDialog import com.simplemobiletools.contacts.extensions.config @@ -279,7 +280,9 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { private fun exportContacts() { FilePickerDialog(this, pickFile = false, showFAB = true) { + ExportContactsDialog(this, it) { file, contactSources -> + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/ExportContactsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/ExportContactsDialog.kt new file mode 100644 index 00000000..1df75ded --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/ExportContactsDialog.kt @@ -0,0 +1,54 @@ +package com.simplemobiletools.contacts.dialogs + +import android.support.v7.app.AlertDialog +import android.view.ViewGroup +import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.contacts.R +import com.simplemobiletools.contacts.activities.SimpleActivity +import com.simplemobiletools.contacts.adapters.FilterContactSourcesAdapter +import com.simplemobiletools.contacts.extensions.config +import com.simplemobiletools.contacts.helpers.ContactsHelper +import kotlinx.android.synthetic.main.dialog_export_contacts.view.* +import java.io.File + +class ExportContactsDialog(val activity: SimpleActivity, val path: String, val callback: (file: File, contactSources: HashSet) -> Unit) { + + init { + val view = (activity.layoutInflater.inflate(R.layout.dialog_export_contacts, null) as ViewGroup).apply { + export_contacts_folder.text = activity.humanizePath(path) + export_contacts_filename.setText("contacts_${System.currentTimeMillis() / 1000}") + + ContactsHelper(activity).getContactSources { + activity.runOnUiThread { + export_contacts_list.adapter = FilterContactSourcesAdapter(activity, it, activity.config.displayContactSources) + } + } + } + + AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this, R.string.export_contacts) { + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val filename = view.export_contacts_filename.value + when { + filename.isEmpty() -> activity.toast(R.string.empty_name) + filename.isAValidFilename() -> { + val file = File(path, "$filename.vcf") + if (file.exists()) { + activity.toast(R.string.name_taken) + return@setOnClickListener + } + + val contactSources = (view.export_contacts_list.adapter as FilterContactSourcesAdapter).getSelectedItemsSet() + callback(file, contactSources) + dismiss() + } + else -> activity.toast(R.string.invalid_name) + } + } + } + } + } +} diff --git a/app/src/main/res/layout/dialog_export_contacts.xml b/app/src/main/res/layout/dialog_export_contacts.xml new file mode 100644 index 00000000..0f053e06 --- /dev/null +++ b/app/src/main/res/layout/dialog_export_contacts.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + +