This commit is contained in:
Niels Andriesse 2021-06-21 16:13:21 +10:00
parent 0eaecf168d
commit 74330c931a
3 changed files with 40 additions and 10 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -10,8 +10,8 @@
<ImageView
android:id="@+id/thumbnailImageView"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_width="96dp"
android:layout_height="96dp"
android:scaleType="centerCrop" />
<TextView