2021-06-01 06:56:58 +02:00
|
|
|
package org.thoughtcrime.securesms.conversation.v2.messages
|
|
|
|
|
|
|
|
import android.content.Context
|
2021-06-22 01:34:23 +02:00
|
|
|
import android.graphics.Canvas
|
2021-06-21 08:13:21 +02:00
|
|
|
import android.graphics.Outline
|
|
|
|
import android.graphics.Path
|
|
|
|
import android.graphics.RectF
|
2021-06-22 01:34:23 +02:00
|
|
|
import android.graphics.drawable.Drawable
|
2021-06-21 08:13:21 +02:00
|
|
|
import android.os.Build
|
2021-06-01 06:56:58 +02:00
|
|
|
import android.util.AttributeSet
|
2021-06-21 08:13:21 +02:00
|
|
|
import android.util.Log
|
2021-06-01 06:56:58 +02:00
|
|
|
import android.view.LayoutInflater
|
2021-06-21 08:13:21 +02:00
|
|
|
import android.view.View
|
2021-06-21 07:26:09 +02:00
|
|
|
import android.view.ViewOutlineProvider
|
2021-06-01 06:56:58 +02:00
|
|
|
import android.widget.LinearLayout
|
|
|
|
import kotlinx.android.synthetic.main.view_link_preview.view.*
|
|
|
|
import network.loki.messenger.R
|
2021-06-21 07:26:09 +02:00
|
|
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
2021-06-01 06:56:58 +02:00
|
|
|
|
|
|
|
class LinkPreviewView : LinearLayout {
|
|
|
|
|
|
|
|
// region Lifecycle
|
2021-06-21 06:24:00 +02:00
|
|
|
constructor(context: Context) : super(context) { initialize() }
|
|
|
|
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { initialize() }
|
|
|
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { initialize() }
|
2021-06-01 06:56:58 +02:00
|
|
|
|
2021-06-21 06:24:00 +02:00
|
|
|
private fun initialize() {
|
2021-06-01 06:56:58 +02:00
|
|
|
LayoutInflater.from(context).inflate(R.layout.view_link_preview, this)
|
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
// region Updating
|
2021-06-22 01:34:23 +02:00
|
|
|
fun bind(message: MmsMessageRecord, glide: GlideRequests, background: Drawable) {
|
|
|
|
mainLinkPreviewContainer.background = background
|
|
|
|
mainLinkPreviewContainer.outlineProvider = ViewOutlineProvider.BACKGROUND
|
2021-06-21 08:13:21 +02:00
|
|
|
mainLinkPreviewContainer.clipToOutline = true
|
2021-06-21 07:26:09 +02:00
|
|
|
// Thumbnail
|
|
|
|
val linkPreview = message.linkPreviews.first()
|
|
|
|
// TODO: Handle downloading state
|
|
|
|
val uri = linkPreview.thumbnail.get().dataUri!!
|
|
|
|
glide.load(uri).into(thumbnailImageView)
|
|
|
|
// TODO: Properly use glide and the actual thumbnail
|
|
|
|
// Title
|
|
|
|
titleTextView.text = linkPreview.title
|
2021-06-22 01:34:23 +02:00
|
|
|
// Body
|
|
|
|
mainLinkPreviewContainer.addView(VisibleMessageContentView.getBodyTextView(context, message))
|
2021-06-01 06:56:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fun recycle() {
|
|
|
|
// TODO: Implement
|
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
}
|