Unverified Commit 77610e63 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito Committed by GitHub

Merge pull request #642 from filipedelimabrito/feature/support-viewing-image

[Feature] Support viewing image
parents 7313b7bc 3e1cd538
......@@ -63,13 +63,15 @@ dependencies {
implementation libraries.okhttp
implementation libraries.okhttpLogger
implementation libraries.timber
implementation libraries.threeTenABP
implementation libraries.fresco
implementation libraries.frescoAnimatedGif
implementation libraries.frescoWebP
implementation libraries.frescoAnimatedWebP
implementation libraries.timber
implementation libraries.threeTenABP
implementation libraries.frescoImageViewer
implementation libraries.floatingSearchView
......
......@@ -3,4 +3,7 @@ package chat.rocket.android.app.chatroom
import chat.rocket.android.app.User
import org.threeten.bp.LocalDateTime
data class Message(val user: User, val content: String, val localDatetime: LocalDateTime)
\ No newline at end of file
data class Message(val user: User,
val textContent: String?,
val imageAttachmentUri: String?,
val localDatetime: LocalDateTime)
\ No newline at end of file
......@@ -22,11 +22,24 @@ class MessageFragment : Fragment() {
// This is just a sample showing 2 messages in the chat room. We need to get it rid in a real word. REMARK: remove this comment and this method.
private fun createDumpData(): List<Message> {
val user1 = User("1", "Filipe Brito", "filipe.brito", "online", "https://open.rocket.chat/avatar/filipe.brito")
val user2 = User("2", "Lucio Maciel", "Lucio Maciel", "busy", "https://open.rocket.chat/avatar/lucio.maciel")
val user1 = User("1",
"Filipe Brito",
"filipe.brito",
"online",
"https://open.rocket.chat/avatar/filipe.brito")
val user2 = User("2",
"Lucio Maciel",
"Lucio Maciel",
"busy",
"https://open.rocket.chat/avatar/lucio.maciel")
val message1 = Message(user1, "This is a multiline chat message from Bertie that will take more than just one line of text. I have sure that everything is amazing!", LocalDateTime.now())
val message2 = Message(user2, "Great!", LocalDateTime.now().plusHours(1))
val message1 = Message(user1,
"This is a multiline chat message from Bertie that will take more than just one line of text. I have sure that everything is amazing!",
"https://rocket.chat/images/index/livechat.png",
LocalDateTime.now())
val message2 = Message(user2, "Great!",
"https://rocket.chat/images/index/screenshot.png",
LocalDateTime.now().plusHours(1))
return listOf(message1, message2)
}
......@@ -34,7 +47,7 @@ class MessageFragment : Fragment() {
private fun showMessageList(dataSet: List<Message>) {
activity?.apply {
recycler_view.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
recycler_view.adapter = MessageListAdapter(dataSet.toMutableList())
recycler_view.adapter = MessageListAdapter(this, dataSet.toMutableList()) {}
}
}
}
\ No newline at end of file
package chat.rocket.android.app.chatroom
import DateTimeHelper
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
......@@ -8,9 +9,10 @@ import android.view.ViewGroup
import android.widget.TextView
import chat.rocket.android.R
import com.facebook.drawee.view.SimpleDraweeView
import com.stfalcon.frescoimageviewer.ImageViewer
import kotlinx.android.synthetic.main.item_message.view.*
class MessageListAdapter(private var dataSet: MutableList<Message>) : RecyclerView.Adapter<MessageListAdapter.ViewHolder>() {
class MessageListAdapter(private val context: Context, private var dataSet: MutableList<Message>, private val listener: (Message) -> Unit) : RecyclerView.Adapter<MessageListAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_message, parent, false)
......@@ -23,7 +25,25 @@ class MessageListAdapter(private var dataSet: MutableList<Message>) : RecyclerVi
holder.userAvatar.setImageURI(message.user.avatarUri)
holder.userName.text = message.user.name
holder.time.text = DateTimeHelper.getTime(message.localDatetime)
holder.content.text = message.content
val textContent = message.textContent
if (textContent.isNullOrBlank()) {
holder.textContent.visibility = View.GONE
} else {
holder.textContent.text = textContent
}
val imageAttachmentUri = message.imageAttachmentUri
if (imageAttachmentUri.isNullOrBlank()) {
holder.imageAttachment.visibility = View.GONE
} else {
holder.imageAttachment.setImageURI(imageAttachmentUri)
holder.imageAttachment.setOnClickListener({
ImageViewer.Builder(context, listOf(imageAttachmentUri))
.hideStatusBar(false)
.show()
})
}
}
override fun getItemCount(): Int = dataSet.size
......@@ -32,6 +52,9 @@ class MessageListAdapter(private var dataSet: MutableList<Message>) : RecyclerVi
val userAvatar: SimpleDraweeView = itemView.image_user_avatar
val userName: TextView = itemView.text_user_name
val time: TextView = itemView.text_message_time
val content: TextView = itemView.text_content
val textContent: TextView = itemView.text_content
val imageAttachment: SimpleDraweeView = itemView.image_attachment
}
}
\ No newline at end of file
......@@ -54,4 +54,13 @@
app:layout_constraintTop_toBottomOf="@+id/top_container"
tools:text="This is a multiline chat message from Bertie that will take more than just one line of text. I have sure that everything is amazing!" />
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/image_attachment"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_marginTop="5dp"
app:layout_constraintLeft_toLeftOf="@id/top_container"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_content" />
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
......@@ -20,9 +20,10 @@ ext {
rxandroid : '2.0.1',
moshi : '1.6.0-SNAPSHOT',
okhttp : '3.9.0',
fresco : '1.5.0',
timber : '4.5.1',
threeTenABP : '1.0.5',
fresco : '1.5.0',
frescoImageViewer : '0.5.0',
floatingSearchView: '2.1.1',
androidSvg : '1.2.1',
......@@ -63,13 +64,15 @@ ext {
okhttp : "com.squareup.okhttp3:okhttp:${versions.okhttp}",
okhttpLogger : "com.squareup.okhttp3:logging-interceptor:${versions.okhttp}",
timber : "com.jakewharton.timber:timber:${versions.timber}",
threeTenABP : "com.jakewharton.threetenabp:threetenabp:${versions.threeTenABP}",
fresco : "com.facebook.fresco:fresco:${versions.fresco}",
frescoAnimatedGif : "com.facebook.fresco:animated-gif:${versions.fresco}",
frescoWebP : "com.facebook.fresco:webpsupport:${versions.fresco}",
frescoAnimatedWebP : "com.facebook.fresco:animated-webp:${versions.fresco}",
timber : "com.jakewharton.timber:timber:${versions.timber}",
threeTenABP : "com.jakewharton.threetenabp:threetenabp:${versions.threeTenABP}",
frescoImageViewer : "com.github.stfalcon:frescoimageviewer:${versions.frescoImageViewer}",
floatingSearchView : "com.github.arimorty:floatingsearchview:${versions.floatingSearchView}",
......
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