mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
Added unknown phone calls visibility in Call History
This commit is contained in:
@ -107,7 +107,11 @@ class RecentCallsAdapter(
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
val recentCall = recentCalls[position]
|
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)
|
setupView(itemView, recentCall)
|
||||||
}
|
}
|
||||||
bindViewHolder(holder)
|
bindViewHolder(holder)
|
||||||
@ -274,6 +278,7 @@ class RecentCallsAdapter(
|
|||||||
private fun getSelectedPhoneNumber() = getSelectedItems().firstOrNull()?.phoneNumber
|
private fun getSelectedPhoneNumber() = getSelectedItems().firstOrNull()?.phoneNumber
|
||||||
|
|
||||||
private fun setupView(view: View, call: RecentCall) {
|
private fun setupView(view: View, call: RecentCall) {
|
||||||
|
val showShowOverflowMenu = showOverflowMenu && !call.isUnknownNumber
|
||||||
view.apply {
|
view.apply {
|
||||||
item_recents_holder.isSelected = selectedKeys.contains(call.id)
|
item_recents_holder.isSelected = selectedKeys.contains(call.id)
|
||||||
val name = findContactByCall(call)?.getNameToDisplay() ?: call.name
|
val name = findContactByCall(call)?.getNameToDisplay() ?: call.name
|
||||||
@ -312,7 +317,7 @@ class RecentCallsAdapter(
|
|||||||
setTextColor(textColor)
|
setTextColor(textColor)
|
||||||
beVisibleIf(call.type != Calls.MISSED_TYPE && call.type != Calls.REJECTED_TYPE && call.duration > 0)
|
beVisibleIf(call.type != Calls.MISSED_TYPE && call.type != Calls.REJECTED_TYPE && call.duration > 0)
|
||||||
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize * 0.8f)
|
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize * 0.8f)
|
||||||
if (!showOverflowMenu) {
|
if (!showShowOverflowMenu) {
|
||||||
item_recents_duration.setPadding(0, 0, durationPadding, 0)
|
item_recents_duration.setPadding(0, 0, durationPadding, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -335,8 +340,8 @@ class RecentCallsAdapter(
|
|||||||
|
|
||||||
item_recents_type.setImageDrawable(drawable)
|
item_recents_type.setImageDrawable(drawable)
|
||||||
|
|
||||||
overflow_menu_icon.beVisibleIf(showOverflowMenu)
|
overflow_menu_icon.beVisibleIf(showShowOverflowMenu)
|
||||||
if (showOverflowMenu) {
|
if (showShowOverflowMenu) {
|
||||||
overflow_menu_icon.drawable.apply {
|
overflow_menu_icon.drawable.apply {
|
||||||
mutate()
|
mutate()
|
||||||
setTint(activity.getProperTextColor())
|
setTint(activity.getProperTextColor())
|
||||||
@ -375,49 +380,59 @@ class RecentCallsAdapter(
|
|||||||
callContact()
|
callContact()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.cab_call_sim_1 -> {
|
R.id.cab_call_sim_1 -> {
|
||||||
executeItemMenuOperation(callId) {
|
executeItemMenuOperation(callId) {
|
||||||
callContact(true)
|
callContact(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.cab_call_sim_2 -> {
|
R.id.cab_call_sim_2 -> {
|
||||||
executeItemMenuOperation(callId) {
|
executeItemMenuOperation(callId) {
|
||||||
callContact(false)
|
callContact(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.cab_send_sms -> {
|
R.id.cab_send_sms -> {
|
||||||
executeItemMenuOperation(callId) {
|
executeItemMenuOperation(callId) {
|
||||||
sendSMS()
|
sendSMS()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.cab_view_details -> {
|
R.id.cab_view_details -> {
|
||||||
executeItemMenuOperation(callId) {
|
executeItemMenuOperation(callId) {
|
||||||
launchContactDetailsIntent(contact)
|
launchContactDetailsIntent(contact)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.cab_add_number -> {
|
R.id.cab_add_number -> {
|
||||||
executeItemMenuOperation(callId) {
|
executeItemMenuOperation(callId) {
|
||||||
addNumberToContact()
|
addNumberToContact()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.cab_show_call_details -> {
|
R.id.cab_show_call_details -> {
|
||||||
executeItemMenuOperation(callId) {
|
executeItemMenuOperation(callId) {
|
||||||
showCallDetails()
|
showCallDetails()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.cab_block_number -> {
|
R.id.cab_block_number -> {
|
||||||
selectedKeys.add(callId)
|
selectedKeys.add(callId)
|
||||||
tryBlocking()
|
tryBlocking()
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.cab_remove -> {
|
R.id.cab_remove -> {
|
||||||
selectedKeys.add(callId)
|
selectedKeys.add(callId)
|
||||||
askConfirmRemove()
|
askConfirmRemove()
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.cab_copy_number -> {
|
R.id.cab_copy_number -> {
|
||||||
executeItemMenuOperation(callId) {
|
executeItemMenuOperation(callId) {
|
||||||
copyNumber()
|
copyNumber()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.cab_remove_default_sim -> {
|
R.id.cab_remove_default_sim -> {
|
||||||
executeItemMenuOperation(callId) {
|
executeItemMenuOperation(callId) {
|
||||||
removeDefaultSIM()
|
removeDefaultSIM()
|
||||||
|
@ -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> {
|
private fun ArrayList<RecentCall>.setNamesIfEmpty(contacts: ArrayList<Contact>, privateContacts: ArrayList<Contact>): ArrayList<RecentCall> {
|
||||||
filter { it.phoneNumber == it.name }.forEach { recent ->
|
val contactsWithNumbers = contacts.filter { it.phoneNumbers.isNotEmpty() }
|
||||||
var wasNameFilled = false
|
return map { recent ->
|
||||||
if (privateContacts.isNotEmpty()) {
|
if (recent.phoneNumber == recent.name) {
|
||||||
val privateContact = privateContacts.firstOrNull { it.doesContainPhoneNumber(recent.phoneNumber) }
|
val privateContact = privateContacts.firstOrNull { it.doesContainPhoneNumber(recent.phoneNumber) }
|
||||||
if (privateContact != null) {
|
val contact = contactsWithNumbers.firstOrNull { it.phoneNumbers.first().normalizedNumber == recent.phoneNumber }
|
||||||
recent.name = privateContact.getNameToDisplay()
|
|
||||||
wasNameFilled = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!wasNameFilled) {
|
when {
|
||||||
val contact = contacts.filter { it.phoneNumbers.isNotEmpty() }.firstOrNull { it.phoneNumbers.first().normalizedNumber == recent.phoneNumber }
|
privateContact != null -> recent.copy(name = privateContact.getNameToDisplay())
|
||||||
if (contact != null) {
|
contact != null -> recent.copy(name = contact.getNameToDisplay())
|
||||||
recent.name = contact.getNameToDisplay()
|
else -> recent
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
recent
|
||||||
}
|
}
|
||||||
}
|
} as ArrayList
|
||||||
return this
|
|
||||||
}
|
}
|
||||||
|
@ -82,16 +82,25 @@ class RecentsHelper(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cursor?.moveToFirst() == true) {
|
cursor?.use {
|
||||||
|
if (!cursor.moveToFirst()) {
|
||||||
|
return@use
|
||||||
|
}
|
||||||
do {
|
do {
|
||||||
val id = cursor.getIntValue(Calls._ID)
|
val id = cursor.getIntValue(Calls._ID)
|
||||||
val number = cursor.getStringValue(Calls.NUMBER) ?: continue
|
var isUnknownNumber = false
|
||||||
var name = cursor.getStringValue(Calls.CACHED_NAME)
|
var number = cursor.getStringValueOrNull(Calls.NUMBER)
|
||||||
if (name == null || name.isEmpty()) {
|
if (number == null) {
|
||||||
|
number = context.getString(R.string.unknown)
|
||||||
|
isUnknownNumber = true
|
||||||
|
}
|
||||||
|
|
||||||
|
var name = cursor.getStringValueOrNull(Calls.CACHED_NAME)
|
||||||
|
if (name.isNullOrEmpty()) {
|
||||||
name = number
|
name = number
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == number) {
|
if (name == number && !isUnknownNumber) {
|
||||||
if (contactsNumbersMap.containsKey(number)) {
|
if (contactsNumbersMap.containsKey(number)) {
|
||||||
name = contactsNumbersMap[number]!!
|
name = contactsNumbersMap[number]!!
|
||||||
} else {
|
} else {
|
||||||
@ -100,7 +109,10 @@ class RecentsHelper(private val context: Context) {
|
|||||||
name = contacts.filter { it.phoneNumbers.isNotEmpty() }.firstOrNull { contact ->
|
name = contacts.filter { it.phoneNumbers.isNotEmpty() }.firstOrNull { contact ->
|
||||||
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.getNameToDisplay()
|
contactsNumbersMap[number] = contact.getNameToDisplay()
|
||||||
return@firstOrNull true
|
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 we have multiple missed calls from the same number, show it just once
|
||||||
if (!groupSubsequentCalls || "$number$name$simID" != previousRecentCallFrom) {
|
if (!groupSubsequentCalls || "$number$name$simID" != previousRecentCallFrom) {
|
||||||
@ -165,7 +190,6 @@ class RecentsHelper(private val context: Context) {
|
|||||||
previousRecentCallFrom = "$number$name$simID"
|
previousRecentCallFrom = "$number$name$simID"
|
||||||
} while (cursor.moveToNext() && recentCalls.size < maxSize)
|
} while (cursor.moveToNext() && recentCalls.size < maxSize)
|
||||||
}
|
}
|
||||||
cursor?.close()
|
|
||||||
|
|
||||||
val blockedNumbers = context.getBlockedNumbers()
|
val blockedNumbers = context.getBlockedNumbers()
|
||||||
recentCalls = recentCalls.filter { !context.isNumberBlocked(it.phoneNumber, blockedNumbers) }.toMutableList() as ArrayList<RecentCall>
|
recentCalls = recentCalls.filter { !context.isNumberBlocked(it.phoneNumber, blockedNumbers) }.toMutableList() as ArrayList<RecentCall>
|
||||||
|
@ -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
|
// model used at displaying recent calls, for contacts with multiple numbers specifify the number and type
|
||||||
data class RecentCall(
|
data class RecentCall(
|
||||||
var id: Int, var phoneNumber: String, var name: String, var photoUri: String, var startTS: Int, var duration: Int, var type: Int,
|
val id: Int,
|
||||||
var neighbourIDs: ArrayList<Int>, val simID: Int, var specificNumber: String, var specificType: String
|
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 {
|
fun doesContainPhoneNumber(text: String): Boolean {
|
||||||
val normalizedText = text.normalizePhoneNumber()
|
val normalizedText = text.normalizePhoneNumber()
|
||||||
|
Reference in New Issue
Block a user