moving some helper functions into Commons
This commit is contained in:
parent
741df6251c
commit
d82d9805be
9 changed files with 14 additions and 43 deletions
|
@ -57,7 +57,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:5.27.18'
|
||||
implementation 'com.simplemobiletools:commons:5.27.20'
|
||||
implementation 'joda-time:joda-time:2.10.1'
|
||||
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'
|
||||
implementation 'com.github.tibbi:IndicatorFastScroll:08f512858a'
|
||||
|
|
|
@ -911,7 +911,7 @@ class EditContactActivity : ContactActivity() {
|
|||
val numberLabel = if (numberType == Phone.TYPE_CUSTOM) numberHolder.contact_number_type.value else ""
|
||||
|
||||
if (number.isNotEmpty()) {
|
||||
phoneNumbers.add(PhoneNumber(number, numberType, numberLabel, number.normalizeNumber()))
|
||||
phoneNumbers.add(PhoneNumber(number, numberType, numberLabel, number.normalizePhoneNumber()))
|
||||
}
|
||||
}
|
||||
return phoneNumbers
|
||||
|
|
|
@ -15,10 +15,7 @@ import com.bumptech.glide.signature.ObjectKey
|
|||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||
import com.simplemobiletools.commons.extensions.getTextSize
|
||||
import com.simplemobiletools.commons.extensions.highlightTextPart
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
|
@ -273,7 +270,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
|||
if (fullName.contains(textToHighlight, true)) {
|
||||
fullName.highlightTextPart(textToHighlight, adjustedPrimaryColor)
|
||||
} else {
|
||||
highlightTextFromNumbers(fullName, textToHighlight, adjustedPrimaryColor)
|
||||
fullName.highlightTextFromNumbers(textToHighlight, adjustedPrimaryColor)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,17 +10,13 @@ import com.bumptech.glide.Glide
|
|||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.bumptech.glide.signature.ObjectKey
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||
import com.simplemobiletools.commons.extensions.getTextSize
|
||||
import com.simplemobiletools.commons.extensions.highlightTextPart
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
|
||||
import com.simplemobiletools.commons.views.FastScroller
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.contacts.pro.R
|
||||
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.pro.extensions.config
|
||||
import com.simplemobiletools.contacts.pro.helpers.highlightTextFromNumbers
|
||||
import com.simplemobiletools.contacts.pro.models.Contact
|
||||
import kotlinx.android.synthetic.main.item_add_favorite_with_number.view.*
|
||||
import java.util.*
|
||||
|
@ -113,7 +109,7 @@ class SelectContactsAdapter(val activity: SimpleActivity, var contacts: ArrayLis
|
|||
if (fullName.contains(textToHighlight, true)) {
|
||||
fullName.highlightTextPart(textToHighlight, adjustedPrimaryColor)
|
||||
} else {
|
||||
highlightTextFromNumbers(fullName, textToHighlight, adjustedPrimaryColor)
|
||||
fullName.highlightTextFromNumbers(textToHighlight, adjustedPrimaryColor)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.simplemobiletools.contacts.pro.extensions
|
||||
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.widget.TextView
|
||||
import com.simplemobiletools.commons.helpers.getDateFormats
|
||||
import org.joda.time.DateTime
|
||||
|
@ -33,5 +32,3 @@ fun String.getDateTimeFromDateString(viewToUpdate: TextView? = null): DateTime {
|
|||
}
|
||||
return date
|
||||
}
|
||||
|
||||
fun String.normalizeNumber() = PhoneNumberUtils.normalizeNumber(this)
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package com.simplemobiletools.contacts.pro.helpers
|
||||
|
||||
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
|
||||
|
||||
|
@ -123,18 +119,3 @@ const val WHATSAPP_PACKAGE = "com.whatsapp"
|
|||
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
|
||||
}
|
||||
|
|
|
@ -265,7 +265,7 @@ class ContactsHelper(val context: Context) {
|
|||
context.queryCursor(uri, projection, selection, selectionArgs, showErrors = true) { cursor ->
|
||||
val id = cursor.getIntValue(Data.RAW_CONTACT_ID)
|
||||
val number = cursor.getStringValue(Phone.NUMBER) ?: return@queryCursor
|
||||
val normalizedNumber = cursor.getStringValue(Phone.NORMALIZED_NUMBER) ?: number.normalizeNumber()
|
||||
val normalizedNumber = cursor.getStringValue(Phone.NORMALIZED_NUMBER) ?: number.normalizePhoneNumber()
|
||||
val type = cursor.getIntValue(Phone.TYPE)
|
||||
val label = cursor.getStringValue(Phone.LABEL) ?: ""
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@ import android.graphics.BitmapFactory
|
|||
import android.provider.ContactsContract.CommonDataKinds
|
||||
import android.provider.ContactsContract.CommonDataKinds.*
|
||||
import android.widget.Toast
|
||||
import com.simplemobiletools.commons.extensions.normalizePhoneNumber
|
||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.pro.extensions.getCachePhoto
|
||||
import com.simplemobiletools.contacts.pro.extensions.getCachePhotoUri
|
||||
import com.simplemobiletools.contacts.pro.extensions.groupsDB
|
||||
import com.simplemobiletools.contacts.pro.extensions.normalizeNumber
|
||||
import com.simplemobiletools.contacts.pro.helpers.VcfImporter.ImportResult.*
|
||||
import com.simplemobiletools.contacts.pro.models.*
|
||||
import com.simplemobiletools.contacts.pro.models.Email
|
||||
|
@ -60,7 +60,7 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||
""
|
||||
}
|
||||
|
||||
phoneNumbers.add(PhoneNumber(number, type, label, number.normalizeNumber()))
|
||||
phoneNumbers.add(PhoneNumber(number, type, label, number.normalizePhoneNumber()))
|
||||
}
|
||||
|
||||
val emails = ArrayList<Email>()
|
||||
|
|
|
@ -2,11 +2,11 @@ package com.simplemobiletools.contacts.pro.models
|
|||
|
||||
import android.graphics.Bitmap
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import com.simplemobiletools.commons.extensions.normalizePhoneNumber
|
||||
import com.simplemobiletools.commons.extensions.normalizeString
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
|
||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||
import com.simplemobiletools.contacts.pro.extensions.normalizeNumber
|
||||
import com.simplemobiletools.contacts.pro.helpers.SMT_PRIVATE
|
||||
|
||||
data class Contact(var id: Int, var prefix: String, var firstName: String, var middleName: String, var surname: String, var suffix: String, var nickname: String,
|
||||
|
@ -109,8 +109,8 @@ data class Contact(var id: Int, var prefix: String, var firstName: String, var m
|
|||
|
||||
fun getStringToCompare(): String {
|
||||
return copy(id = 0, prefix = "", firstName = getNameToDisplay().toLowerCase(), middleName = "", surname = "", suffix = "", nickname = "", photoUri = "",
|
||||
phoneNumbers = ArrayList(), emails = ArrayList(), events = ArrayList(), source = "", addresses = ArrayList(), starred = 0, contactId = 0,
|
||||
thumbnailUri = "", notes = "", groups = ArrayList(), websites = ArrayList(), organization = Organization("", ""), IMs = ArrayList()).toString()
|
||||
phoneNumbers = ArrayList(), emails = ArrayList(), events = ArrayList(), source = "", addresses = ArrayList(), starred = 0, contactId = 0,
|
||||
thumbnailUri = "", notes = "", groups = ArrayList(), websites = ArrayList(), organization = Organization("", ""), IMs = ArrayList()).toString()
|
||||
}
|
||||
|
||||
fun getHashToCompare() = getStringToCompare().hashCode()
|
||||
|
@ -125,12 +125,12 @@ data class Contact(var id: Int, var prefix: String, var firstName: String, var m
|
|||
|
||||
fun doesContainPhoneNumber(text: String, convertLetters: Boolean): Boolean {
|
||||
return if (text.isNotEmpty()) {
|
||||
val normalizedText = if (convertLetters) text.normalizeNumber() else text
|
||||
val normalizedText = if (convertLetters) text.normalizePhoneNumber() else text
|
||||
phoneNumbers.any {
|
||||
PhoneNumberUtils.compare(it.normalizedNumber, normalizedText) ||
|
||||
it.value.contains(text) ||
|
||||
it.normalizedNumber?.contains(normalizedText) == true ||
|
||||
it.value.normalizeNumber().contains(normalizedText)
|
||||
it.value.normalizePhoneNumber().contains(normalizedText)
|
||||
}
|
||||
} else {
|
||||
false
|
||||
|
|
Loading…
Reference in a new issue