add a new field to ContactSource, publicName

This commit is contained in:
tibbi 2018-12-28 15:51:26 +01:00
parent dcc2490f86
commit cb7e281051
9 changed files with 47 additions and 21 deletions

View File

@ -568,15 +568,19 @@ class EditContactActivity : ContactActivity() {
} }
private fun setupContactSource() { private fun setupContactSource() {
contact_source.text = getPublicContactSource(contact!!.source)
originalContactSource = contact!!.source originalContactSource = contact!!.source
getPublicContactSource(contact!!.source) {
contact_source.text = it
}
} }
private fun setupNewContact() { private fun setupNewContact() {
supportActionBar?.title = resources.getString(R.string.new_contact) supportActionBar?.title = resources.getString(R.string.new_contact)
originalContactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE originalContactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
contact = getEmptyContact() contact = getEmptyContact()
contact_source.text = getPublicContactSource(contact!!.source) getPublicContactSource(contact!!.source) {
contact_source.text = it
}
} }
private fun setupTypePickers() { private fun setupTypePickers() {
@ -831,7 +835,9 @@ class EditContactActivity : ContactActivity() {
private fun showSelectContactSourceDialog() { private fun showSelectContactSourceDialog() {
showContactSourcePicker(contact!!.source) { showContactSourcePicker(contact!!.source) {
contact!!.source = if (it == getString(R.string.phone_storage_hidden)) SMT_PRIVATE else it contact!!.source = if (it == getString(R.string.phone_storage_hidden)) SMT_PRIVATE else it
contact_source.text = getPublicContactSource(it) getPublicContactSource(it) {
contact_source.text = it
}
} }
} }

View File

@ -446,11 +446,12 @@ class ViewContactActivity : ContactActivity() {
private fun setupContactSource() { private fun setupContactSource() {
if (showFields and SHOW_CONTACT_SOURCE_FIELD != 0) { if (showFields and SHOW_CONTACT_SOURCE_FIELD != 0) {
val contactSourceValue = getPublicContactSource(contact!!.source) getPublicContactSource(contact!!.source) {
contact_source.text = contactSourceValue contact_source.text = it
contact_source.copyOnLongClick(it)
}
contact_source_image.beVisible() contact_source_image.beVisible()
contact_source.beVisible() contact_source.beVisible()
contact_source.copyOnLongClick(contactSourceValue)
} else { } else {
contact_source_image.beGone() contact_source_image.beGone()
contact_source.beGone() contact_source.beGone()

View File

@ -62,7 +62,7 @@ class FilterContactSourcesAdapter(val activity: SimpleActivity, private val cont
itemView.apply { itemView.apply {
filter_contact_source_checkbox.isChecked = isSelected filter_contact_source_checkbox.isChecked = isSelected
filter_contact_source_checkbox.setColors(activity.config.textColor, activity.getAdjustedPrimaryColor(), activity.config.backgroundColor) filter_contact_source_checkbox.setColors(activity.config.textColor, activity.getAdjustedPrimaryColor(), activity.config.backgroundColor)
filter_contact_source_checkbox.text = contactSource.name filter_contact_source_checkbox.text = contactSource.publicName
filter_contact_source_holder.setOnClickListener { viewClicked(!isSelected, contactSource) } filter_contact_source_holder.setOnClickListener { viewClicked(!isSelected, contactSource) }
} }

View File

@ -36,12 +36,14 @@ class CreateNewGroupDialog(val activity: BaseSimpleActivity, val callback: (newG
val contactSources = ArrayList<ContactSource>() val contactSources = ArrayList<ContactSource>()
if (activity.config.localAccountName.isNotEmpty()) { if (activity.config.localAccountName.isNotEmpty()) {
contactSources.add(ContactSource(activity.config.localAccountName, activity.config.localAccountType)) val localAccountName = activity.config.localAccountName
contactSources.add(ContactSource(localAccountName, activity.config.localAccountType, localAccountName))
} }
ContactsHelper(activity).getContactSources { ContactsHelper(activity).getContactSources {
it.filter { it.type.contains("google", true) }.mapTo(contactSources, { ContactSource(it.name, it.type) }) it.filter { it.type.contains("google", true) }.mapTo(contactSources) { ContactSource(it.name, it.type, it.name) }
contactSources.add(ContactSource(activity.getString(R.string.phone_storage_hidden), SMT_PRIVATE)) val phoneSecret = activity.getString(R.string.phone_storage_hidden)
contactSources.add(ContactSource(phoneSecret, SMT_PRIVATE, phoneSecret))
val items = ArrayList<RadioItem>() val items = ArrayList<RadioItem>()
contactSources.forEachIndexed { index, contactSource -> contactSources.forEachIndexed { index, contactSource ->

View File

@ -20,11 +20,16 @@ class ImportContactsDialog(val activity: SimpleActivity, val path: String, priva
init { init {
val view = (activity.layoutInflater.inflate(R.layout.dialog_import_contacts, null) as ViewGroup).apply { val view = (activity.layoutInflater.inflate(R.layout.dialog_import_contacts, null) as ViewGroup).apply {
targetContactSource = activity.config.lastUsedContactSource targetContactSource = activity.config.lastUsedContactSource
import_contacts_title.text = activity.getPublicContactSource(targetContactSource) activity.getPublicContactSource(targetContactSource) {
import_contacts_title.text = it
}
import_contacts_title.setOnClickListener { import_contacts_title.setOnClickListener {
activity.showContactSourcePicker(targetContactSource) { activity.showContactSourcePicker(targetContactSource) {
targetContactSource = if (it == activity.getString(R.string.phone_storage_hidden)) SMT_PRIVATE else it targetContactSource = if (it == activity.getString(R.string.phone_storage_hidden)) SMT_PRIVATE else it
import_contacts_title.text = activity.getPublicContactSource(it) activity.getPublicContactSource(it) {
import_contacts_title.text = it
}
} }
} }
} }

View File

@ -193,12 +193,13 @@ fun Context.getPhotoThumbnailSize(): Int {
fun Context.hasContactPermissions() = hasPermission(PERMISSION_READ_CONTACTS) && hasPermission(PERMISSION_WRITE_CONTACTS) fun Context.hasContactPermissions() = hasPermission(PERMISSION_READ_CONTACTS) && hasPermission(PERMISSION_WRITE_CONTACTS)
fun Context.getPublicContactSource(source: String): String { fun Context.getPublicContactSource(source: String, callback: (String) -> Unit) {
return when (source) { val newSource = when (source) {
config.localAccountName -> getString(R.string.phone_storage) config.localAccountName -> getString(R.string.phone_storage)
SMT_PRIVATE -> getString(R.string.phone_storage_hidden) SMT_PRIVATE -> getString(R.string.phone_storage_hidden)
else -> source else -> source
} }
callback(newSource)
} }
fun Context.sendSMSToContacts(contacts: ArrayList<Contact>) { fun Context.sendSMSToContacts(contacts: ArrayList<Contact>) {
@ -289,7 +290,8 @@ fun Context.getContactPublicUri(contact: Contact): Uri {
fun Context.getVisibleContactSources(): ArrayList<String> { fun Context.getVisibleContactSources(): ArrayList<String> {
val sources = ContactsHelper(this).getDeviceContactSources() val sources = ContactsHelper(this).getDeviceContactSources()
sources.add(ContactSource(getString(R.string.phone_storage_hidden), SMT_PRIVATE)) val phoneSecret = getString(R.string.phone_storage_hidden)
sources.add(ContactSource(phoneSecret, SMT_PRIVATE, phoneSecret))
val sourceNames = ArrayList(sources).map { if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.name }.toMutableList() as ArrayList<String> val sourceNames = ArrayList(sources).map { if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.name }.toMutableList() as ArrayList<String>
sourceNames.removeAll(config.ignoredContactSources) sourceNames.removeAll(config.ignoredContactSources)
return sourceNames return sourceNames

View File

@ -108,7 +108,12 @@ class ContactsHelper(val context: Context) {
do { do {
val name = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: "" val name = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: ""
val type = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_TYPE) ?: "" val type = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_TYPE) ?: ""
val source = ContactSource(name, type) var publicName = name
if (type == TELEGRAM_PACKAGE) {
publicName += " (${context.getString(R.string.telegram)})"
}
val source = ContactSource(name, type, publicName)
sources.add(source) sources.add(source)
} while (cursor.moveToNext()) } while (cursor.moveToNext())
} }
@ -831,7 +836,8 @@ class ContactsHelper(val context: Context) {
private fun getContactSourcesSync(): ArrayList<ContactSource> { private fun getContactSourcesSync(): ArrayList<ContactSource> {
val sources = getDeviceContactSources() val sources = getDeviceContactSources()
sources.add(ContactSource(context.getString(R.string.phone_storage_hidden), SMT_PRIVATE)) val phoneSecret = context.getString(R.string.phone_storage_hidden)
sources.add(ContactSource(phoneSecret, SMT_PRIVATE, phoneSecret))
return ArrayList(sources) return ArrayList(sources)
} }
@ -844,7 +850,11 @@ class ContactsHelper(val context: Context) {
val accounts = AccountManager.get(context).accounts val accounts = AccountManager.get(context).accounts
accounts.forEach { accounts.forEach {
if (ContentResolver.getIsSyncable(it, ContactsContract.AUTHORITY) == 1) { if (ContentResolver.getIsSyncable(it, ContactsContract.AUTHORITY) == 1) {
val contactSource = ContactSource(it.name, it.type) var publicName = it.name
if (it.type == TELEGRAM_PACKAGE) {
publicName += " (${context.getString(R.string.telegram)})"
}
val contactSource = ContactSource(it.name, it.type, publicName)
sources.add(contactSource) sources.add(contactSource)
} }
} }
@ -855,7 +865,7 @@ class ContactsHelper(val context: Context) {
sources.addAll(contentResolverAccounts) sources.addAll(contentResolverAccounts)
if (sources.isEmpty() && context.config.localAccountName.isEmpty() && context.config.localAccountType.isEmpty()) { if (sources.isEmpty() && context.config.localAccountName.isEmpty() && context.config.localAccountType.isEmpty()) {
sources.add(ContactSource("", "")) sources.add(ContactSource("", "", ""))
} }
return sources return sources

View File

@ -119,7 +119,7 @@ data class Contact(var id: Int, var prefix: String, var firstName: String, var m
fun getHashToCompare() = getStringToCompare().hashCode() fun getHashToCompare() = getStringToCompare().hashCode()
fun getFullCompany(): String { private fun getFullCompany(): String {
var fullOrganization = if (organization.company.isEmpty()) "" else "${organization.company}, " var fullOrganization = if (organization.company.isEmpty()) "" else "${organization.company}, "
fullOrganization += organization.jobPosition fullOrganization += organization.jobPosition
return fullOrganization.trim().trimEnd(',') return fullOrganization.trim().trimEnd(',')

View File

@ -1,3 +1,3 @@
package com.simplemobiletools.contacts.pro.models package com.simplemobiletools.contacts.pro.models
data class ContactSource(var name: String, var type: String) data class ContactSource(var name: String, var type: String, var publicName: String)