From 9860b8118cb52d3f1900ca89202593f449d267b7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 29 Apr 2020 20:27:04 +0200 Subject: [PATCH] do not try inserting the contact thumbnail, it will be generated --- .../contacts/pro/helpers/ContactsHelper.kt | 36 +++++-------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt index 3702d7b2..97b8d7f3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt @@ -1301,43 +1301,25 @@ class ContactsHelper(val context: Context) { // photo (inspired by https://gist.github.com/slightfoot/5985900) var fullSizePhotoData: ByteArray? = null - var scaledSizePhotoData: ByteArray? if (contact.photoUri.isNotEmpty()) { val photoUri = Uri.parse(contact.photoUri) val bitmap = MediaStore.Images.Media.getBitmap(context.contentResolver, photoUri) - val thumbnailSize = context.getPhotoThumbnailSize() - val scaledPhoto = Bitmap.createScaledBitmap(bitmap, thumbnailSize, thumbnailSize, false) - scaledSizePhotoData = scaledPhoto.getByteArray() - fullSizePhotoData = bitmap.getByteArray() - scaledPhoto.recycle() bitmap.recycle() - - ContentProviderOperation.newInsert(Data.CONTENT_URI).apply { - withValueBackReference(Data.RAW_CONTACT_ID, 0) - withValue(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE) - withValue(Photo.PHOTO, scaledSizePhotoData) - operations.add(build()) - } } - val results: Array - try { - results = context.contentResolver.applyBatch(AUTHORITY, operations) + val results = context.contentResolver.applyBatch(AUTHORITY, operations) - // storing contacts on some devices seems to be messed up and they move on Phone instead, or disappear completely - // try storing a lighter contact version with this oldschool version too just so it wont disappear, future edits work well - if (getContactSourceType(contact.source).contains(".sim")) { - val simUri = Uri.parse("content://icc/adn") - ContentValues().apply { - put("number", contact.phoneNumbers.firstOrNull()?.value ?: "") - put("tag", contact.getNameToDisplay()) - context.contentResolver.insert(simUri, this) - } + // storing contacts on some devices seems to be messed up and they move on Phone instead, or disappear completely + // try storing a lighter contact version with this oldschool version too just so it wont disappear, future edits work well + if (getContactSourceType(contact.source).contains(".sim")) { + val simUri = Uri.parse("content://icc/adn") + ContentValues().apply { + put("number", contact.phoneNumbers.firstOrNull()?.value ?: "") + put("tag", contact.getNameToDisplay()) + context.contentResolver.insert(simUri, this) } - } finally { - scaledSizePhotoData = null } // fullsize photo