diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt index b5afcf56d1..90e2a5be17 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt @@ -1,20 +1,20 @@ package org.thoughtcrime.securesms.conversation.v2.messages import android.content.Context -import android.graphics.drawable.Drawable +import android.graphics.Outline +import android.graphics.Path +import android.graphics.RectF +import android.os.Build import android.util.AttributeSet +import android.util.Log import android.view.LayoutInflater +import android.view.View import android.view.ViewOutlineProvider import android.widget.LinearLayout -import com.bumptech.glide.load.engine.DiskCacheStrategy -import com.bumptech.glide.load.resource.bitmap.CenterCrop -import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import kotlinx.android.synthetic.main.view_link_preview.view.* import network.loki.messenger.R import org.thoughtcrime.securesms.database.model.MmsMessageRecord -import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri import org.thoughtcrime.securesms.mms.GlideRequests -import org.thoughtcrime.securesms.mms.ImageSlide class LinkPreviewView : LinearLayout { @@ -29,7 +29,9 @@ class LinkPreviewView : LinearLayout { // endregion // region Updating - fun bind(message: MmsMessageRecord, glide: GlideRequests) { + fun bind(message: MmsMessageRecord, glide: GlideRequests, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean) { + mainLinkPreviewContainer.outlineProvider = getOutlineProvider(message.isOutgoing, isStartOfMessageCluster, isEndOfMessageCluster) + mainLinkPreviewContainer.clipToOutline = true // Thumbnail val linkPreview = message.linkPreviews.first() // TODO: Handle downloading state @@ -44,4 +46,32 @@ class LinkPreviewView : LinearLayout { // TODO: Implement } // endregion + + // region Convenience + private fun getOutlineProvider(isOutgoing: Boolean, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean): ViewOutlineProvider { + return object : ViewOutlineProvider() { + + override fun getOutline(view: View, outline: Outline) { + val path = Path() + val rect = RectF(0.0f, 0.0f, view.width.toFloat(), view.height.toFloat()) + val topLeft = if (isOutgoing) { + resources.getDimension(R.dimen.message_corner_radius) + } else { + if (isStartOfMessageCluster) resources.getDimension(R.dimen.message_corner_radius) else resources.getDimension(R.dimen.message_corner_collapse_radius) + } + val topRight = if (isOutgoing) { + if (isStartOfMessageCluster) resources.getDimension(R.dimen.message_corner_radius) else resources.getDimension(R.dimen.message_corner_collapse_radius) + } else { + resources.getDimension(R.dimen.message_corner_radius) + } + path.addRoundRect(rect, floatArrayOf( topLeft, topLeft, topRight, topRight, 0.0f, 0.0f, 0.0f, 0.0f ), Path.Direction.CW) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + outline.setPath(path) + } else { + @Suppress("DEPRECATION") outline.setConvexPath(path) + } + } + } + } + // endregion } \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt index 832f575933..c2938dff96 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt @@ -55,7 +55,7 @@ class VisibleMessageContentView : LinearLayout { onContentClick = null if (message is MmsMessageRecord && message.linkPreviews.isNotEmpty()) { val linkPreviewView = LinkPreviewView(context) - linkPreviewView.bind(message, glide) + linkPreviewView.bind(message, glide, isStartOfMessageCluster, isEndOfMessageCluster) mainContainer.addView(linkPreviewView) val bodyTextView = getBodyTextView(message) mainContainer.addView(bodyTextView) diff --git a/app/src/main/res/layout/view_link_preview.xml b/app/src/main/res/layout/view_link_preview.xml index 46790cae76..8d381092d5 100644 --- a/app/src/main/res/layout/view_link_preview.xml +++ b/app/src/main/res/layout/view_link_preview.xml @@ -10,8 +10,8 @@