Fix bad background on long text posts.
This commit is contained in:
parent
c7bb0eadc2
commit
eb6a14e686
3 changed files with 46 additions and 43 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,40 +1,49 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:viewBindingIgnore="true"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
|
||||
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout"
|
||||
tools:viewBindingIgnore="true">
|
||||
|
||||
<ImageView
|
||||
android:importantForAccessibility="no"
|
||||
android:id="@+id/text_story_post_background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no" />
|
||||
|
||||
<org.thoughtcrime.securesms.stories.StoryTextView
|
||||
android:id="@+id/text_story_post_text"
|
||||
android:layout_width="match_parent"
|
||||
<org.thoughtcrime.securesms.components.ClippedCardView
|
||||
android:id="@+id/text_story_text_background"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start|center_vertical"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:focusable="false"
|
||||
android:gravity="center"
|
||||
android:paddingHorizontal="12dp"
|
||||
android:paddingTop="15dp"
|
||||
android:paddingBottom="13dp"
|
||||
android:text="@string/TextStoryPostCreationFragment__tap_to_add_text"
|
||||
android:textAppearance="@style/TextAppearance.Signal.Body1.Bold"
|
||||
android:textColor="@color/core_white"
|
||||
android:textSize="34dp"
|
||||
app:cardCornerRadius="18dp"
|
||||
app:cardElevation="0dp"
|
||||
app:layout_constrainedWidth="true"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:ignore="SpUsage"
|
||||
tools:text="TEST" />
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<org.thoughtcrime.securesms.stories.StoryTextView
|
||||
android:id="@+id/text_story_post_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start|center_vertical"
|
||||
android:focusable="false"
|
||||
android:gravity="center"
|
||||
android:paddingHorizontal="12dp"
|
||||
android:paddingTop="15dp"
|
||||
android:paddingBottom="13dp"
|
||||
android:text="@string/TextStoryPostCreationFragment__tap_to_add_text"
|
||||
android:textAppearance="@style/TextAppearance.Signal.Body1.Bold"
|
||||
android:textColor="@color/core_white"
|
||||
android:textSize="34dp"
|
||||
tools:ignore="SpUsage"
|
||||
tools:text="TEST" />
|
||||
|
||||
</org.thoughtcrime.securesms.components.ClippedCardView>
|
||||
|
||||
<org.thoughtcrime.securesms.stories.StoryLinkPreviewView
|
||||
android:id="@+id/text_story_post_link_preview"
|
||||
|
|
Loading…
Add table
Reference in a new issue