mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Should fix black avatar for chat rooms & conferences if there is a picture set for a contact but that file can't be read for some reason
This commit is contained in:
parent
559397d420
commit
cacaf29771
3 changed files with 42 additions and 9 deletions
|
|
@ -416,8 +416,13 @@ private fun loadContactPictureWithCoil(
|
|||
AppUtils.getDimension(R.dimen.avatar_list_cell_size).toInt()
|
||||
}
|
||||
val bitmap = ImageUtils.getBitmapFromMultipleAvatars(imageView.context, w, images)
|
||||
imageView.load(bitmap) {
|
||||
transformations(CircleCropTransformation())
|
||||
if (bitmap != null) {
|
||||
imageView.load(bitmap) {
|
||||
transformations(CircleCropTransformation())
|
||||
}
|
||||
} else {
|
||||
val initials = model.initials.value.orEmpty()
|
||||
imageView.load(ImageUtils.getGeneratedAvatar(context, size, textSize, initials))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,6 +115,10 @@ class ImageUtils {
|
|||
"$TAG Found at [${list.size}] participant(s) with a picture for conversation [$id]($hash), creating avatar"
|
||||
)
|
||||
val bitmap = generateBitmapFromList(list)
|
||||
if (bitmap == null) {
|
||||
Log.e("$TAG Avatar couldn't be generated")
|
||||
return ""
|
||||
}
|
||||
val outputStream: OutputStream = FileOutputStream(file)
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream)
|
||||
outputStream.close()
|
||||
|
|
@ -130,13 +134,13 @@ class ImageUtils {
|
|||
}
|
||||
|
||||
@WorkerThread
|
||||
fun generateBitmapFromList(list: ArrayList<String>): Bitmap {
|
||||
fun generateBitmapFromList(list: ArrayList<String>): Bitmap? {
|
||||
val size = AppUtils.getDimension(R.dimen.avatar_in_call_size).toInt()
|
||||
return getBitmapFromMultipleAvatars(coreContext.context, size, list)
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
fun getBitmapFromMultipleAvatars(context: Context, size: Int, images: List<String>): Bitmap {
|
||||
fun getBitmapFromMultipleAvatars(context: Context, size: Int, images: List<String>): Bitmap? {
|
||||
val drawables = images.mapNotNull {
|
||||
try {
|
||||
val uri = Uri.parse(it)
|
||||
|
|
@ -148,10 +152,18 @@ class ImageUtils {
|
|||
null
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("$TAG Failed to get scaled bitmap for URI [$it]")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
if (drawables.isEmpty()) {
|
||||
Log.e("$TAG Drawables list is empty, can't generate bitmap without at least one")
|
||||
return null
|
||||
} else {
|
||||
Log.i("$TAG Generating avatar using [${drawables.size}] drawables")
|
||||
}
|
||||
|
||||
val rectangles = if (drawables.size == 2) {
|
||||
arrayListOf(
|
||||
Rect(0, 0, size / 2, size),
|
||||
|
|
@ -187,7 +199,7 @@ class ImageUtils {
|
|||
val quarter = size / 4
|
||||
Rect(quarter, 0, 3 * quarter, size)
|
||||
} else {
|
||||
null
|
||||
Rect(0, 0, size, size)
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -415,9 +415,13 @@ class LinphoneUtils {
|
|||
fakeFriend.address = conferenceInfo.uri
|
||||
fakeFriend.name = conferenceInfo.subject
|
||||
|
||||
var avatarFound = true
|
||||
val hash = conferenceInfo.uri?.asStringUriOnly().hashCode().toString()
|
||||
val file = FileUtils.getFileStorageCacheDir("$hash.jpg", overrideExisting = true)
|
||||
if (!file.exists()) {
|
||||
avatarFound = false
|
||||
Log.w("$TAG File [${file.absolutePath}] doesn't exist yet, trying to generate it")
|
||||
|
||||
val list = arrayListOf<String>()
|
||||
for (participant in conferenceInfo.participantInfos) {
|
||||
val friend = coreContext.contactsManager.findContactByAddress(
|
||||
|
|
@ -432,13 +436,25 @@ class LinphoneUtils {
|
|||
}
|
||||
if (list.isNotEmpty()) {
|
||||
val bitmap = ImageUtils.generateBitmapFromList(list)
|
||||
val outputStream: OutputStream = FileOutputStream(file)
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream)
|
||||
outputStream.close()
|
||||
if (bitmap != null) {
|
||||
val outputStream: OutputStream = FileOutputStream(file)
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream)
|
||||
outputStream.close()
|
||||
avatarFound = true
|
||||
Log.i("$TAG Generated avatar and stored it in [${file.absolutePath}]")
|
||||
} else {
|
||||
Log.w("$TAG Can't generate avatar from that participants list")
|
||||
}
|
||||
} else {
|
||||
Log.w(
|
||||
"$TAG Can't generate avatar as no participant was found with an available picture"
|
||||
)
|
||||
}
|
||||
}
|
||||
fakeFriend.photo = FileUtils.getProperFilePath(file.absolutePath)
|
||||
|
||||
if (avatarFound) {
|
||||
fakeFriend.photo = FileUtils.getProperFilePath(file.absolutePath)
|
||||
}
|
||||
val avatarModel = ContactAvatarModel(fakeFriend)
|
||||
avatarModel.defaultToConferenceIcon.postValue(true)
|
||||
avatarModel.skipInitials.postValue(true)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue