moving some shared helper functions at the Constants.kt
This commit is contained in:
parent
12ee6d1592
commit
433cfef221
|
@ -21,6 +21,7 @@ import com.simplemobiletools.contacts.pro.extensions.config
|
||||||
import com.simplemobiletools.contacts.pro.extensions.getContactPublicUri
|
import com.simplemobiletools.contacts.pro.extensions.getContactPublicUri
|
||||||
import com.simplemobiletools.contacts.pro.extensions.getVisibleContactSources
|
import com.simplemobiletools.contacts.pro.extensions.getVisibleContactSources
|
||||||
import com.simplemobiletools.contacts.pro.helpers.ContactsHelper
|
import com.simplemobiletools.contacts.pro.helpers.ContactsHelper
|
||||||
|
import com.simplemobiletools.contacts.pro.helpers.getProperText
|
||||||
import com.simplemobiletools.contacts.pro.models.Contact
|
import com.simplemobiletools.contacts.pro.models.Contact
|
||||||
import kotlinx.android.synthetic.main.activity_select_contact.*
|
import kotlinx.android.synthetic.main.activity_select_contact.*
|
||||||
|
|
||||||
|
@ -156,8 +157,6 @@ class SelectContactActivity : SimpleActivity() {
|
||||||
(select_contact_list.adapter as? SelectContactsAdapter)?.updateItems(contactsIgnoringSearch)
|
(select_contact_list.adapter as? SelectContactsAdapter)?.updateItems(contactsIgnoringSearch)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getProperText(text: String, shouldNormalize: Boolean) = if (shouldNormalize) text.normalizeString() else text
|
|
||||||
|
|
||||||
private fun showSortingDialog() {
|
private fun showSortingDialog() {
|
||||||
ChangeSortingDialog(this) {
|
ChangeSortingDialog(this) {
|
||||||
initContacts()
|
initContacts()
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
package com.simplemobiletools.contacts.pro.adapters
|
package com.simplemobiletools.contacts.pro.adapters
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.telephony.PhoneNumberUtils
|
|
||||||
import android.text.Spannable
|
|
||||||
import android.text.SpannableString
|
|
||||||
import android.text.style.ForegroundColorSpan
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -285,7 +281,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
||||||
if (fullName.contains(textToHighlight, true)) {
|
if (fullName.contains(textToHighlight, true)) {
|
||||||
fullName.highlightTextPart(textToHighlight, adjustedPrimaryColor)
|
fullName.highlightTextPart(textToHighlight, adjustedPrimaryColor)
|
||||||
} else {
|
} else {
|
||||||
highlightTextFromNumbers(fullName, textToHighlight)
|
highlightTextFromNumbers(fullName, textToHighlight, adjustedPrimaryColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,19 +344,4 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun highlightTextFromNumbers(name: String, textToHighlight: String): SpannableString {
|
|
||||||
val spannableString = SpannableString(name)
|
|
||||||
val digits = PhoneNumberUtils.convertKeypadLettersToDigits(name)
|
|
||||||
if (digits.contains(textToHighlight)) {
|
|
||||||
val startIndex = digits.indexOf(textToHighlight, 0, true)
|
|
||||||
val endIndex = Math.min(startIndex + textToHighlight.length, name.length)
|
|
||||||
try {
|
|
||||||
spannableString.setSpan(ForegroundColorSpan(adjustedPrimaryColor), startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_INCLUSIVE)
|
|
||||||
} catch (ignored: IndexOutOfBoundsException) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return spannableString
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
package com.simplemobiletools.contacts.pro.adapters
|
package com.simplemobiletools.contacts.pro.adapters
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.telephony.PhoneNumberUtils
|
|
||||||
import android.text.Spannable
|
|
||||||
import android.text.SpannableString
|
|
||||||
import android.text.style.ForegroundColorSpan
|
|
||||||
import android.util.SparseArray
|
import android.util.SparseArray
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -24,6 +20,7 @@ import com.simplemobiletools.contacts.pro.R
|
||||||
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
|
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
|
||||||
import com.simplemobiletools.contacts.pro.extensions.config
|
import com.simplemobiletools.contacts.pro.extensions.config
|
||||||
import com.simplemobiletools.contacts.pro.helpers.Config
|
import com.simplemobiletools.contacts.pro.helpers.Config
|
||||||
|
import com.simplemobiletools.contacts.pro.helpers.highlightTextFromNumbers
|
||||||
import com.simplemobiletools.contacts.pro.models.Contact
|
import com.simplemobiletools.contacts.pro.models.Contact
|
||||||
import kotlinx.android.synthetic.main.item_add_favorite_with_number.view.*
|
import kotlinx.android.synthetic.main.item_add_favorite_with_number.view.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -120,7 +117,7 @@ class SelectContactsAdapter(val activity: SimpleActivity, var contacts: ArrayLis
|
||||||
if (fullName.contains(textToHighlight, true)) {
|
if (fullName.contains(textToHighlight, true)) {
|
||||||
fullName.highlightTextPart(textToHighlight, adjustedPrimaryColor)
|
fullName.highlightTextPart(textToHighlight, adjustedPrimaryColor)
|
||||||
} else {
|
} else {
|
||||||
highlightTextFromNumbers(fullName, textToHighlight)
|
highlightTextFromNumbers(fullName, textToHighlight, adjustedPrimaryColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,19 +170,4 @@ class SelectContactsAdapter(val activity: SimpleActivity, var contacts: ArrayLis
|
||||||
toggleItemSelection(select, adapterPosition)
|
toggleItemSelection(select, adapterPosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun highlightTextFromNumbers(name: String, textToHighlight: String): SpannableString {
|
|
||||||
val spannableString = SpannableString(name)
|
|
||||||
val digits = PhoneNumberUtils.convertKeypadLettersToDigits(name)
|
|
||||||
if (digits.contains(textToHighlight)) {
|
|
||||||
val startIndex = digits.indexOf(textToHighlight, 0, true)
|
|
||||||
val endIndex = Math.min(startIndex + textToHighlight.length, name.length)
|
|
||||||
try {
|
|
||||||
spannableString.setSpan(ForegroundColorSpan(adjustedPrimaryColor), startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_INCLUSIVE)
|
|
||||||
} catch (ignored: IndexOutOfBoundsException) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return spannableString
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,7 +264,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filtered.isEmpty() && this@MyViewPagerFragment is FavoritesFragment) {
|
if (filtered.isEmpty() && this@MyViewPagerFragment is FavoritesFragment) {
|
||||||
fragment_placeholder.text = activity?.getString(R.string.no_items_found)
|
fragment_placeholder.text = activity?.getString(R.string.no_contacts_found)
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment_placeholder.beVisibleIf(filtered.isEmpty())
|
fragment_placeholder.beVisibleIf(filtered.isEmpty())
|
||||||
|
@ -283,8 +283,6 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getProperText(text: String, shouldNormalize: Boolean) = if (shouldNormalize) text.normalizeString() else text
|
|
||||||
|
|
||||||
fun onSearchOpened() {
|
fun onSearchOpened() {
|
||||||
contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: ArrayList()
|
contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: ArrayList()
|
||||||
groupsIgnoringSearch = (fragment_list?.adapter as? GroupsAdapter)?.groups ?: ArrayList()
|
groupsIgnoringSearch = (fragment_list?.adapter as? GroupsAdapter)?.groups ?: ArrayList()
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
package com.simplemobiletools.contacts.pro.helpers
|
package com.simplemobiletools.contacts.pro.helpers
|
||||||
|
|
||||||
import android.provider.ContactsContract.CommonDataKinds
|
import android.provider.ContactsContract.CommonDataKinds
|
||||||
|
import android.telephony.PhoneNumberUtils
|
||||||
|
import android.text.Spannable
|
||||||
|
import android.text.SpannableString
|
||||||
|
import android.text.style.ForegroundColorSpan
|
||||||
|
import com.simplemobiletools.commons.extensions.normalizeString
|
||||||
import com.simplemobiletools.contacts.pro.models.LocalContact
|
import com.simplemobiletools.contacts.pro.models.LocalContact
|
||||||
|
|
||||||
// shared prefs
|
// shared prefs
|
||||||
|
@ -109,3 +114,20 @@ const val SIGNAL_PACKAGE = "org.thoughtcrime.securesms"
|
||||||
const val WHATSAPP_PACKAGE = "com.whatsapp"
|
const val WHATSAPP_PACKAGE = "com.whatsapp"
|
||||||
|
|
||||||
fun getEmptyLocalContact() = LocalContact(0, "", "", "", "", "", "", null, ArrayList(), ArrayList(), ArrayList(), 0, ArrayList(), "", ArrayList(), "", "", ArrayList(), ArrayList())
|
fun getEmptyLocalContact() = LocalContact(0, "", "", "", "", "", "", null, ArrayList(), ArrayList(), ArrayList(), 0, ArrayList(), "", ArrayList(), "", "", ArrayList(), ArrayList())
|
||||||
|
|
||||||
|
fun getProperText(text: String, shouldNormalize: Boolean) = if (shouldNormalize) text.normalizeString() else text
|
||||||
|
|
||||||
|
fun highlightTextFromNumbers(name: String, textToHighlight: String, adjustedPrimaryColor: Int): SpannableString {
|
||||||
|
val spannableString = SpannableString(name)
|
||||||
|
val digits = PhoneNumberUtils.convertKeypadLettersToDigits(name)
|
||||||
|
if (digits.contains(textToHighlight)) {
|
||||||
|
val startIndex = digits.indexOf(textToHighlight, 0, true)
|
||||||
|
val endIndex = Math.min(startIndex + textToHighlight.length, name.length)
|
||||||
|
try {
|
||||||
|
spannableString.setSpan(ForegroundColorSpan(adjustedPrimaryColor), startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_INCLUSIVE)
|
||||||
|
} catch (ignored: IndexOutOfBoundsException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return spannableString
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue