fix #25, try harder at fetching the contact name in Recents

This commit is contained in:
tibbi
2020-05-21 21:40:53 +02:00
parent 7a48bb3044
commit 7e5a15bf28

View File

@ -5,6 +5,7 @@ import android.util.AttributeSet
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
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
@ -44,12 +45,22 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
override fun refreshItems() { override fun refreshItems() {
val privateCursor = context?.getMyContactsContentProviderCursorLoader()?.loadInBackground() val privateCursor = context?.getMyContactsContentProviderCursorLoader()?.loadInBackground()
RecentsHelper(context).getRecentCalls { recents -> RecentsHelper(context).getRecentCalls { recents ->
SimpleContactsHelper(context).getAvailableContacts(false) { contacts ->
val privateContacts = MyContactsContentProvider.getSimpleContacts(context, privateCursor) val privateContacts = MyContactsContentProvider.getSimpleContacts(context, privateCursor)
if (privateContacts.isNotEmpty()) {
recents.filter { it.phoneNumber == it.name }.forEach { recent -> recents.filter { it.phoneNumber == it.name }.forEach { recent ->
var wasNameFilled = false
if (privateContacts.isNotEmpty()) {
val privateContact = privateContacts.firstOrNull { it.phoneNumber == recent.phoneNumber } val privateContact = privateContacts.firstOrNull { it.phoneNumber == recent.phoneNumber }
if (privateContact != null) { if (privateContact != null) {
recent.name = privateContact.name recent.name = privateContact.name
wasNameFilled = true
}
}
if (!wasNameFilled) {
val contact = contacts.firstOrNull { it.phoneNumber == recent.phoneNumber }
if (contact != null) {
recent.name = contact.name
} }
} }
} }
@ -59,6 +70,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
} }
} }
} }
}
private fun gotRecents(recents: ArrayList<RecentCall>) { private fun gotRecents(recents: ArrayList<RecentCall>) {
if (recents.isEmpty()) { if (recents.isEmpty()) {