From eb6a14e6866f5074405c6baa0b191bb7c76f71b7 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Wed, 4 Jan 2023 12:45:54 -0400 Subject: [PATCH] Fix bad background on long text posts. --- .../securesms/stories/StoryTextPostView.kt | 36 +++++--------- .../securesms/stories/StoryTextView.kt | 4 ++ .../res/layout/stories_text_post_view.xml | 49 +++++++++++-------- 3 files changed, 46 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/stories/StoryTextPostView.kt b/app/src/main/java/org/thoughtcrime/securesms/stories/StoryTextPostView.kt index cda4a9bb08..d7805cbd87 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/stories/StoryTextPostView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/stories/StoryTextPostView.kt @@ -12,12 +12,12 @@ import androidx.core.graphics.ColorUtils import androidx.core.view.doOnNextLayout import androidx.core.view.isVisible import org.thoughtcrime.securesms.R +import org.thoughtcrime.securesms.components.ClippedCardView import org.thoughtcrime.securesms.conversation.colors.ChatColors import org.thoughtcrime.securesms.database.model.databaseprotos.StoryTextPost import org.thoughtcrime.securesms.fonts.TextFont import org.thoughtcrime.securesms.linkpreview.LinkPreview import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel -import org.thoughtcrime.securesms.mediasend.v2.text.TextAlignment import org.thoughtcrime.securesms.mediasend.v2.text.TextStoryPostCreationState import org.thoughtcrime.securesms.mediasend.v2.text.TextStoryScale import org.thoughtcrime.securesms.mediasend.v2.text.TextStoryTextWatcher @@ -35,9 +35,9 @@ class StoryTextPostView @JvmOverloads constructor( inflate(context, R.layout.stories_text_post_view, this) } - private var textAlignment: TextAlignment? = null private val backgroundView: ImageView = findViewById(R.id.text_story_post_background) private val textView: StoryTextView = findViewById(R.id.text_story_post_text) + private val textWrapperView: ClippedCardView = findViewById(R.id.text_story_text_background) private val linkPreviewView: StoryLinkPreviewView = findViewById(R.id.text_story_post_link_preview) private var isPlaceholder: Boolean = true @@ -83,27 +83,21 @@ class StoryTextPostView @JvmOverloads constructor( textView.text = text } - private fun setTextGravity(textAlignment: TextAlignment) { - textView.gravity = textAlignment.gravity - } - private fun setTextScale(scalePercent: Int) { val scale = TextStoryScale.convertToScale(scalePercent) - textView.scaleX = scale - textView.scaleY = scale + textWrapperView.scaleX = scale + textWrapperView.scaleY = scale } private fun setTextVisible(visible: Boolean) { - textView.visible = visible + textWrapperView.visible = visible } private fun setTextBackgroundColor(@ColorInt color: Int) { - textView.setWrappedBackgroundColor(color) + textWrapperView.setCardBackgroundColor(color) } fun bindFromCreationState(state: TextStoryPostCreationState) { - textAlignment = state.textAlignment - setPostBackground(state.backgroundColor.chatBubbleMask) setText( state.body.ifEmpty { @@ -120,7 +114,6 @@ class StoryTextPostView @JvmOverloads constructor( setTextColor(state.textForegroundColor, state.body.isEmpty()) setTextBackgroundColor(state.textBackgroundColor) - setTextGravity(state.textAlignment) setTextScale(state.textScale) postAdjustLinkPreviewTranslationY() @@ -130,8 +123,6 @@ class StoryTextPostView @JvmOverloads constructor( visible = true linkPreviewView.visible = false - textAlignment = TextAlignment.CENTER - val font = TextFont.fromStyle(storyTextPost.style) setPostBackground(ChatColors.forChatColor(ChatColors.Id.NotSet, storyTextPost.background).chatBubbleMask) @@ -143,7 +134,6 @@ class StoryTextPostView @JvmOverloads constructor( setTextColor(storyTextPost.textForegroundColor, false) setTextBackgroundColor(storyTextPost.textBackgroundColor) - setTextGravity(TextAlignment.CENTER) hideCloseButton() @@ -182,12 +172,12 @@ class StoryTextPostView @JvmOverloads constructor( } fun showPostContent() { - textView.alpha = 1f + textWrapperView.alpha = 1f linkPreviewView.alpha = 1f } fun hidePostContent() { - textView.alpha = 0f + textWrapperView.alpha = 0f linkPreviewView.alpha = 0f } @@ -197,7 +187,7 @@ class StoryTextPostView @JvmOverloads constructor( private fun adjustLinkPreviewTranslationY() { val backgroundHeight = backgroundView.measuredHeight - val textHeight = if (canDisplayText()) textView.measuredHeight * textView.scaleY else 0f + val textHeight = if (canDisplayText()) textWrapperView.measuredHeight * textWrapperView.scaleY else 0f val previewHeight = if (linkPreviewView.visible) linkPreviewView.measuredHeight else 0 val availableHeight = backgroundHeight - textHeight @@ -208,17 +198,17 @@ class StoryTextPostView @JvmOverloads constructor( linkPreviewView.translationY = -margin - val originPoint = textView.measuredHeight / 2f + val originPoint = textWrapperView.measuredHeight / 2f val desiredPoint = (textHeight / 2f) + margin - textView.translationY = desiredPoint - originPoint + textWrapperView.translationY = desiredPoint - originPoint } else { linkPreviewView.translationY = 0f - val originPoint = textView.measuredHeight / 2f + val originPoint = textWrapperView.measuredHeight / 2f val desiredPoint = backgroundHeight / 2f - textView.translationY = desiredPoint - originPoint + textWrapperView.translationY = desiredPoint - originPoint } } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/stories/StoryTextView.kt b/app/src/main/java/org/thoughtcrime/securesms/stories/StoryTextView.kt index bb893d7168..d288b60952 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/stories/StoryTextView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/stories/StoryTextView.kt @@ -36,6 +36,10 @@ class StoryTextView @JvmOverloads constructor( } override fun onDraw(canvas: Canvas) { + if (layout == null) { + invalidate() + } + if (wrappedBackgroundPaint.color != Color.TRANSPARENT && layout != null) { canvas.getClipBounds(canvasBounds) textBounds.set(canvasBounds) diff --git a/app/src/main/res/layout/stories_text_post_view.xml b/app/src/main/res/layout/stories_text_post_view.xml index 6ba7ee44b3..3a8f47a1fb 100644 --- a/app/src/main/res/layout/stories_text_post_view.xml +++ b/app/src/main/res/layout/stories_text_post_view.xml @@ -1,40 +1,49 @@ + tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout" + tools:viewBindingIgnore="true"> + android:layout_height="match_parent" + android:importantForAccessibility="no" /> - + app:layout_constraintTop_toTopOf="parent"> + + + +