Skip to content

Commit cb7e281

Browse files
committed
add a new field to ContactSource, publicName
1 parent dcc2490 commit cb7e281

File tree

9 files changed

+47
-21
lines changed

9 files changed

+47
-21
lines changed

app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,15 +568,19 @@ class EditContactActivity : ContactActivity() {
568568
}
569569

570570
private fun setupContactSource() {
571-
contact_source.text = getPublicContactSource(contact!!.source)
572571
originalContactSource = contact!!.source
572+
getPublicContactSource(contact!!.source) {
573+
contact_source.text = it
574+
}
573575
}
574576

575577
private fun setupNewContact() {
576578
supportActionBar?.title = resources.getString(R.string.new_contact)
577579
originalContactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
578580
contact = getEmptyContact()
579-
contact_source.text = getPublicContactSource(contact!!.source)
581+
getPublicContactSource(contact!!.source) {
582+
contact_source.text = it
583+
}
580584
}
581585

582586
private fun setupTypePickers() {
@@ -831,7 +835,9 @@ class EditContactActivity : ContactActivity() {
831835
private fun showSelectContactSourceDialog() {
832836
showContactSourcePicker(contact!!.source) {
833837
contact!!.source = if (it == getString(R.string.phone_storage_hidden)) SMT_PRIVATE else it
834-
contact_source.text = getPublicContactSource(it)
838+
getPublicContactSource(it) {
839+
contact_source.text = it
840+
}
835841
}
836842
}
837843

app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,12 @@ class ViewContactActivity : ContactActivity() {
446446

447447
private fun setupContactSource() {
448448
if (showFields and SHOW_CONTACT_SOURCE_FIELD != 0) {
449-
val contactSourceValue = getPublicContactSource(contact!!.source)
450-
contact_source.text = contactSourceValue
449+
getPublicContactSource(contact!!.source) {
450+
contact_source.text = it
451+
contact_source.copyOnLongClick(it)
452+
}
451453
contact_source_image.beVisible()
452454
contact_source.beVisible()
453-
contact_source.copyOnLongClick(contactSourceValue)
454455
} else {
455456
contact_source_image.beGone()
456457
contact_source.beGone()

app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/FilterContactSourcesAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class FilterContactSourcesAdapter(val activity: SimpleActivity, private val cont
6262
itemView.apply {
6363
filter_contact_source_checkbox.isChecked = isSelected
6464
filter_contact_source_checkbox.setColors(activity.config.textColor, activity.getAdjustedPrimaryColor(), activity.config.backgroundColor)
65-
filter_contact_source_checkbox.text = contactSource.name
65+
filter_contact_source_checkbox.text = contactSource.publicName
6666
filter_contact_source_holder.setOnClickListener { viewClicked(!isSelected, contactSource) }
6767
}
6868

app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/CreateNewGroupDialog.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ class CreateNewGroupDialog(val activity: BaseSimpleActivity, val callback: (newG
3636

3737
val contactSources = ArrayList<ContactSource>()
3838
if (activity.config.localAccountName.isNotEmpty()) {
39-
contactSources.add(ContactSource(activity.config.localAccountName, activity.config.localAccountType))
39+
val localAccountName = activity.config.localAccountName
40+
contactSources.add(ContactSource(localAccountName, activity.config.localAccountType, localAccountName))
4041
}
4142

4243
ContactsHelper(activity).getContactSources {
43-
it.filter { it.type.contains("google", true) }.mapTo(contactSources, { ContactSource(it.name, it.type) })
44-
contactSources.add(ContactSource(activity.getString(R.string.phone_storage_hidden), SMT_PRIVATE))
44+
it.filter { it.type.contains("google", true) }.mapTo(contactSources) { ContactSource(it.name, it.type, it.name) }
45+
val phoneSecret = activity.getString(R.string.phone_storage_hidden)
46+
contactSources.add(ContactSource(phoneSecret, SMT_PRIVATE, phoneSecret))
4547

4648
val items = ArrayList<RadioItem>()
4749
contactSources.forEachIndexed { index, contactSource ->

app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/ImportContactsDialog.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ class ImportContactsDialog(val activity: SimpleActivity, val path: String, priva
2020
init {
2121
val view = (activity.layoutInflater.inflate(R.layout.dialog_import_contacts, null) as ViewGroup).apply {
2222
targetContactSource = activity.config.lastUsedContactSource
23-
import_contacts_title.text = activity.getPublicContactSource(targetContactSource)
23+
activity.getPublicContactSource(targetContactSource) {
24+
import_contacts_title.text = it
25+
}
26+
2427
import_contacts_title.setOnClickListener {
2528
activity.showContactSourcePicker(targetContactSource) {
2629
targetContactSource = if (it == activity.getString(R.string.phone_storage_hidden)) SMT_PRIVATE else it
27-
import_contacts_title.text = activity.getPublicContactSource(it)
30+
activity.getPublicContactSource(it) {
31+
import_contacts_title.text = it
32+
}
2833
}
2934
}
3035
}

app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,13 @@ fun Context.getPhotoThumbnailSize(): Int {
193193

194194
fun Context.hasContactPermissions() = hasPermission(PERMISSION_READ_CONTACTS) && hasPermission(PERMISSION_WRITE_CONTACTS)
195195

196-
fun Context.getPublicContactSource(source: String): String {
197-
return when (source) {
196+
fun Context.getPublicContactSource(source: String, callback: (String) -> Unit) {
197+
val newSource = when (source) {
198198
config.localAccountName -> getString(R.string.phone_storage)
199199
SMT_PRIVATE -> getString(R.string.phone_storage_hidden)
200200
else -> source
201201
}
202+
callback(newSource)
202203
}
203204

204205
fun Context.sendSMSToContacts(contacts: ArrayList<Contact>) {
@@ -289,7 +290,8 @@ fun Context.getContactPublicUri(contact: Contact): Uri {
289290

290291
fun Context.getVisibleContactSources(): ArrayList<String> {
291292
val sources = ContactsHelper(this).getDeviceContactSources()
292-
sources.add(ContactSource(getString(R.string.phone_storage_hidden), SMT_PRIVATE))
293+
val phoneSecret = getString(R.string.phone_storage_hidden)
294+
sources.add(ContactSource(phoneSecret, SMT_PRIVATE, phoneSecret))
293295
val sourceNames = ArrayList(sources).map { if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.name }.toMutableList() as ArrayList<String>
294296
sourceNames.removeAll(config.ignoredContactSources)
295297
return sourceNames

app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ class ContactsHelper(val context: Context) {
108108
do {
109109
val name = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: ""
110110
val type = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_TYPE) ?: ""
111-
val source = ContactSource(name, type)
111+
var publicName = name
112+
if (type == TELEGRAM_PACKAGE) {
113+
publicName += " (${context.getString(R.string.telegram)})"
114+
}
115+
116+
val source = ContactSource(name, type, publicName)
112117
sources.add(source)
113118
} while (cursor.moveToNext())
114119
}
@@ -831,7 +836,8 @@ class ContactsHelper(val context: Context) {
831836

832837
private fun getContactSourcesSync(): ArrayList<ContactSource> {
833838
val sources = getDeviceContactSources()
834-
sources.add(ContactSource(context.getString(R.string.phone_storage_hidden), SMT_PRIVATE))
839+
val phoneSecret = context.getString(R.string.phone_storage_hidden)
840+
sources.add(ContactSource(phoneSecret, SMT_PRIVATE, phoneSecret))
835841
return ArrayList(sources)
836842
}
837843

@@ -844,7 +850,11 @@ class ContactsHelper(val context: Context) {
844850
val accounts = AccountManager.get(context).accounts
845851
accounts.forEach {
846852
if (ContentResolver.getIsSyncable(it, ContactsContract.AUTHORITY) == 1) {
847-
val contactSource = ContactSource(it.name, it.type)
853+
var publicName = it.name
854+
if (it.type == TELEGRAM_PACKAGE) {
855+
publicName += " (${context.getString(R.string.telegram)})"
856+
}
857+
val contactSource = ContactSource(it.name, it.type, publicName)
848858
sources.add(contactSource)
849859
}
850860
}
@@ -855,7 +865,7 @@ class ContactsHelper(val context: Context) {
855865
sources.addAll(contentResolverAccounts)
856866

857867
if (sources.isEmpty() && context.config.localAccountName.isEmpty() && context.config.localAccountType.isEmpty()) {
858-
sources.add(ContactSource("", ""))
868+
sources.add(ContactSource("", "", ""))
859869
}
860870

861871
return sources

app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/Contact.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ data class Contact(var id: Int, var prefix: String, var firstName: String, var m
119119

120120
fun getHashToCompare() = getStringToCompare().hashCode()
121121

122-
fun getFullCompany(): String {
122+
private fun getFullCompany(): String {
123123
var fullOrganization = if (organization.company.isEmpty()) "" else "${organization.company}, "
124124
fullOrganization += organization.jobPosition
125125
return fullOrganization.trim().trimEnd(',')
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package com.simplemobiletools.contacts.pro.models
22

3-
data class ContactSource(var name: String, var type: String)
3+
data class ContactSource(var name: String, var type: String, var publicName: String)

0 commit comments

Comments
 (0)