Skip to content

Commit

Permalink
Fixed isue with negative image size
Browse files Browse the repository at this point in the history
  • Loading branch information
glodanif committed Mar 24, 2018
1 parent 0f4c1c5 commit 9143a20
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,20 @@ class ChatAdapter(private val context: Context) : RecyclerView.Adapter<RecyclerV
holder?.image?.visibility = View.VISIBLE
holder?.missingLabel?.visibility = View.GONE

if (message.imageSize != null) {

val size = message.imageSize
holder?.image?.layoutParams = FrameLayout.LayoutParams(size.width, size.height)
holder?.image?.setOnClickListener {
imageClickListener?.invoke(holder.image, message)
}

Picasso.with(context)
.load(message.imageUri)
.config(Bitmap.Config.RGB_565)
.error(R.color.background_image)
.placeholder(R.color.background_image)
.tag(picassoTag)
.resize(size.width, size.height)
.into(holder?.image)
val size = message.imageSize
holder?.image?.layoutParams = FrameLayout.LayoutParams(size.width, size.height)
holder?.image?.setOnClickListener {
imageClickListener?.invoke(holder.image, message)
}

Picasso.with(context)
.load(message.imageUri)
.config(Bitmap.Config.RGB_565)
.error(R.color.background_image)
.placeholder(R.color.background_image)
.tag(picassoTag)
.resize(size.width, size.height)
.into(holder?.image)
}

holder?.date?.text = message.date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class ChatMessageViewModel(
val isImageAvailable: Boolean,
@StringRes
val imageProblemText: Int,
val imageSize: Size?,
val imageSize: Size,
val imagePath: String?,
val imageUri: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ class ChatMessageConverter(private val context: Context, private val displayMetr

val info = message.fileInfo
val actualSize = info?.split("x")
var size: Size? = null
if (info != null && actualSize != null && actualSize.size == 2) {
size = getScaledSize(actualSize[0].toInt(), actualSize[1].toInt())
var width = (displayMetrics.widthPixels * .5).toInt()
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()
}

return ChatMessageViewModel(
Expand All @@ -34,7 +36,7 @@ class ChatMessageConverter(private val context: Context, private val displayMetr
message.messageType,
isImageAvailable,
problemString,
size,
Size(width, height),
message.filePath,
"file://${message.filePath}"
)
Expand Down

0 comments on commit 9143a20

Please sign in to comment.