|
|
@ -1,17 +1,23 @@
|
|
|
|
package org.thoughtcrime.securesms.conversation.v2.messages
|
|
|
|
package org.thoughtcrime.securesms.conversation.v2.messages
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Context
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
import android.graphics.Canvas
|
|
|
|
import android.graphics.Canvas
|
|
|
|
import android.graphics.drawable.Drawable
|
|
|
|
import android.graphics.drawable.Drawable
|
|
|
|
|
|
|
|
import android.net.Uri
|
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.ViewOutlineProvider
|
|
|
|
import android.view.ViewOutlineProvider
|
|
|
|
import android.widget.LinearLayout
|
|
|
|
import android.widget.LinearLayout
|
|
|
|
|
|
|
|
import android.widget.Toast
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import androidx.core.content.res.ResourcesCompat
|
|
|
|
import androidx.core.content.res.ResourcesCompat
|
|
|
|
import kotlinx.android.synthetic.main.view_link_preview.view.*
|
|
|
|
import kotlinx.android.synthetic.main.view_link_preview.view.*
|
|
|
|
import network.loki.messenger.R
|
|
|
|
import network.loki.messenger.R
|
|
|
|
import org.thoughtcrime.securesms.components.CornerMask
|
|
|
|
import org.thoughtcrime.securesms.components.CornerMask
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.conversation.v2.dialogs.OpenURLDialog
|
|
|
|
import org.thoughtcrime.securesms.conversation.v2.utilities.MessageBubbleUtilities
|
|
|
|
import org.thoughtcrime.securesms.conversation.v2.utilities.MessageBubbleUtilities
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord
|
|
|
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
|
|
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
|
|
|
import org.thoughtcrime.securesms.loki.utilities.UiModeUtilities
|
|
|
|
import org.thoughtcrime.securesms.loki.utilities.UiModeUtilities
|
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
|
|
@ -19,6 +25,7 @@ import org.thoughtcrime.securesms.mms.ImageSlide
|
|
|
|
|
|
|
|
|
|
|
|
class LinkPreviewView : LinearLayout {
|
|
|
|
class LinkPreviewView : LinearLayout {
|
|
|
|
private val cornerMask by lazy { CornerMask(this) }
|
|
|
|
private val cornerMask by lazy { CornerMask(this) }
|
|
|
|
|
|
|
|
private var url: String? = null
|
|
|
|
|
|
|
|
|
|
|
|
// region Lifecycle
|
|
|
|
// region Lifecycle
|
|
|
|
constructor(context: Context) : super(context) { initialize() }
|
|
|
|
constructor(context: Context) : super(context) { initialize() }
|
|
|
@ -32,11 +39,9 @@ class LinkPreviewView : LinearLayout {
|
|
|
|
|
|
|
|
|
|
|
|
// region Updating
|
|
|
|
// region Updating
|
|
|
|
fun bind(message: MmsMessageRecord, glide: GlideRequests, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean) {
|
|
|
|
fun bind(message: MmsMessageRecord, glide: GlideRequests, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean) {
|
|
|
|
mainLinkPreviewContainer.background = background
|
|
|
|
|
|
|
|
mainLinkPreviewContainer.outlineProvider = ViewOutlineProvider.BACKGROUND
|
|
|
|
|
|
|
|
mainLinkPreviewContainer.clipToOutline = true
|
|
|
|
|
|
|
|
// Thumbnail
|
|
|
|
|
|
|
|
val linkPreview = message.linkPreviews.first()
|
|
|
|
val linkPreview = message.linkPreviews.first()
|
|
|
|
|
|
|
|
url = linkPreview.url
|
|
|
|
|
|
|
|
// Thumbnail
|
|
|
|
if (linkPreview.getThumbnail().isPresent) {
|
|
|
|
if (linkPreview.getThumbnail().isPresent) {
|
|
|
|
// This internally fetches the thumbnail
|
|
|
|
// This internally fetches the thumbnail
|
|
|
|
thumbnailImageView.setImageResource(glide, ImageSlide(context, linkPreview.getThumbnail().get()), false, false)
|
|
|
|
thumbnailImageView.setImageResource(glide, ImageSlide(context, linkPreview.getThumbnail().get()), false, false)
|
|
|
@ -65,4 +70,12 @@ class LinkPreviewView : LinearLayout {
|
|
|
|
cornerMask.mask(canvas)
|
|
|
|
cornerMask.mask(canvas)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// region Interaction
|
|
|
|
|
|
|
|
fun openURL() {
|
|
|
|
|
|
|
|
val url = this.url ?: return
|
|
|
|
|
|
|
|
val activity = context as AppCompatActivity
|
|
|
|
|
|
|
|
OpenURLDialog(url).show(activity.supportFragmentManager, "Open URL Dialog")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// endregion
|
|
|
|
}
|
|
|
|
}
|