add Scoped Storage handling at contact exporting
This commit is contained in:
parent
1ee2e591d5
commit
ba75f5daa1
|
@ -49,13 +49,14 @@ import java.util.*
|
|||
|
||||
class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||
private val PICK_IMPORT_SOURCE_INTENT = 1
|
||||
private val PICK_EXPORT_FILE_INTENT = 1
|
||||
private val PICK_EXPORT_FILE_INTENT = 2
|
||||
|
||||
private var isSearchOpen = false
|
||||
private var searchMenuItem: MenuItem? = null
|
||||
private var werePermissionsHandled = false
|
||||
private var isFirstResume = true
|
||||
private var isGettingContacts = false
|
||||
private var ignoredExportContactSources = HashSet<String>()
|
||||
private var handledShowTabs = 0
|
||||
|
||||
private var storedTextColor = 0
|
||||
|
@ -226,6 +227,9 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
super.onActivityResult(requestCode, resultCode, resultData)
|
||||
if (requestCode == PICK_IMPORT_SOURCE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
|
||||
tryImportContactsFromFile(resultData.data!!)
|
||||
} else if (requestCode == PICK_EXPORT_FILE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
|
||||
val outputStream = contentResolver.openOutputStream(resultData.data!!)
|
||||
exportContactsTo(ignoredExportContactSources, outputStream)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -513,6 +517,20 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
}
|
||||
|
||||
private fun tryExportContacts() {
|
||||
if (isQPlus()) {
|
||||
ExportContactsDialog(this, config.lastExportPath, true) { file, ignoredContactSources ->
|
||||
config.lastExportPath = file.absolutePath.getParentPath()
|
||||
ignoredExportContactSources = ignoredContactSources
|
||||
|
||||
Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
|
||||
type = "text/x-vcard"
|
||||
putExtra(Intent.EXTRA_TITLE, file.name)
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
|
||||
startActivityForResult(this, PICK_EXPORT_FILE_INTENT)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
||||
if (it) {
|
||||
ExportContactsDialog(this, config.lastExportPath, false) { file, ignoredContactSources ->
|
||||
|
@ -524,6 +542,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun exportContactsTo(ignoredContactSources: HashSet<String>, outputStream: OutputStream?) {
|
||||
ContactsHelper(this).getContacts(true, ignoredContactSources) { contacts ->
|
||||
|
|
Loading…
Reference in New Issue