diff --git a/app/src/main/kotlin/org/fossify/contacts/activities/MainActivity.kt b/app/src/main/kotlin/org/fossify/contacts/activities/MainActivity.kt index 3df3000bd..b97ac9a3a 100644 --- a/app/src/main/kotlin/org/fossify/contacts/activities/MainActivity.kt +++ b/app/src/main/kotlin/org/fossify/contacts/activities/MainActivity.kt @@ -43,6 +43,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { private var storedShowContactThumbnails = false private var storedShowPhoneNumbers = false + private var storedShowCompanyInList = false + private var storedShowGroupsInList = false private var storedStartNameWithSurname = false private var storedFontSize = 0 private var storedShowTabs = 0 @@ -95,6 +97,12 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { return } + if (storedShowCompanyInList != config.showCompanyInList || storedShowGroupsInList != config.showGroupsInList) { + finish() + startActivity(intent) + return + } + val configShowContactThumbnails = config.showContactThumbnails if (storedShowContactThumbnails != configShowContactThumbnails) { getAllFragments().forEach { @@ -242,6 +250,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { config.apply { storedShowContactThumbnails = showContactThumbnails storedShowPhoneNumbers = showPhoneNumbers + storedShowCompanyInList = showCompanyInList + storedShowGroupsInList = showGroupsInList storedStartNameWithSurname = startNameWithSurname storedShowTabs = showTabs storedFontSize = fontSize diff --git a/app/src/main/kotlin/org/fossify/contacts/activities/SettingsActivity.kt b/app/src/main/kotlin/org/fossify/contacts/activities/SettingsActivity.kt index e937a355d..abbc76604 100644 --- a/app/src/main/kotlin/org/fossify/contacts/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/org/fossify/contacts/activities/SettingsActivity.kt @@ -52,6 +52,8 @@ class SettingsActivity : SimpleActivity() { setupShowContactThumbnails() setupShowPhoneNumbers() setupEnableNumberFormatting() + setupShowCompanyInList() + setupShowGroupsInList() setupShowContactsWithNumbers() setupStartNameWithSurname() setupMergeDuplicateContacts() @@ -181,6 +183,22 @@ class SettingsActivity : SimpleActivity() { } } + private fun setupShowCompanyInList() { + binding.settingsShowCompanyInList.isChecked = config.showCompanyInList + binding.settingsShowCompanyInListHolder.setOnClickListener { + binding.settingsShowCompanyInList.toggle() + config.showCompanyInList = binding.settingsShowCompanyInList.isChecked + } + } + + private fun setupShowGroupsInList() { + binding.settingsShowGroupsInList.isChecked = config.showGroupsInList + binding.settingsShowGroupsInListHolder.setOnClickListener { + binding.settingsShowGroupsInList.toggle() + config.showGroupsInList = binding.settingsShowGroupsInList.isChecked + } + } + private fun setupShowContactsWithNumbers() { binding.settingsShowOnlyContactsWithNumbers.isChecked = config.showOnlyContactsWithNumbers binding.settingsShowOnlyContactsWithNumbersHolder.setOnClickListener { diff --git a/app/src/main/kotlin/org/fossify/contacts/adapters/ContactsAdapter.kt b/app/src/main/kotlin/org/fossify/contacts/adapters/ContactsAdapter.kt index 162dd040c..d42287437 100644 --- a/app/src/main/kotlin/org/fossify/contacts/adapters/ContactsAdapter.kt +++ b/app/src/main/kotlin/org/fossify/contacts/adapters/ContactsAdapter.kt @@ -71,6 +71,8 @@ class ContactsAdapter( var startNameWithSurname = config.startNameWithSurname var showContactThumbnails = config.showContactThumbnails var showPhoneNumbers = config.showPhoneNumbers + var showCompanyInList = config.showCompanyInList + var showGroupsInList = config.showGroupsInList var fontSize = activity.getTextSize() var onDragEndListener: (() -> Unit)? = null @@ -156,7 +158,11 @@ class ContactsAdapter( } else -> { - if (showPhoneNumbers) org.fossify.commons.R.layout.item_contact_with_number else org.fossify.commons.R.layout.item_contact_without_number + when { + showCompanyInList || showGroupsInList -> R.layout.item_contact_with_details + showPhoneNumbers -> org.fossify.commons.R.layout.item_contact_with_number + else -> org.fossify.commons.R.layout.item_contact_without_number + } } } @@ -403,7 +409,12 @@ class ContactsAdapter( setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize) } - if (findViewById(org.fossify.commons.R.id.item_contact_number) != null) { + val numberView = findViewById(org.fossify.commons.R.id.item_contact_number) + if (numberView != null && !showPhoneNumbers) { + // only possible with item_contact_with_details, which always contains the number view + numberView.beGone() + } else if (numberView != null) { + numberView.beVisible() val phoneNumberToUse = if (textToHighlight.isEmpty()) { contact.phoneNumbers.firstOrNull() } else { @@ -415,13 +426,21 @@ class ContactsAdapter( } else { phoneNumberToUse?.value ?: "" } - findViewById(org.fossify.commons.R.id.item_contact_number).apply { + numberView.apply { text = if (textToHighlight.isEmpty()) numberText else numberText.highlightTextPart(textToHighlight, properPrimaryColor, false, true) setTextColor(textColor) setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize) } } + findViewById(R.id.item_contact_details)?.apply { + val details = getContactDetails(contact) + beVisibleIf(details.isNotEmpty()) + text = if (textToHighlight.isEmpty()) details else details.highlightTextPart(textToHighlight, properPrimaryColor) + setTextColor(textColor) + setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize) + } + findViewById(org.fossify.commons.R.id.item_contact_image).apply { beVisibleIf(showContactThumbnails) if (profileIconClick != null && viewType != VIEW_TYPE_GRID) { @@ -483,6 +502,31 @@ class ContactsAdapter( } } + // "Company · Group A, Group B", depending on the enabled settings + private fun getContactDetails(contact: Contact): String { + val parts = ArrayList(2) + if (showCompanyInList) { + val company = contact.organization.company.trim() + if (company.isNotEmpty()) { + parts.add(company) + } + } + + if (showGroupsInList) { + val groupTitles = contact.groups + .map { it.title.trim() } + .filter { it.isNotEmpty() } + .distinct() + .sortedWith(String.CASE_INSENSITIVE_ORDER) + + if (groupTitles.isNotEmpty()) { + parts.add(groupTitles.joinToString(", ")) + } + } + + return parts.joinToString(" · ") + } + override fun onChange(position: Int) = contactItems.getOrNull(position)?.getBubbleText() ?: "" override fun onRowMoved(fromPosition: Int, toPosition: Int) { diff --git a/app/src/main/kotlin/org/fossify/contacts/fragments/MyViewPagerFragment.kt b/app/src/main/kotlin/org/fossify/contacts/fragments/MyViewPagerFragment.kt index bef154ebc..350aed9cc 100644 --- a/app/src/main/kotlin/org/fossify/contacts/fragments/MyViewPagerFragment.kt +++ b/app/src/main/kotlin/org/fossify/contacts/fragments/MyViewPagerFragment.kt @@ -324,6 +324,7 @@ abstract class MyViewPagerFragment(c getProperText(it.notes, shouldNormalize).contains(fixedText, true) || getProperText(it.organization.company, shouldNormalize).contains(fixedText, true) || getProperText(it.organization.jobPosition, shouldNormalize).contains(fixedText, true) || + it.groups.any { group -> getProperText(group.title, shouldNormalize).contains(fixedText, true) } || it.websites.any { it.contains(fixedText, true) } } as ArrayList diff --git a/app/src/main/kotlin/org/fossify/contacts/helpers/Config.kt b/app/src/main/kotlin/org/fossify/contacts/helpers/Config.kt index 5be4a497f..8539f1a68 100644 --- a/app/src/main/kotlin/org/fossify/contacts/helpers/Config.kt +++ b/app/src/main/kotlin/org/fossify/contacts/helpers/Config.kt @@ -18,4 +18,11 @@ class Config(context: Context) : BaseConfig(context) { set(autoBackupContactSources) = prefs.edit().remove(AUTO_BACKUP_CONTACT_SOURCES).putStringSet(AUTO_BACKUP_CONTACT_SOURCES, autoBackupContactSources) .apply() + var showCompanyInList: Boolean + get() = prefs.getBoolean(SHOW_COMPANY_IN_LIST, false) + set(showCompanyInList) = prefs.edit().putBoolean(SHOW_COMPANY_IN_LIST, showCompanyInList).apply() + + var showGroupsInList: Boolean + get() = prefs.getBoolean(SHOW_GROUPS_IN_LIST, false) + set(showGroupsInList) = prefs.edit().putBoolean(SHOW_GROUPS_IN_LIST, showGroupsInList).apply() } diff --git a/app/src/main/kotlin/org/fossify/contacts/helpers/Constants.kt b/app/src/main/kotlin/org/fossify/contacts/helpers/Constants.kt index c6e8c5a45..4d8e3b82b 100644 --- a/app/src/main/kotlin/org/fossify/contacts/helpers/Constants.kt +++ b/app/src/main/kotlin/org/fossify/contacts/helpers/Constants.kt @@ -12,6 +12,8 @@ const val DEFAULT_FILE_NAME = "contacts.vcf" const val AVOID_CHANGING_TEXT_TAG = "avoid_changing_text_tag" const val AVOID_CHANGING_VISIBILITY_TAG = "avoid_changing_visibility_tag" const val FORMAT_PHONE_NUMBERS = "format_phone_numbers" +const val SHOW_COMPANY_IN_LIST = "show_company_in_list" +const val SHOW_GROUPS_IN_LIST = "show_groups_in_list" const val AUTOMATIC_BACKUP_REQUEST_CODE = 10001 const val AUTO_BACKUP_INTERVAL_IN_DAYS = 1 diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 85d05441e..8d506d854 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -354,6 +354,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 3d532bba2..0fe4b6a17 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -8,6 +8,8 @@ Almacenamiento del teléfono (no visible para otras aplicaciones) Compañía Puesto de trabajo + Mostrar la empresa en la lista de contactos + Mostrar los grupos (etiquetas) en la lista de contactos Enviar SMS a contactos Enviar correo electrónico a contactos Enviar SMS a grupo diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a536344f1..5eaa742c1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -15,6 +15,8 @@ Phone storage (not visible by other apps) Company Job position + Show company in the contact list + Show groups in the contact list Send SMS to contacts Send email to contacts Send SMS to group