Skip to content

Commit

Permalink
Fallback to contact thumbnail if no photo available (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed May 29, 2023
1 parent 00f03d9 commit ee02da9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class DeviceContactsHelper(private val context: Context) : ContactsHelper() {

override suspend fun loadAdvancedData(contact: ContactData) = contact.apply {
thumbnail = getContactPhotoThumbnail(contactId)
photo = getContactPhoto(contactId)
photo = getContactPhoto(contactId) ?: thumbnail
groups = getGroups(contactId, storedContactGroups)
nickName = getEntry(contactId, Nickname.CONTENT_ITEM_TYPE, Nickname.NAME)
organization = getEntry(contactId, Organization.CONTENT_ITEM_TYPE, Organization.COMPANY)
Expand Down Expand Up @@ -606,14 +606,14 @@ class DeviceContactsHelper(private val context: Context) : ContactsHelper() {
val displayPhotoUri =
Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO)
return runCatching {
context.contentResolver.openAssetFileDescriptor(displayPhotoUri, "r").use { fd ->
BitmapFactory.decodeStream(fd!!.createInputStream())
context.contentResolver.openAssetFileDescriptor(displayPhotoUri, "r")?.use { fd ->
BitmapFactory.decodeStream(fd.createInputStream())
}
}.getOrNull()
}

private fun getBitmapBytes(bitmap: Bitmap): ByteArray {
var bytes: ByteArray = ImageHelper.bitmapToByteArray(bitmap)
var bytes = ImageHelper.bitmapToByteArray(bitmap)

// prevent crashes due to a too large transaction
if (bytes.size / 1024 > 900) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/bnyro/contacts/util/VcardHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ object VcardHelper {
addNote(note.value)
}
}
contact.photo?.let {
(contact.photo ?: contact.thumbnail)?.let {
val photo = Photo(ImageHelper.bitmapToByteArray(it), ImageType.PNG)
addPhoto(photo)
}
Expand Down

0 comments on commit ee02da9

Please sign in to comment.