From d31b93d8509d3bdb19429cbe9b9537e38e18bfaf Mon Sep 17 00:00:00 2001 From: Vasyl Glodan Date: Sat, 24 Mar 2018 17:13:47 +0200 Subject: [PATCH] Fixed images scaling --- app/build.gradle | 4 ++-- .../ui/viewmodel/converter/ChatMessageConverter.kt | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 334ad10d..2ba0a64d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,5 @@ -def final VERSION_CODE = 13 -def final VERSION_NAME = '1.0.0' +def final VERSION_CODE = 14 +def final VERSION_NAME = '1.0.1' apply plugin: 'com.android.application' apply plugin: 'kotlin-android' diff --git a/app/src/main/kotlin/com/glodanif/bluetoothchat/ui/viewmodel/converter/ChatMessageConverter.kt b/app/src/main/kotlin/com/glodanif/bluetoothchat/ui/viewmodel/converter/ChatMessageConverter.kt index 70bce93b..ccbad196 100644 --- a/app/src/main/kotlin/com/glodanif/bluetoothchat/ui/viewmodel/converter/ChatMessageConverter.kt +++ b/app/src/main/kotlin/com/glodanif/bluetoothchat/ui/viewmodel/converter/ChatMessageConverter.kt @@ -21,11 +21,14 @@ class ChatMessageConverter(private val context: Context, private val displayMetr val info = message.fileInfo val actualSize = info?.split("x") - var width = (displayMetrics.widthPixels * .5).toInt() + var width = displayMetrics.widthPixels / 2 var height = width - if (info != null && actualSize != null && actualSize.size == 2 && actualSize[0].toInt() >= 0 && actualSize[1].toInt() >= 0) { - width = actualSize[0].toInt() - height = actualSize[1].toInt() + if (info != null && actualSize != null && actualSize.size == 2) { + val scaledSize = getScaledSize(actualSize[0].toInt(), actualSize[1].toInt()) + if (scaledSize.width >= 0 && scaledSize.height >= 0) { + width = scaledSize.width + height = scaledSize.height + } } return ChatMessageViewModel(