UrlPreviewViewHolder.kt 1.23 KB
Newer Older
1 2 3 4 5 6 7
package chat.rocket.android.chatroom.adapter

import android.content.Intent
import android.net.Uri
import android.view.View
import chat.rocket.android.chatroom.viewmodel.UrlPreviewViewModel
import chat.rocket.android.util.extensions.content
8
import chat.rocket.android.util.extensions.setVisible
9 10
import kotlinx.android.synthetic.main.message_url_preview.view.*

11 12 13 14 15 16 17 18 19
class UrlPreviewViewHolder(itemView: View, listener: ActionsListener)
    : BaseViewHolder<UrlPreviewViewModel>(itemView, listener) {

    init {
        with(itemView) {
            setupActionMenu(url_preview_layout)
        }
    }

20 21
    override fun bindViews(data: UrlPreviewViewModel) {
        with(itemView) {
22 23 24 25 26 27
            if (data.thumbUrl.isNullOrEmpty()) {
                image_preview.setVisible(false)
            } else {
                image_preview.setImageURI(data.thumbUrl)
                image_preview.setVisible(true)
            }
28 29
            text_host.content = data.hostname
            text_title.content = data.title
30
            text_description.content = data.description ?: ""
31 32 33 34 35 36 37 38

            url_preview_layout.setOnClickListener { view ->
                view.context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(data.rawData.url)))
            }
        }
    }

}