mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-28 18:57:43 +00:00
Fix link preview corner rounding
This commit is contained in:
parent
74330c931a
commit
252f344d93
@ -1,9 +1,11 @@
|
||||
package org.thoughtcrime.securesms.conversation.v2.messages
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Outline
|
||||
import android.graphics.Path
|
||||
import android.graphics.RectF
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
@ -29,8 +31,9 @@ class LinkPreviewView : LinearLayout {
|
||||
// endregion
|
||||
|
||||
// region Updating
|
||||
fun bind(message: MmsMessageRecord, glide: GlideRequests, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean) {
|
||||
mainLinkPreviewContainer.outlineProvider = getOutlineProvider(message.isOutgoing, isStartOfMessageCluster, isEndOfMessageCluster)
|
||||
fun bind(message: MmsMessageRecord, glide: GlideRequests, background: Drawable) {
|
||||
mainLinkPreviewContainer.background = background
|
||||
mainLinkPreviewContainer.outlineProvider = ViewOutlineProvider.BACKGROUND
|
||||
mainLinkPreviewContainer.clipToOutline = true
|
||||
// Thumbnail
|
||||
val linkPreview = message.linkPreviews.first()
|
||||
@ -40,38 +43,12 @@ class LinkPreviewView : LinearLayout {
|
||||
// TODO: Properly use glide and the actual thumbnail
|
||||
// Title
|
||||
titleTextView.text = linkPreview.title
|
||||
// Body
|
||||
mainLinkPreviewContainer.addView(VisibleMessageContentView.getBodyTextView(context, message))
|
||||
}
|
||||
|
||||
fun recycle() {
|
||||
// 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
|
||||
}
|
@ -55,16 +55,15 @@ class VisibleMessageContentView : LinearLayout {
|
||||
onContentClick = null
|
||||
if (message is MmsMessageRecord && message.linkPreviews.isNotEmpty()) {
|
||||
val linkPreviewView = LinkPreviewView(context)
|
||||
linkPreviewView.bind(message, glide, isStartOfMessageCluster, isEndOfMessageCluster)
|
||||
linkPreviewView.bind(message, glide, background)
|
||||
mainContainer.addView(linkPreviewView)
|
||||
val bodyTextView = getBodyTextView(message)
|
||||
mainContainer.addView(bodyTextView)
|
||||
// Body text view is inside the link preview for layout convenience
|
||||
} else if (message is MmsMessageRecord && message.quote != null) {
|
||||
val quote = message.quote!!
|
||||
val quoteView = QuoteView(context, QuoteView.Mode.Regular)
|
||||
quoteView.bind(quote.author.toString(), quote.text, quote.attachment, message.recipient, message.isOutgoing)
|
||||
mainContainer.addView(quoteView)
|
||||
val bodyTextView = getBodyTextView(message)
|
||||
val bodyTextView = VisibleMessageContentView.getBodyTextView(context, message)
|
||||
ViewUtil.setPaddingTop(bodyTextView, 0)
|
||||
mainContainer.addView(bodyTextView)
|
||||
} else if (message is MmsMessageRecord && message.slideDeck.audioSlide != null) {
|
||||
@ -74,12 +73,12 @@ class VisibleMessageContentView : LinearLayout {
|
||||
onContentClick = { voiceMessageView.togglePlayback() }
|
||||
} else if (message is MmsMessageRecord && message.slideDeck.documentSlide != null) {
|
||||
val documentView = DocumentView(context)
|
||||
documentView.bind(message, getTextColor(message))
|
||||
documentView.bind(message, VisibleMessageContentView.getTextColor(context, message))
|
||||
mainContainer.addView(documentView)
|
||||
} else if (message is MmsMessageRecord && message.slideDeck.asAttachments().isNotEmpty()) {
|
||||
throw IllegalStateException("Not yet implemented; we may want to use Signal's album view here.")
|
||||
} else {
|
||||
val bodyTextView = getBodyTextView(message)
|
||||
val bodyTextView = VisibleMessageContentView.getBodyTextView(context, message)
|
||||
mainContainer.addView(bodyTextView)
|
||||
}
|
||||
}
|
||||
@ -105,27 +104,30 @@ class VisibleMessageContentView : LinearLayout {
|
||||
// endregion
|
||||
|
||||
// region Convenience
|
||||
private fun getBodyTextView(message: MessageRecord): TextView {
|
||||
val result = TextView(context)
|
||||
val vPadding = resources.getDimension(R.dimen.small_spacing).toInt()
|
||||
val hPadding = toPx(12, resources)
|
||||
result.setPadding(hPadding, vPadding, hPadding, vPadding)
|
||||
result.text = message.body
|
||||
result.setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.small_font_size))
|
||||
val color = getTextColor(message)
|
||||
result.setTextColor(color)
|
||||
return result
|
||||
}
|
||||
companion object {
|
||||
|
||||
@ColorInt
|
||||
private fun getTextColor(message: MessageRecord): Int {
|
||||
val uiMode = UiModeUtilities.getUserSelectedUiMode(context)
|
||||
val colorID = if (message.isOutgoing) {
|
||||
if (uiMode == UiMode.NIGHT) R.color.black else R.color.white
|
||||
} else {
|
||||
if (uiMode == UiMode.NIGHT) R.color.white else R.color.black
|
||||
fun getBodyTextView(context: Context, message: MessageRecord): TextView {
|
||||
val result = TextView(context)
|
||||
val vPadding = context.resources.getDimension(R.dimen.small_spacing).toInt()
|
||||
val hPadding = toPx(12, context.resources)
|
||||
result.setPadding(hPadding, vPadding, hPadding, vPadding)
|
||||
result.text = message.body
|
||||
result.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.resources.getDimension(R.dimen.small_font_size))
|
||||
val color = getTextColor(context, message)
|
||||
result.setTextColor(color)
|
||||
return result
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
fun getTextColor(context: Context, message: MessageRecord): Int {
|
||||
val uiMode = UiModeUtilities.getUserSelectedUiMode(context)
|
||||
val colorID = if (message.isOutgoing) {
|
||||
if (uiMode == UiMode.NIGHT) R.color.black else R.color.white
|
||||
} else {
|
||||
if (uiMode == UiMode.NIGHT) R.color.white else R.color.black
|
||||
}
|
||||
return context.resources.getColorWithID(colorID, context.theme)
|
||||
}
|
||||
return resources.getColorWithID(colorID, context.theme)
|
||||
}
|
||||
// endregion
|
||||
}
|
@ -5,27 +5,34 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center">
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/thumbnailImageView"
|
||||
android:layout_width="96dp"
|
||||
android:layout_height="96dp"
|
||||
android:scaleType="centerCrop" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleTextView"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingStart="12dp"
|
||||
android:gravity="center_vertical"
|
||||
android:textSize="@dimen/small_font_size"
|
||||
android:textStyle="bold"
|
||||
tools:text="The Day The Dinosaurs Died - Minute by Minute"
|
||||
android:maxLines="3"
|
||||
android:ellipsize="end"
|
||||
android:textColor="@color/text"
|
||||
android:background="@color/link_preview_background" />
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/thumbnailImageView"
|
||||
android:layout_width="96dp"
|
||||
android:layout_height="96dp"
|
||||
android:scaleType="centerCrop" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingHorizontal="12dp"
|
||||
android:gravity="center_vertical"
|
||||
android:textSize="@dimen/small_font_size"
|
||||
android:textStyle="bold"
|
||||
tools:text="The Day The Dinosaurs Died - Minute by Minute"
|
||||
android:maxLines="3"
|
||||
android:ellipsize="end"
|
||||
android:textColor="@color/text"
|
||||
android:background="@color/link_preview_background" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user