allow sharing multiple handpicked contacts at once

This commit is contained in:
tibbi 2018-01-15 23:49:03 +01:00
parent dc308a94dc
commit 13f5fbc859
4 changed files with 24 additions and 4 deletions

View File

@ -312,7 +312,7 @@ class ContactActivity : SimpleActivity() {
} }
private fun shareContact() { private fun shareContact() {
shareContact(contact!!) shareContacts(arrayListOf(contact!!))
} }
private fun showPhotoPlaceholder() { private fun showPhotoPlaceholder() {

View File

@ -19,6 +19,7 @@ import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.activities.SimpleActivity import com.simplemobiletools.contacts.activities.SimpleActivity
import com.simplemobiletools.contacts.extensions.config import com.simplemobiletools.contacts.extensions.config
import com.simplemobiletools.contacts.extensions.openContact import com.simplemobiletools.contacts.extensions.openContact
import com.simplemobiletools.contacts.extensions.shareContacts
import com.simplemobiletools.contacts.helpers.ContactsHelper import com.simplemobiletools.contacts.helpers.ContactsHelper
import com.simplemobiletools.contacts.interfaces.RefreshContactsListener import com.simplemobiletools.contacts.interfaces.RefreshContactsListener
import com.simplemobiletools.contacts.models.Contact import com.simplemobiletools.contacts.models.Contact
@ -62,9 +63,10 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
when (id) { when (id) {
R.id.cab_edit -> editContact() R.id.cab_edit -> editContact()
R.id.cab_select_all -> selectAll() R.id.cab_select_all -> selectAll()
R.id.cab_delete -> askConfirmDelete()
R.id.cab_add_to_favorites -> addToFavorites() R.id.cab_add_to_favorites -> addToFavorites()
R.id.cab_share -> shareContacts()
R.id.cab_remove -> removeFavorites() R.id.cab_remove -> removeFavorites()
R.id.cab_delete -> askConfirmDelete()
} }
} }
@ -161,6 +163,19 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
finishActMode() finishActMode()
} }
private fun shareContacts() {
if (selectedPositions.isEmpty()) {
return
}
val contacts = ArrayList<Contact>()
selectedPositions.forEach {
contacts.add(contactItems[it])
}
activity.shareContacts(contacts)
}
override fun onViewRecycled(holder: ViewHolder?) { override fun onViewRecycled(holder: ViewHolder?) {
super.onViewRecycled(holder) super.onViewRecycled(holder)
if (!activity.isActivityDestroyed()) { if (!activity.isActivityDestroyed()) {

View File

@ -68,14 +68,14 @@ fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (new
} }
} }
fun BaseSimpleActivity.shareContact(contact: Contact) { fun BaseSimpleActivity.shareContacts(contacts: ArrayList<Contact>) {
val file = getTempFile() val file = getTempFile()
if (file == null) { if (file == null) {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
return return
} }
VcfExporter().exportContacts(this, file, arrayListOf(contact)) { VcfExporter().exportContacts(this, file, contacts) {
if (it == VcfExporter.ExportResult.EXPORT_OK) { if (it == VcfExporter.ExportResult.EXPORT_OK) {
val uri = getFilePublicUri(file, BuildConfig.APPLICATION_ID) val uri = getFilePublicUri(file, BuildConfig.APPLICATION_ID)
shareUri(uri, BuildConfig.APPLICATION_ID) shareUri(uri, BuildConfig.APPLICATION_ID)

View File

@ -16,6 +16,11 @@
android:icon="@drawable/ic_star_on" android:icon="@drawable/ic_star_on"
android:title="@string/add_to_favorites" android:title="@string/add_to_favorites"
app:showAsAction="ifRoom"/> app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_share"
android:icon="@drawable/ic_share"
android:title="@string/share"
app:showAsAction="ifRoom"/>
<item <item
android:id="@+id/cab_delete" android:id="@+id/cab_delete"
android:icon="@drawable/ic_delete" android:icon="@drawable/ic_delete"