Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -242,6 +250,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
config.apply {
storedShowContactThumbnails = showContactThumbnails
storedShowPhoneNumbers = showPhoneNumbers
storedShowCompanyInList = showCompanyInList
storedShowGroupsInList = showGroupsInList
storedStartNameWithSurname = startNameWithSurname
storedShowTabs = showTabs
storedFontSize = fontSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class SettingsActivity : SimpleActivity() {
setupShowContactThumbnails()
setupShowPhoneNumbers()
setupEnableNumberFormatting()
setupShowCompanyInList()
setupShowGroupsInList()
setupShowContactsWithNumbers()
setupStartNameWithSurname()
setupMergeDuplicateContacts()
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
}
}

Expand Down Expand Up @@ -403,7 +409,12 @@ class ContactsAdapter(
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
}

if (findViewById<TextView>(org.fossify.commons.R.id.item_contact_number) != null) {
val numberView = findViewById<TextView>(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 {
Expand All @@ -415,13 +426,21 @@ class ContactsAdapter(
} else {
phoneNumberToUse?.value ?: ""
}
findViewById<TextView>(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<TextView>(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<ImageView>(org.fossify.commons.R.id.item_contact_image).apply {
beVisibleIf(showContactThumbnails)
if (profileIconClick != null && viewType != VIEW_TYPE_GRID) {
Expand Down Expand Up @@ -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<String>(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() }
Comment on lines +516 to +517
.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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ abstract class MyViewPagerFragment<Binding : MyViewPagerFragment.InnerBinding>(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

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/kotlin/org/fossify/contacts/helpers/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,36 @@

</RelativeLayout>

<RelativeLayout
android:id="@+id/settings_show_company_in_list_holder"
style="@style/SettingsHolderSwitchStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<org.fossify.commons.views.MyMaterialSwitch
android:id="@+id/settings_show_company_in_list"
style="@style/SettingsSwitchStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/show_company_in_list" />

</RelativeLayout>

<RelativeLayout
android:id="@+id/settings_show_groups_in_list_holder"
style="@style/SettingsHolderSwitchStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<org.fossify.commons.views.MyMaterialSwitch
android:id="@+id/settings_show_groups_in_list"
style="@style/SettingsSwitchStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/show_groups_in_list" />

</RelativeLayout>

<RelativeLayout
android:id="@+id/settings_start_name_with_surname_holder"
style="@style/SettingsHolderSwitchStyle"
Expand Down
90 changes: 90 additions & 0 deletions app/src/main/res/layout/item_contact_with_details.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
List item used when "Show company/groups in the contact list" is enabled.
Same IDs as the Commons item_contact_with_number layout, plus item_contact_details.
The number and details lines are hidden at bind time when not needed.
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_contact_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/tiny_margin"
android:background="@drawable/selector_clickable"
android:clickable="true"
android:focusable="true"
android:minHeight="@dimen/two_line_list_item_min_height"
android:paddingHorizontal="@dimen/list_item_padding_horizontal"
android:paddingVertical="@dimen/list_item_padding_vertical">

<ImageView
android:id="@+id/item_contact_image"
android:layout_width="@dimen/list_icon_size_medium"
android:layout_height="@dimen/list_icon_size_medium"
android:padding="@dimen/tiny_margin"
android:src="@drawable/ic_person_vector"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/item_contact_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/list_item_padding_horizontal"
android:ellipsize="end"
android:maxLines="1"
android:textDirection="locale"
android:textSize="@dimen/list_primary_text_size"
app:layout_constraintBottom_toTopOf="@+id/item_contact_number"
app:layout_constraintEnd_toStartOf="@+id/drag_handle_icon"
app:layout_constraintStart_toEndOf="@+id/item_contact_image"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="John Doe" />

<TextView
android:id="@+id/item_contact_number"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/list_item_padding_horizontal"
android:alpha="0.6"
android:maxLines="1"
android:textSize="@dimen/list_secondary_text_size"
app:layout_constraintBottom_toTopOf="@+id/item_contact_details"
app:layout_constraintEnd_toStartOf="@+id/drag_handle_icon"
app:layout_constraintStart_toEndOf="@+id/item_contact_image"
app:layout_constraintTop_toBottomOf="@+id/item_contact_name"
tools:text="0123 456 789" />

<TextView
android:id="@+id/item_contact_details"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/list_item_padding_horizontal"
android:alpha="0.6"
android:ellipsize="end"
android:maxLines="1"
android:textDirection="locale"
android:textSize="@dimen/list_secondary_text_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/drag_handle_icon"
app:layout_constraintStart_toEndOf="@+id/item_contact_image"
app:layout_constraintTop_toBottomOf="@+id/item_contact_number"
tools:text="Acme S.L. · Clientes, Proveedores" />

<ImageView
android:id="@+id/drag_handle_icon"
android:layout_width="@dimen/list_touch_target_min"
android:layout_height="@dimen/list_touch_target_min"
android:paddingTop="@dimen/normal_margin"
android:paddingBottom="@dimen/normal_margin"
android:src="@drawable/ic_drag_handle_vector"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<string name="phone_storage_hidden">Almacenamiento del teléfono (no visible para otras aplicaciones)</string>
<string name="company">Compañía</string>
<string name="job_position">Puesto de trabajo</string>
<string name="show_company_in_list">Mostrar la empresa en la lista de contactos</string>
<string name="show_groups_in_list">Mostrar los grupos (etiquetas) en la lista de contactos</string>
<string name="send_sms_to_contacts">Enviar SMS a contactos</string>
<string name="send_email_to_contacts">Enviar correo electrónico a contactos</string>
<string name="send_sms_to_group">Enviar SMS a grupo</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="phone_storage_hidden">Phone storage (not visible by other apps)</string>
<string name="company">Company</string>
<string name="job_position">Job position</string>
<string name="show_company_in_list">Show company in the contact list</string>
<string name="show_groups_in_list">Show groups in the contact list</string>
<string name="send_sms_to_contacts">Send SMS to contacts</string>
<string name="send_email_to_contacts">Send email to contacts</string>
<string name="send_sms_to_group">Send SMS to group</string>
Expand Down
Loading