Added unknown phone calls visibility in Call History

This commit is contained in:
merkost
2023-06-21 10:54:16 +10:00
parent 939cba30ea
commit d575123474
4 changed files with 74 additions and 28 deletions

View File

@ -107,7 +107,11 @@ class RecentCallsAdapter(
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val recentCall = recentCalls[position]
holder.bindView(recentCall, refreshItemsListener != null, refreshItemsListener != null) { itemView, layoutPosition ->
holder.bindView(
any = recentCall,
allowSingleClick = refreshItemsListener != null && !recentCall.isUnknownNumber,
allowLongClick = refreshItemsListener != null && !recentCall.isUnknownNumber
) { itemView, _ ->
setupView(itemView, recentCall)
}
bindViewHolder(holder)
@ -274,6 +278,7 @@ class RecentCallsAdapter(
private fun getSelectedPhoneNumber() = getSelectedItems().firstOrNull()?.phoneNumber
private fun setupView(view: View, call: RecentCall) {
val showShowOverflowMenu = showOverflowMenu && !call.isUnknownNumber
view.apply {
item_recents_holder.isSelected = selectedKeys.contains(call.id)
val name = findContactByCall(call)?.getNameToDisplay() ?: call.name
@ -312,7 +317,7 @@ class RecentCallsAdapter(
setTextColor(textColor)
beVisibleIf(call.type != Calls.MISSED_TYPE && call.type != Calls.REJECTED_TYPE && call.duration > 0)
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize * 0.8f)
if (!showOverflowMenu) {
if (!showShowOverflowMenu) {
item_recents_duration.setPadding(0, 0, durationPadding, 0)
}
}
@ -335,8 +340,8 @@ class RecentCallsAdapter(
item_recents_type.setImageDrawable(drawable)
overflow_menu_icon.beVisibleIf(showOverflowMenu)
if (showOverflowMenu) {
overflow_menu_icon.beVisibleIf(showShowOverflowMenu)
if (showShowOverflowMenu) {
overflow_menu_icon.drawable.apply {
mutate()
setTint(activity.getProperTextColor())
@ -375,49 +380,59 @@ class RecentCallsAdapter(
callContact()
}
}
R.id.cab_call_sim_1 -> {
executeItemMenuOperation(callId) {
callContact(true)
}
}
R.id.cab_call_sim_2 -> {
executeItemMenuOperation(callId) {
callContact(false)
}
}
R.id.cab_send_sms -> {
executeItemMenuOperation(callId) {
sendSMS()
}
}
R.id.cab_view_details -> {
executeItemMenuOperation(callId) {
launchContactDetailsIntent(contact)
}
}
R.id.cab_add_number -> {
executeItemMenuOperation(callId) {
addNumberToContact()
}
}
R.id.cab_show_call_details -> {
executeItemMenuOperation(callId) {
showCallDetails()
}
}
R.id.cab_block_number -> {
selectedKeys.add(callId)
tryBlocking()
}
R.id.cab_remove -> {
selectedKeys.add(callId)
askConfirmRemove()
}
R.id.cab_copy_number -> {
executeItemMenuOperation(callId) {
copyNumber()
}
}
R.id.cab_remove_default_sim -> {
executeItemMenuOperation(callId) {
removeDefaultSIM()

View File

@ -179,22 +179,19 @@ private fun List<RecentCall>.hidePrivateContacts(privateContacts: ArrayList<Cont
}
private fun ArrayList<RecentCall>.setNamesIfEmpty(contacts: ArrayList<Contact>, privateContacts: ArrayList<Contact>): ArrayList<RecentCall> {
filter { it.phoneNumber == it.name }.forEach { recent ->
var wasNameFilled = false
if (privateContacts.isNotEmpty()) {
val contactsWithNumbers = contacts.filter { it.phoneNumbers.isNotEmpty() }
return map { recent ->
if (recent.phoneNumber == recent.name) {
val privateContact = privateContacts.firstOrNull { it.doesContainPhoneNumber(recent.phoneNumber) }
if (privateContact != null) {
recent.name = privateContact.getNameToDisplay()
wasNameFilled = true
}
}
val contact = contactsWithNumbers.firstOrNull { it.phoneNumbers.first().normalizedNumber == recent.phoneNumber }
if (!wasNameFilled) {
val contact = contacts.filter { it.phoneNumbers.isNotEmpty() }.firstOrNull { it.phoneNumbers.first().normalizedNumber == recent.phoneNumber }
if (contact != null) {
recent.name = contact.getNameToDisplay()
when {
privateContact != null -> recent.copy(name = privateContact.getNameToDisplay())
contact != null -> recent.copy(name = contact.getNameToDisplay())
else -> recent
}
} else {
recent
}
}
return this
} as ArrayList
}

View File

@ -82,16 +82,25 @@ class RecentsHelper(private val context: Context) {
}
}
if (cursor?.moveToFirst() == true) {
cursor?.use {
if (!cursor.moveToFirst()) {
return@use
}
do {
val id = cursor.getIntValue(Calls._ID)
val number = cursor.getStringValue(Calls.NUMBER) ?: continue
var name = cursor.getStringValue(Calls.CACHED_NAME)
if (name == null || name.isEmpty()) {
var isUnknownNumber = false
var number = cursor.getStringValueOrNull(Calls.NUMBER)
if (number == null) {
number = context.getString(R.string.unknown)
isUnknownNumber = true
}
var name = cursor.getStringValueOrNull(Calls.CACHED_NAME)
if (name.isNullOrEmpty()) {
name = number
}
if (name == number) {
if (name == number && !isUnknownNumber) {
if (contactsNumbersMap.containsKey(number)) {
name = contactsNumbersMap[number]!!
} else {
@ -100,7 +109,10 @@ class RecentsHelper(private val context: Context) {
name = contacts.filter { it.phoneNumbers.isNotEmpty() }.firstOrNull { contact ->
val curNumber = contact.phoneNumbers.first().normalizedNumber
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.getNameToDisplay()
return@firstOrNull true
}
@ -153,7 +165,20 @@ class RecentsHelper(private val context: Context) {
}
}
val recentCall = RecentCall(id, number, name, photoUri, startTS, duration, type, neighbourIDs, simID, specificNumber, specificType)
val recentCall = RecentCall(
id = id,
phoneNumber = number,
name = name,
photoUri = photoUri,
startTS = startTS,
duration = duration,
type = type,
neighbourIDs = neighbourIDs,
simID = simID,
specificNumber = specificNumber,
specificType = specificType,
isUnknownNumber = isUnknownNumber
)
// if we have multiple missed calls from the same number, show it just once
if (!groupSubsequentCalls || "$number$name$simID" != previousRecentCallFrom) {
@ -165,7 +190,6 @@ class RecentsHelper(private val context: Context) {
previousRecentCallFrom = "$number$name$simID"
} while (cursor.moveToNext() && recentCalls.size < maxSize)
}
cursor?.close()
val blockedNumbers = context.getBlockedNumbers()
recentCalls = recentCalls.filter { !context.isNumberBlocked(it.phoneNumber, blockedNumbers) }.toMutableList() as ArrayList<RecentCall>

View File

@ -5,8 +5,18 @@ import com.simplemobiletools.commons.extensions.normalizePhoneNumber
// model used at displaying recent calls, for contacts with multiple numbers specifify the number and type
data class RecentCall(
var id: Int, var phoneNumber: String, var name: String, var photoUri: String, var startTS: Int, var duration: Int, var type: Int,
var neighbourIDs: ArrayList<Int>, val simID: Int, var specificNumber: String, var specificType: String
val id: Int,
val phoneNumber: String,
val name: String,
val photoUri: String,
val startTS: Int,
val duration: Int,
val type: Int,
val neighbourIDs: ArrayList<Int>,
val simID: Int,
val specificNumber: String,
val specificType: String,
val isUnknownNumber: Boolean,
) {
fun doesContainPhoneNumber(text: String): Boolean {
val normalizedText = text.normalizePhoneNumber()