create the Export Contacts dialog

This commit is contained in:
tibbi 2018-01-15 16:01:24 +01:00
parent 0e1009b499
commit 04b345e0ac
4 changed files with 136 additions and 1 deletions

View File

@ -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"

View File

@ -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 ->
}
}
}

View File

@ -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<String>) -> 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)
}
}
}
}
}
}

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/export_contacts_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/export_contacts_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/export_contacts_folder_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/folder"
android:textSize="@dimen/smaller_text_size"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/export_contacts_folder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:layout_marginLeft="@dimen/activity_margin"
android:paddingBottom="@dimen/small_margin"
android:paddingRight="@dimen/small_margin"
android:paddingTop="@dimen/small_margin"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/export_contacts_filename_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/filename_without_vcf"
android:textSize="@dimen/smaller_text_size"/>
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/export_contacts_filename"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:layout_marginLeft="@dimen/activity_margin"
android:paddingRight="@dimen/small_margin"
android:paddingTop="@dimen/normal_margin"
android:textSize="@dimen/normal_text_size"/>
<ImageView
android:id="@+id/export_contacts_divider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginBottom="@dimen/medium_margin"
android:layout_marginTop="@dimen/medium_margin"
android:background="@color/divider_grey"
android:importantForAccessibility="no"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/export_contacts_pick_sources_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/include_contact_sources"
android:textSize="@dimen/smaller_text_size"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/export_contacts_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:overScrollMode="never"
android:paddingTop="@dimen/medium_margin"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
</LinearLayout>
</ScrollView>