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