Commit 717824a7 authored by Lucio Maciel's avatar Lucio Maciel

Guggy gif attachments

parent dc3ed63a
......@@ -2,6 +2,8 @@ package chat.rocket.android.chatroom.adapter
import android.view.View
import chat.rocket.android.chatroom.viewmodel.ImageAttachmentViewModel
import com.facebook.drawee.backends.pipeline.Fresco
import com.facebook.drawee.interfaces.DraweeController
import com.stfalcon.frescoimageviewer.ImageViewer
import kotlinx.android.synthetic.main.message_attachment.view.*
......@@ -17,12 +19,21 @@ class ImageAttachmentViewHolder(itemView: View, listener: ActionsListener)
override fun bindViews(data: ImageAttachmentViewModel) {
with(itemView) {
image_attachment.setImageURI(data.attachmentUrl)
val controller = Fresco.newDraweeControllerBuilder().apply {
setUri(data.attachmentUrl)
autoPlayAnimations = true
oldController = image_attachment.controller
}.build()
image_attachment.controller = controller
file_name.text = data.attachmentTitle
image_attachment.setOnClickListener { view ->
// TODO - implement a proper image viewer with a proper Transition
val builder = ImageViewer.createPipelineDraweeControllerBuilder()
.setAutoPlayAnimations(true)
ImageViewer.Builder(view.context, listOf(data.attachmentUrl))
.setStartPosition(0)
.hideStatusBar(false)
.setCustomDraweeControllerBuilder(builder)
.show()
}
}
......
......@@ -94,16 +94,20 @@ class ViewModelMapper @Inject constructor(private val context: Context,
}
private fun mapFileAttachment(message: Message, attachment: FileAttachment): BaseViewModel<*>? {
val attachmentUrl = attachmentUrl("$baseUrl${attachment.url}")
val attachmentTitle = attachment.title
val id = "${message.id}_${attachment.titleLink}".hashCode().toLong()
val attachmentUrl = if (attachment.url.startsWith("http")) {
attachment.url
} else {
attachmentUrl("$baseUrl${attachment.url}")
}
val attachmentTitle = attachment.attachmentTitle
val id = "${message.id}_${attachment.url}".hashCode().toLong()
return when (attachment) {
is ImageAttachment -> ImageAttachmentViewModel(message, attachment, message.id,
attachmentUrl, attachmentTitle ?: "", id)
attachmentUrl, attachmentTitle, id)
is VideoAttachment -> VideoAttachmentViewModel(message, attachment, message.id,
attachmentUrl, attachmentTitle ?: "", id)
attachmentUrl, attachmentTitle, id)
is AudioAttachment -> AudioAttachmentViewModel(message, attachment, message.id,
attachmentUrl, attachmentTitle ?: "", id)
attachmentUrl, attachmentTitle, id)
else -> null
}
}
......@@ -281,4 +285,16 @@ class ViewModelMapper @Inject constructor(private val context: Context,
})
}
}
}
\ No newline at end of file
}
internal val FileAttachment.attachmentTitle: String
get() {
title?.let { return it }
val fileUrl = HttpUrl.parse(url)
fileUrl?.let {
return it.pathSegments().last()
}
return ""
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ ext {
rxBinding : '2.0.0',
fresco : '1.8.1',
kotshi : '0.3.0',
frescoImageViewer : '0.5.0',
frescoImageViewer : '0.5.1',
androidSvg : 'master-SNAPSHOT',
markwon : '1.0.3',
sheetMenu : '1.3.3',
......@@ -84,7 +84,7 @@ ext {
kotshiApi : "se.ansman.kotshi:api:${versions.kotshi}",
kotshiCompiler : "se.ansman.kotshi:compiler:${versions.kotshi}",
frescoImageViewer : "com.github.stfalcon:frescoimageviewer:${versions.frescoImageViewer}",
frescoImageViewer : "com.github.luciofm:FrescoImageViewer:${versions.frescoImageViewer}",
androidSvg : "com.github.BigBadaboom:androidsvg:${versions.androidSvg}",
markwon : "ru.noties:markwon:${versions.markwon}",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment