Fixed display for starting with surname (#544)

This commit is contained in:
Agnieszka C
2023-03-09 20:16:35 +01:00
parent 2bb7a1debe
commit 6afb6f3220
12 changed files with 49 additions and 27 deletions

View File

@ -274,7 +274,7 @@ class DialpadActivity : SimpleActivity() {
letter_fastscroller.setupWithRecyclerView(dialpad_list, { position -> letter_fastscroller.setupWithRecyclerView(dialpad_list, { position ->
try { try {
val name = filtered[position].name val name = filtered[position].getNameToDisplay()
val character = if (name.isNotEmpty()) name.substring(0, 1) else "" val character = if (name.isNotEmpty()) name.substring(0, 1) else ""
FastScrollItemIndicator.Text(character.toUpperCase(Locale.getDefault())) FastScrollItemIndicator.Text(character.toUpperCase(Locale.getDefault()))
} catch (e: Exception) { } catch (e: Exception) {

View File

@ -41,6 +41,7 @@ import me.grantland.widget.AutofitHelper
class MainActivity : SimpleActivity() { class MainActivity : SimpleActivity() {
private var launchedDialer = false private var launchedDialer = false
private var storedShowTabs = 0 private var storedShowTabs = 0
private var storedStartNameWithSurname = false
var cachedContacts = ArrayList<Contact>() var cachedContacts = ArrayList<Contact>()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -106,6 +107,13 @@ class MainActivity : SimpleActivity() {
it?.setupColors(getProperTextColor(), getProperPrimaryColor(), getProperPrimaryColor()) it?.setupColors(getProperTextColor(), getProperPrimaryColor(), getProperPrimaryColor())
} }
val configStartNameWithSurname = config.startNameWithSurname
if (storedStartNameWithSurname != configStartNameWithSurname) {
contacts_fragment?.startNameWithSurnameChanged(configStartNameWithSurname)
favorites_fragment?.startNameWithSurnameChanged(configStartNameWithSurname)
storedStartNameWithSurname = config.startNameWithSurname
}
if (!main_menu.isSearchOpen) { if (!main_menu.isSearchOpen) {
refreshItems(true) refreshItems(true)
} }
@ -119,6 +127,7 @@ class MainActivity : SimpleActivity() {
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
storedShowTabs = config.showTabs storedShowTabs = config.showTabs
storedStartNameWithSurname = config.startNameWithSurname
config.lastUsedViewPagerPage = view_pager.currentItem config.lastUsedViewPagerPage = view_pager.currentItem
} }
@ -373,6 +382,7 @@ class MainActivity : SimpleActivity() {
main_tabs_holder.beGoneIf(main_tabs_holder.tabCount == 1) main_tabs_holder.beGoneIf(main_tabs_holder.tabCount == 1)
storedShowTabs = config.showTabs storedShowTabs = config.showTabs
storedStartNameWithSurname = config.startNameWithSurname
} }
private fun getTabIcon(position: Int): Drawable { private fun getTabIcon(position: Int): Drawable {
@ -417,7 +427,7 @@ class MainActivity : SimpleActivity() {
} }
} }
private fun refreshFragments() { fun refreshFragments() {
contacts_fragment?.refreshItems() contacts_fragment?.refreshItems()
favorites_fragment?.refreshItems() favorites_fragment?.refreshItems()
recents_fragment?.refreshItems() recents_fragment?.refreshItems()

View File

@ -5,7 +5,6 @@ import com.google.gson.Gson
import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.helpers.ContactsHelper import com.simplemobiletools.commons.helpers.ContactsHelper
import com.simplemobiletools.commons.helpers.NavigationIcon import com.simplemobiletools.commons.helpers.NavigationIcon
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import com.simplemobiletools.commons.models.contacts.Contact import com.simplemobiletools.commons.models.contacts.Contact
import com.simplemobiletools.dialer.R import com.simplemobiletools.dialer.R
import com.simplemobiletools.dialer.adapters.SpeedDialAdapter import com.simplemobiletools.dialer.adapters.SpeedDialAdapter
@ -55,7 +54,7 @@ class ManageSpeedDialActivity : SimpleActivity(), RemoveSpeedDialListener {
SelectContactDialog(this, allContacts) { selectedContact -> SelectContactDialog(this, allContacts) { selectedContact ->
speedDialValues.first { it.id == clickedContact.id }.apply { speedDialValues.first { it.id == clickedContact.id }.apply {
displayName = selectedContact.name displayName = selectedContact.getNameToDisplay()
number = selectedContact.phoneNumbers.first().normalizedNumber number = selectedContact.phoneNumbers.first().normalizedNumber
} }
updateAdapter() updateAdapter()

View File

@ -184,7 +184,7 @@ class ContactsAdapter(
val itemsCnt = selectedKeys.size val itemsCnt = selectedKeys.size
val firstItem = getSelectedItems().firstOrNull() ?: return val firstItem = getSelectedItems().firstOrNull() ?: return
val items = if (itemsCnt == 1) { val items = if (itemsCnt == 1) {
"\"${firstItem.name}\"" "\"${firstItem.getNameToDisplay()}\""
} else { } else {
resources.getQuantityString(R.plurals.delete_contacts, itemsCnt, itemsCnt) resources.getQuantityString(R.plurals.delete_contacts, itemsCnt, itemsCnt)
} }
@ -242,7 +242,7 @@ class ContactsAdapter(
val contact = contacts.firstOrNull { selectedKeys.contains(it.rawId) } ?: return val contact = contacts.firstOrNull { selectedKeys.contains(it.rawId) } ?: return
val manager = activity.shortcutManager val manager = activity.shortcutManager
if (manager.isRequestPinShortcutSupported) { if (manager.isRequestPinShortcutSupported) {
SimpleContactsHelper(activity).getShortcutImage(contact.photoUri, contact.name) { image -> SimpleContactsHelper(activity).getShortcutImage(contact.photoUri, contact.getNameToDisplay()) { image ->
activity.runOnUiThread { activity.runOnUiThread {
activity.handlePermission(PERMISSION_CALL_PHONE) { hasPermission -> activity.handlePermission(PERMISSION_CALL_PHONE) { hasPermission ->
val action = if (hasPermission) Intent.ACTION_CALL else Intent.ACTION_DIAL val action = if (hasPermission) Intent.ACTION_CALL else Intent.ACTION_DIAL
@ -251,7 +251,7 @@ class ContactsAdapter(
} }
val shortcut = ShortcutInfo.Builder(activity, contact.hashCode().toString()) val shortcut = ShortcutInfo.Builder(activity, contact.hashCode().toString())
.setShortLabel(contact.name) .setShortLabel(contact.getNameToDisplay())
.setIcon(Icon.createWithBitmap(image)) .setIcon(Icon.createWithBitmap(image))
.setIntent(intent) .setIntent(intent)
.build() .build()
@ -277,11 +277,12 @@ class ContactsAdapter(
setTextColor(textColor) setTextColor(textColor)
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize) setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
text = if (textToHighlight.isEmpty()) contact.name else { val name = contact.getNameToDisplay()
if (contact.name.contains(textToHighlight, true)) { text = if (textToHighlight.isEmpty()) name else {
contact.name.highlightTextPart(textToHighlight, properPrimaryColor) if (name.contains(textToHighlight, true)) {
name.highlightTextPart(textToHighlight, properPrimaryColor)
} else { } else {
contact.name.highlightTextFromNumbers(textToHighlight, properPrimaryColor) name.highlightTextFromNumbers(textToHighlight, properPrimaryColor)
} }
} }
} }
@ -306,7 +307,7 @@ class ContactsAdapter(
} }
if (!activity.isDestroyed) { if (!activity.isDestroyed) {
SimpleContactsHelper(context).loadContactImage(contact.photoUri, findViewById(R.id.item_contact_image), contact.name) SimpleContactsHelper(context).loadContactImage(contact.photoUri, findViewById(R.id.item_contact_image), contact.getNameToDisplay())
} }
} }
} }

View File

@ -275,13 +275,14 @@ class RecentCallsAdapter(
private fun setupView(view: View, call: RecentCall) { private fun setupView(view: View, call: RecentCall) {
view.apply { view.apply {
item_recents_holder.isSelected = selectedKeys.contains(call.id) item_recents_holder.isSelected = selectedKeys.contains(call.id)
var nameToShow = SpannableString(call.name) val name = findContactByCall(call)?.getNameToDisplay() ?: call.name
var nameToShow = SpannableString(name)
if (call.specificType.isNotEmpty()) { if (call.specificType.isNotEmpty()) {
nameToShow = SpannableString("${call.name} - ${call.specificType}") nameToShow = SpannableString("${name} - ${call.specificType}")
// show specific number at "Show call details" dialog too // show specific number at "Show call details" dialog too
if (refreshItemsListener == null) { if (refreshItemsListener == null) {
nameToShow = SpannableString("${call.name} - ${call.specificType}, ${call.specificNumber}") nameToShow = SpannableString("${name} - ${call.specificType}, ${call.specificNumber}")
} }
} }

View File

@ -23,7 +23,7 @@ class SelectContactDialog(val activity: SimpleActivity, contacts: ArrayList<Cont
letter_fastscroller.setupWithRecyclerView(select_contact_list, { position -> letter_fastscroller.setupWithRecyclerView(select_contact_list, { position ->
try { try {
val name = contacts[position].name val name = contacts[position].getNameToDisplay()
val character = if (name.isNotEmpty()) name.substring(0, 1) else "" val character = if (name.isNotEmpty()) name.substring(0, 1) else ""
FastScrollItemIndicator.Text(character.toUpperCase(Locale.getDefault())) FastScrollItemIndicator.Text(character.toUpperCase(Locale.getDefault()))
} catch (e: Exception) { } catch (e: Exception) {

View File

@ -112,7 +112,7 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
private fun setupLetterFastscroller(contacts: ArrayList<Contact>) { private fun setupLetterFastscroller(contacts: ArrayList<Contact>) {
letter_fastscroller.setupWithRecyclerView(fragment_list, { position -> letter_fastscroller.setupWithRecyclerView(fragment_list, { position ->
try { try {
val name = contacts[position].name val name = contacts[position].getNameToDisplay()
val character = if (name.isNotEmpty()) name.substring(0, 1) else "" val character = if (name.isNotEmpty()) name.substring(0, 1) else ""
FastScrollItemIndicator.Text(character.toUpperCase(Locale.getDefault()).normalizeString()) FastScrollItemIndicator.Text(character.toUpperCase(Locale.getDefault()).normalizeString())
} catch (e: Exception) { } catch (e: Exception) {
@ -130,7 +130,7 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
override fun onSearchQueryChanged(text: String) { override fun onSearchQueryChanged(text: String) {
val shouldNormalize = text.normalizeString() == text val shouldNormalize = text.normalizeString() == text
val filtered = allContacts.filter { val filtered = allContacts.filter {
getProperText(it.name, shouldNormalize).contains(text, true) || getProperText(it.getNameToDisplay(), shouldNormalize).contains(text, true) ||
getProperText(it.nickname, shouldNormalize).contains(text, true) || getProperText(it.nickname, shouldNormalize).contains(text, true) ||
it.phoneNumbers.any { it.phoneNumbers.any {
text.normalizePhoneNumber().isNotEmpty() && it.normalizedNumber.contains(text.normalizePhoneNumber(), true) text.normalizePhoneNumber().isNotEmpty() && it.normalizedNumber.contains(text.normalizePhoneNumber(), true)
@ -145,7 +145,7 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
} as ArrayList } as ArrayList
filtered.sortBy { filtered.sortBy {
val nameToDisplay = it.name val nameToDisplay = it.getNameToDisplay()
!getProperText(nameToDisplay, shouldNormalize).startsWith(text, true) && !nameToDisplay.contains(text, true) !getProperText(nameToDisplay, shouldNormalize).startsWith(text, true) && !nameToDisplay.contains(text, true)
} }

View File

@ -92,7 +92,7 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
enableDrag = true, enableDrag = true,
) { ) {
if (context.config.showCallConfirmation) { if (context.config.showCallConfirmation) {
CallConfirmationDialog(activity as SimpleActivity, (it as Contact).name) { CallConfirmationDialog(activity as SimpleActivity, (it as Contact).getNameToDisplay()) {
callContact(it) callContact(it)
} }
} else { } else {
@ -167,7 +167,7 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
private fun setupLetterFastscroller(contacts: ArrayList<Contact>) { private fun setupLetterFastscroller(contacts: ArrayList<Contact>) {
letter_fastscroller.setupWithRecyclerView(fragment_list, { position -> letter_fastscroller.setupWithRecyclerView(fragment_list, { position ->
try { try {
val name = contacts[position].name val name = contacts[position].getNameToDisplay()
val character = if (name.isNotEmpty()) name.substring(0, 1) else "" val character = if (name.isNotEmpty()) name.substring(0, 1) else ""
FastScrollItemIndicator.Text(character.toUpperCase(Locale.getDefault()).normalizeString()) FastScrollItemIndicator.Text(character.toUpperCase(Locale.getDefault()).normalizeString())
} catch (e: Exception) { } catch (e: Exception) {

View File

@ -6,7 +6,11 @@ import android.widget.RelativeLayout
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.getProperPrimaryColor import com.simplemobiletools.commons.extensions.getProperPrimaryColor
import com.simplemobiletools.commons.extensions.getProperTextColor import com.simplemobiletools.commons.extensions.getProperTextColor
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
import com.simplemobiletools.commons.helpers.SORT_BY_SURNAME
import com.simplemobiletools.dialer.activities.MainActivity
import com.simplemobiletools.dialer.activities.SimpleActivity import com.simplemobiletools.dialer.activities.SimpleActivity
import com.simplemobiletools.dialer.adapters.ContactsAdapter
import com.simplemobiletools.dialer.extensions.config import com.simplemobiletools.dialer.extensions.config
import com.simplemobiletools.dialer.helpers.Config import com.simplemobiletools.dialer.helpers.Config
import kotlinx.android.synthetic.main.fragment_letters_layout.view.* import kotlinx.android.synthetic.main.fragment_letters_layout.view.*
@ -27,6 +31,15 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
} }
} }
fun startNameWithSurnameChanged(startNameWithSurname: Boolean) {
if (this !is RecentsFragment) {
(fragment_list.adapter as? ContactsAdapter)?.apply {
config.sorting = if (startNameWithSurname) SORT_BY_SURNAME else SORT_BY_FIRST_NAME
(this@MyViewPagerFragment.activity!! as MainActivity).refreshFragments()
}
}
}
fun finishActMode() { fun finishActMode() {
(fragment_list?.adapter as? MyRecyclerViewAdapter)?.finishActMode() (fragment_list?.adapter as? MyRecyclerViewAdapter)?.finishActMode()
(recents_list?.adapter as? MyRecyclerViewAdapter)?.finishActMode() (recents_list?.adapter as? MyRecyclerViewAdapter)?.finishActMode()

View File

@ -7,7 +7,6 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ContactsHelper import com.simplemobiletools.commons.helpers.ContactsHelper
import com.simplemobiletools.commons.helpers.MyContactsContentProvider import com.simplemobiletools.commons.helpers.MyContactsContentProvider
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import com.simplemobiletools.dialer.R import com.simplemobiletools.dialer.R
import com.simplemobiletools.dialer.activities.SimpleActivity import com.simplemobiletools.dialer.activities.SimpleActivity
import com.simplemobiletools.dialer.adapters.RecentCallsAdapter import com.simplemobiletools.dialer.adapters.RecentCallsAdapter
@ -58,7 +57,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
if (privateContacts.isNotEmpty()) { if (privateContacts.isNotEmpty()) {
val privateContact = privateContacts.firstOrNull { it.doesContainPhoneNumber(recent.phoneNumber) } val privateContact = privateContacts.firstOrNull { it.doesContainPhoneNumber(recent.phoneNumber) }
if (privateContact != null) { if (privateContact != null) {
recent.name = privateContact.name recent.name = privateContact.getNameToDisplay()
wasNameFilled = true wasNameFilled = true
} }
} }
@ -66,7 +65,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
if (!wasNameFilled) { if (!wasNameFilled) {
val contact = contacts.filter { it.phoneNumbers.isNotEmpty() }.firstOrNull { it.phoneNumbers.first().normalizedNumber == recent.phoneNumber } val contact = contacts.filter { it.phoneNumbers.isNotEmpty() }.firstOrNull { it.phoneNumbers.first().normalizedNumber == recent.phoneNumber }
if (contact != null) { if (contact != null) {
recent.name = contact.name recent.name = contact.getNameToDisplay()
} }
} }
} }

View File

@ -7,7 +7,6 @@ import com.simplemobiletools.commons.extensions.getMyContactsCursor
import com.simplemobiletools.commons.extensions.getPhoneNumberTypeText import com.simplemobiletools.commons.extensions.getPhoneNumberTypeText
import com.simplemobiletools.commons.helpers.ContactsHelper import com.simplemobiletools.commons.helpers.ContactsHelper
import com.simplemobiletools.commons.helpers.MyContactsContentProvider import com.simplemobiletools.commons.helpers.MyContactsContentProvider
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.dialer.R import com.simplemobiletools.dialer.R
import com.simplemobiletools.dialer.extensions.isConference import com.simplemobiletools.dialer.extensions.isConference
@ -54,7 +53,7 @@ fun getCallContact(context: Context, call: Call?, callback: (CallContact) -> Uni
callContact.number = number callContact.number = number
val contact = contacts.firstOrNull { it.doesHavePhoneNumber(number) } val contact = contacts.firstOrNull { it.doesHavePhoneNumber(number) }
if (contact != null) { if (contact != null) {
callContact.name = contact.name callContact.name = contact.getNameToDisplay()
callContact.photoUri = contact.photoUri callContact.photoUri = contact.photoUri
if (contact.phoneNumbers.size > 1) { if (contact.phoneNumbers.size > 1) {

View File

@ -101,7 +101,7 @@ class RecentsHelper(private val context: Context) {
val curNumber = contact.phoneNumbers.first().normalizedNumber val curNumber = contact.phoneNumbers.first().normalizedNumber
if (curNumber.length >= COMPARABLE_PHONE_NUMBER_LENGTH) { if (curNumber.length >= COMPARABLE_PHONE_NUMBER_LENGTH) {
if (curNumber.substring(curNumber.length - COMPARABLE_PHONE_NUMBER_LENGTH) == normalizedNumber.substring(normalizedNumber.length - COMPARABLE_PHONE_NUMBER_LENGTH)) { if (curNumber.substring(curNumber.length - COMPARABLE_PHONE_NUMBER_LENGTH) == normalizedNumber.substring(normalizedNumber.length - COMPARABLE_PHONE_NUMBER_LENGTH)) {
contactsNumbersMap[number] = contact.name contactsNumbersMap[number] = contact.getNameToDisplay()
return@firstOrNull true return@firstOrNull true
} }
} }