From cb7e2810513a73edbca75136027162b800eaeb70 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 28 Dec 2018 15:51:26 +0100 Subject: [PATCH] add a new field to ContactSource, publicName --- .../pro/activities/EditContactActivity.kt | 12 +++++++++--- .../pro/activities/ViewContactActivity.kt | 7 ++++--- .../adapters/FilterContactSourcesAdapter.kt | 2 +- .../pro/dialogs/CreateNewGroupDialog.kt | 8 +++++--- .../pro/dialogs/ImportContactsDialog.kt | 9 +++++++-- .../contacts/pro/extensions/Context.kt | 8 +++++--- .../contacts/pro/helpers/ContactsHelper.kt | 18 ++++++++++++++---- .../contacts/pro/models/Contact.kt | 2 +- .../contacts/pro/models/ContactSource.kt | 2 +- 9 files changed, 47 insertions(+), 21 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt index f882d3c3..a25b59d1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt @@ -568,15 +568,19 @@ class EditContactActivity : ContactActivity() { } private fun setupContactSource() { - contact_source.text = getPublicContactSource(contact!!.source) originalContactSource = contact!!.source + getPublicContactSource(contact!!.source) { + contact_source.text = it + } } private fun setupNewContact() { supportActionBar?.title = resources.getString(R.string.new_contact) originalContactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE contact = getEmptyContact() - contact_source.text = getPublicContactSource(contact!!.source) + getPublicContactSource(contact!!.source) { + contact_source.text = it + } } private fun setupTypePickers() { @@ -831,7 +835,9 @@ class EditContactActivity : ContactActivity() { private fun showSelectContactSourceDialog() { showContactSourcePicker(contact!!.source) { 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 + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt index b1ef1744..84fe9fea 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt @@ -446,11 +446,12 @@ class ViewContactActivity : ContactActivity() { private fun setupContactSource() { if (showFields and SHOW_CONTACT_SOURCE_FIELD != 0) { - val contactSourceValue = getPublicContactSource(contact!!.source) - contact_source.text = contactSourceValue + getPublicContactSource(contact!!.source) { + contact_source.text = it + contact_source.copyOnLongClick(it) + } contact_source_image.beVisible() contact_source.beVisible() - contact_source.copyOnLongClick(contactSourceValue) } else { contact_source_image.beGone() contact_source.beGone() diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/FilterContactSourcesAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/FilterContactSourcesAdapter.kt index 9af1c7e7..c125072d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/FilterContactSourcesAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/FilterContactSourcesAdapter.kt @@ -62,7 +62,7 @@ class FilterContactSourcesAdapter(val activity: SimpleActivity, private val cont itemView.apply { filter_contact_source_checkbox.isChecked = isSelected 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) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/CreateNewGroupDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/CreateNewGroupDialog.kt index a0e0e9e8..2126c3c5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/CreateNewGroupDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/CreateNewGroupDialog.kt @@ -36,12 +36,14 @@ class CreateNewGroupDialog(val activity: BaseSimpleActivity, val callback: (newG val contactSources = ArrayList() 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 { - it.filter { it.type.contains("google", true) }.mapTo(contactSources, { ContactSource(it.name, it.type) }) - contactSources.add(ContactSource(activity.getString(R.string.phone_storage_hidden), SMT_PRIVATE)) + it.filter { it.type.contains("google", true) }.mapTo(contactSources) { ContactSource(it.name, it.type, it.name) } + val phoneSecret = activity.getString(R.string.phone_storage_hidden) + contactSources.add(ContactSource(phoneSecret, SMT_PRIVATE, phoneSecret)) val items = ArrayList() contactSources.forEachIndexed { index, contactSource -> diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ImportContactsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ImportContactsDialog.kt index 6ece8edb..131070d3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ImportContactsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ImportContactsDialog.kt @@ -20,11 +20,16 @@ class ImportContactsDialog(val activity: SimpleActivity, val path: String, priva init { val view = (activity.layoutInflater.inflate(R.layout.dialog_import_contacts, null) as ViewGroup).apply { targetContactSource = activity.config.lastUsedContactSource - import_contacts_title.text = activity.getPublicContactSource(targetContactSource) + activity.getPublicContactSource(targetContactSource) { + import_contacts_title.text = it + } + import_contacts_title.setOnClickListener { activity.showContactSourcePicker(targetContactSource) { 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 + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt index 7e1a768a..1b99392e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt @@ -193,12 +193,13 @@ fun Context.getPhotoThumbnailSize(): Int { fun Context.hasContactPermissions() = hasPermission(PERMISSION_READ_CONTACTS) && hasPermission(PERMISSION_WRITE_CONTACTS) -fun Context.getPublicContactSource(source: String): String { - return when (source) { +fun Context.getPublicContactSource(source: String, callback: (String) -> Unit) { + val newSource = when (source) { config.localAccountName -> getString(R.string.phone_storage) SMT_PRIVATE -> getString(R.string.phone_storage_hidden) else -> source } + callback(newSource) } fun Context.sendSMSToContacts(contacts: ArrayList) { @@ -289,7 +290,8 @@ fun Context.getContactPublicUri(contact: Contact): Uri { fun Context.getVisibleContactSources(): ArrayList { 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 sourceNames.removeAll(config.ignoredContactSources) return sourceNames diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt index b861565c..1382b6e9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt @@ -108,7 +108,12 @@ class ContactsHelper(val context: Context) { do { val name = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: "" 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) } while (cursor.moveToNext()) } @@ -831,7 +836,8 @@ class ContactsHelper(val context: Context) { private fun getContactSourcesSync(): ArrayList { 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) } @@ -844,7 +850,11 @@ class ContactsHelper(val context: Context) { val accounts = AccountManager.get(context).accounts accounts.forEach { 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) } } @@ -855,7 +865,7 @@ class ContactsHelper(val context: Context) { sources.addAll(contentResolverAccounts) if (sources.isEmpty() && context.config.localAccountName.isEmpty() && context.config.localAccountType.isEmpty()) { - sources.add(ContactSource("", "")) + sources.add(ContactSource("", "", "")) } return sources diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/Contact.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/Contact.kt index 7eb0d57e..c3851d83 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/Contact.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/Contact.kt @@ -119,7 +119,7 @@ data class Contact(var id: Int, var prefix: String, var firstName: String, var m fun getHashToCompare() = getStringToCompare().hashCode() - fun getFullCompany(): String { + private fun getFullCompany(): String { var fullOrganization = if (organization.company.isEmpty()) "" else "${organization.company}, " fullOrganization += organization.jobPosition return fullOrganization.trim().trimEnd(',') diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/ContactSource.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/ContactSource.kt index f1a4ba0b..4cd64377 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/ContactSource.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/ContactSource.kt @@ -1,3 +1,3 @@ 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)