mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
adding a helper exportContactsTo function
This commit is contained in:
@ -44,6 +44,7 @@ import kotlinx.android.synthetic.main.fragment_contacts.*
|
|||||||
import kotlinx.android.synthetic.main.fragment_favorites.*
|
import kotlinx.android.synthetic.main.fragment_favorites.*
|
||||||
import kotlinx.android.synthetic.main.fragment_groups.*
|
import kotlinx.android.synthetic.main.fragment_groups.*
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
|
import java.io.OutputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), RefreshContactsListener {
|
class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||||
@ -514,20 +515,22 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
private fun tryExportContacts() {
|
private fun tryExportContacts() {
|
||||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
handlePermission(PERMISSION_WRITE_STORAGE) {
|
||||||
if (it) {
|
if (it) {
|
||||||
exportContacts()
|
ExportContactsDialog(this, config.lastExportPath, false) { file, ignoredContactSources ->
|
||||||
|
config.lastExportPath = file.absolutePath.getParentPath()
|
||||||
|
getFileOutputStream(file.toFileDirItem(this), true) {
|
||||||
|
exportContactsTo(ignoredContactSources, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun exportContacts() {
|
private fun exportContactsTo(ignoredContactSources: HashSet<String>, outputStream: OutputStream?) {
|
||||||
ExportContactsDialog(this, config.lastExportPath, false) { file, ignoredContactSources ->
|
|
||||||
config.lastExportPath = file.absolutePath.getParentPath()
|
|
||||||
ContactsHelper(this).getContacts(true, ignoredContactSources) { contacts ->
|
ContactsHelper(this).getContacts(true, ignoredContactSources) { contacts ->
|
||||||
if (contacts.isEmpty()) {
|
if (contacts.isEmpty()) {
|
||||||
toast(R.string.no_entries_for_exporting)
|
toast(R.string.no_entries_for_exporting)
|
||||||
} else {
|
} else {
|
||||||
getFileOutputStream(file.toFileDirItem(this), true) {
|
VcfExporter().exportContacts(this, outputStream, contacts, true) { result ->
|
||||||
VcfExporter().exportContacts(this, it, contacts, true) { result ->
|
|
||||||
toast(when (result) {
|
toast(when (result) {
|
||||||
VcfExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
|
VcfExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
|
||||||
VcfExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed
|
VcfExporter.ExportResult.EXPORT_PARTIAL -> R.string.exporting_some_entries_failed
|
||||||
@ -537,8 +540,6 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun launchAbout() {
|
private fun launchAbout() {
|
||||||
val licenses = LICENSE_JODA or LICENSE_GLIDE or LICENSE_GSON or LICENSE_INDICATOR_FAST_SCROLL
|
val licenses = LICENSE_JODA or LICENSE_GLIDE or LICENSE_GSON or LICENSE_INDICATOR_FAST_SCROLL
|
||||||
|
Reference in New Issue
Block a user