add a new source for storing contacts locally, without sharing with other apps
This commit is contained in:
parent
6400735463
commit
8e207414ef
|
@ -287,7 +287,7 @@ class EditContactActivity : ContactActivity() {
|
|||
contact_source.text = getPublicContactSource(contact!!.source)
|
||||
contact_source.setOnClickListener {
|
||||
showContactSourcePicker(contact!!.source) {
|
||||
contact!!.source = it
|
||||
contact!!.source = if (it == getString(R.string.phone_storage_hidden)) SMT_PRIVATE else it
|
||||
contact_source.text = getPublicContactSource(it)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.simplemobiletools.contacts.extensions
|
|||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import com.simplemobiletools.commons.R
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.getFilePublicUri
|
||||
|
@ -11,6 +10,7 @@ import com.simplemobiletools.commons.extensions.toast
|
|||
import com.simplemobiletools.commons.helpers.PERMISSION_CALL_PHONE
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.contacts.BuildConfig
|
||||
import com.simplemobiletools.contacts.R
|
||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.helpers.VcfExporter
|
||||
|
@ -56,7 +56,7 @@ fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (new
|
|||
sources.forEachIndexed { index, account ->
|
||||
var publicAccount = account
|
||||
if (account == config.localAccountName) {
|
||||
publicAccount = getString(com.simplemobiletools.contacts.R.string.phone_storage)
|
||||
publicAccount = getString(R.string.phone_storage)
|
||||
}
|
||||
|
||||
items.add(RadioItem(index, publicAccount))
|
||||
|
@ -73,7 +73,7 @@ fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (new
|
|||
}
|
||||
}
|
||||
|
||||
fun SimpleActivity.getPublicContactSource(source: String) = if (source == config.localAccountName) getString(com.simplemobiletools.contacts.R.string.phone_storage) else source
|
||||
fun SimpleActivity.getPublicContactSource(source: String) = if (source == config.localAccountName) getString(R.string.phone_storage) else source
|
||||
|
||||
fun BaseSimpleActivity.shareContacts(contacts: ArrayList<Contact>) {
|
||||
val file = getTempFile()
|
||||
|
|
|
@ -14,6 +14,7 @@ const val LOCAL_ACCOUNT_TYPE = "local_account_type"
|
|||
const val ON_CONTACT_CLICK = "on_contact_click"
|
||||
|
||||
const val CONTACT_ID = "contact_id"
|
||||
const val SMT_PRIVATE = "smt_private"
|
||||
|
||||
// contact photo changes
|
||||
const val PHOTO_ADDED = 1
|
||||
|
|
|
@ -227,7 +227,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
}
|
||||
|
||||
fun getContactSources(callback: (ArrayList<ContactSource>) -> Unit) {
|
||||
val sources = HashSet<ContactSource>()
|
||||
val sources = LinkedHashSet<ContactSource>()
|
||||
Thread {
|
||||
val uri = ContactsContract.RawContacts.CONTENT_URI
|
||||
val projection = arrayOf(ContactsContract.RawContacts.ACCOUNT_NAME, ContactsContract.RawContacts.ACCOUNT_TYPE)
|
||||
|
@ -247,6 +247,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
cursor?.close()
|
||||
}
|
||||
|
||||
sources.add(ContactSource(activity.getString(R.string.phone_storage_hidden), SMT_PRIVATE))
|
||||
callback(ArrayList(sources))
|
||||
}.start()
|
||||
}
|
||||
|
@ -451,7 +452,10 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
}
|
||||
|
||||
fun insertContact(contact: Contact): Boolean {
|
||||
return try {
|
||||
return if (contact.source == SMT_PRIVATE) {
|
||||
insertLocalContact(contact)
|
||||
} else {
|
||||
try {
|
||||
val operations = ArrayList<ContentProviderOperation>()
|
||||
ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI).apply {
|
||||
withValue(ContactsContract.RawContacts.ACCOUNT_NAME, contact.source)
|
||||
|
@ -553,6 +557,11 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun insertLocalContact(contact: Contact): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
private fun addFullSizePhoto(contactId: Long, fullSizePhotoData: ByteArray) {
|
||||
val baseUri = ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, contactId)
|
||||
|
|
Loading…
Reference in New Issue