fix #59, properly fetch contact photos at Recents tab

This commit is contained in:
tibbi 2021-07-25 21:35:33 +02:00
parent 5b339eec5b
commit eabbf41ab7
1 changed files with 15 additions and 3 deletions

View File

@ -3,10 +3,8 @@ package com.simplemobiletools.dialer.helpers
import android.annotation.SuppressLint
import android.content.ContentResolver
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.provider.CallLog.Calls
import androidx.annotation.RequiresApi
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.SimpleContact
@ -44,6 +42,8 @@ class RecentsHelper(private val context: Context) {
var previousRecentCallFrom = ""
var previousStartTS = 0
val contactsNumbersMap = HashMap<String, String>()
val contactPhotosMap = HashMap<String, String>()
val uri = Calls.CONTENT_URI
val projection = arrayOf(
Calls._ID,
@ -107,7 +107,19 @@ class RecentsHelper(private val context: Context) {
name = context.getString(R.string.unknown)
}
val photoUri = cursor.getStringValue(Calls.CACHED_PHOTO_URI) ?: ""
var photoUri = cursor.getStringValue(Calls.CACHED_PHOTO_URI) ?: ""
if (photoUri.isEmpty()) {
if (contactPhotosMap.containsKey(number)) {
photoUri = contactPhotosMap[number]!!
} else {
val contact = contacts.firstOrNull { it.doesContainPhoneNumber(number) }
if (contact != null) {
photoUri = contact.photoUri
contactPhotosMap[number] = contact.photoUri
}
}
}
val startTS = (cursor.getLongValue(Calls.DATE) / 1000L).toInt()
if (previousStartTS == startTS) {
continue