Fix bad background on long text posts.

main
Alex Hart 2023-01-04 12:45:54 -04:00 zatwierdzone przez Greyson Parrelli
rodzic c7bb0eadc2
commit eb6a14e686
3 zmienionych plików z 46 dodań i 43 usunięć

Wyświetl plik

@ -12,12 +12,12 @@ import androidx.core.graphics.ColorUtils
import androidx.core.view.doOnNextLayout import androidx.core.view.doOnNextLayout
import androidx.core.view.isVisible import androidx.core.view.isVisible
import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.components.ClippedCardView
import org.thoughtcrime.securesms.conversation.colors.ChatColors import org.thoughtcrime.securesms.conversation.colors.ChatColors
import org.thoughtcrime.securesms.database.model.databaseprotos.StoryTextPost import org.thoughtcrime.securesms.database.model.databaseprotos.StoryTextPost
import org.thoughtcrime.securesms.fonts.TextFont import org.thoughtcrime.securesms.fonts.TextFont
import org.thoughtcrime.securesms.linkpreview.LinkPreview import org.thoughtcrime.securesms.linkpreview.LinkPreview
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel 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.TextStoryPostCreationState
import org.thoughtcrime.securesms.mediasend.v2.text.TextStoryScale import org.thoughtcrime.securesms.mediasend.v2.text.TextStoryScale
import org.thoughtcrime.securesms.mediasend.v2.text.TextStoryTextWatcher 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) 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 backgroundView: ImageView = findViewById(R.id.text_story_post_background)
private val textView: StoryTextView = findViewById(R.id.text_story_post_text) 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 val linkPreviewView: StoryLinkPreviewView = findViewById(R.id.text_story_post_link_preview)
private var isPlaceholder: Boolean = true private var isPlaceholder: Boolean = true
@ -83,27 +83,21 @@ class StoryTextPostView @JvmOverloads constructor(
textView.text = text textView.text = text
} }
private fun setTextGravity(textAlignment: TextAlignment) {
textView.gravity = textAlignment.gravity
}
private fun setTextScale(scalePercent: Int) { private fun setTextScale(scalePercent: Int) {
val scale = TextStoryScale.convertToScale(scalePercent) val scale = TextStoryScale.convertToScale(scalePercent)
textView.scaleX = scale textWrapperView.scaleX = scale
textView.scaleY = scale textWrapperView.scaleY = scale
} }
private fun setTextVisible(visible: Boolean) { private fun setTextVisible(visible: Boolean) {
textView.visible = visible textWrapperView.visible = visible
} }
private fun setTextBackgroundColor(@ColorInt color: Int) { private fun setTextBackgroundColor(@ColorInt color: Int) {
textView.setWrappedBackgroundColor(color) textWrapperView.setCardBackgroundColor(color)
} }
fun bindFromCreationState(state: TextStoryPostCreationState) { fun bindFromCreationState(state: TextStoryPostCreationState) {
textAlignment = state.textAlignment
setPostBackground(state.backgroundColor.chatBubbleMask) setPostBackground(state.backgroundColor.chatBubbleMask)
setText( setText(
state.body.ifEmpty { state.body.ifEmpty {
@ -120,7 +114,6 @@ class StoryTextPostView @JvmOverloads constructor(
setTextColor(state.textForegroundColor, state.body.isEmpty()) setTextColor(state.textForegroundColor, state.body.isEmpty())
setTextBackgroundColor(state.textBackgroundColor) setTextBackgroundColor(state.textBackgroundColor)
setTextGravity(state.textAlignment)
setTextScale(state.textScale) setTextScale(state.textScale)
postAdjustLinkPreviewTranslationY() postAdjustLinkPreviewTranslationY()
@ -130,8 +123,6 @@ class StoryTextPostView @JvmOverloads constructor(
visible = true visible = true
linkPreviewView.visible = false linkPreviewView.visible = false
textAlignment = TextAlignment.CENTER
val font = TextFont.fromStyle(storyTextPost.style) val font = TextFont.fromStyle(storyTextPost.style)
setPostBackground(ChatColors.forChatColor(ChatColors.Id.NotSet, storyTextPost.background).chatBubbleMask) setPostBackground(ChatColors.forChatColor(ChatColors.Id.NotSet, storyTextPost.background).chatBubbleMask)
@ -143,7 +134,6 @@ class StoryTextPostView @JvmOverloads constructor(
setTextColor(storyTextPost.textForegroundColor, false) setTextColor(storyTextPost.textForegroundColor, false)
setTextBackgroundColor(storyTextPost.textBackgroundColor) setTextBackgroundColor(storyTextPost.textBackgroundColor)
setTextGravity(TextAlignment.CENTER)
hideCloseButton() hideCloseButton()
@ -182,12 +172,12 @@ class StoryTextPostView @JvmOverloads constructor(
} }
fun showPostContent() { fun showPostContent() {
textView.alpha = 1f textWrapperView.alpha = 1f
linkPreviewView.alpha = 1f linkPreviewView.alpha = 1f
} }
fun hidePostContent() { fun hidePostContent() {
textView.alpha = 0f textWrapperView.alpha = 0f
linkPreviewView.alpha = 0f linkPreviewView.alpha = 0f
} }
@ -197,7 +187,7 @@ class StoryTextPostView @JvmOverloads constructor(
private fun adjustLinkPreviewTranslationY() { private fun adjustLinkPreviewTranslationY() {
val backgroundHeight = backgroundView.measuredHeight 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 previewHeight = if (linkPreviewView.visible) linkPreviewView.measuredHeight else 0
val availableHeight = backgroundHeight - textHeight val availableHeight = backgroundHeight - textHeight
@ -208,17 +198,17 @@ class StoryTextPostView @JvmOverloads constructor(
linkPreviewView.translationY = -margin linkPreviewView.translationY = -margin
val originPoint = textView.measuredHeight / 2f val originPoint = textWrapperView.measuredHeight / 2f
val desiredPoint = (textHeight / 2f) + margin val desiredPoint = (textHeight / 2f) + margin
textView.translationY = desiredPoint - originPoint textWrapperView.translationY = desiredPoint - originPoint
} else { } else {
linkPreviewView.translationY = 0f linkPreviewView.translationY = 0f
val originPoint = textView.measuredHeight / 2f val originPoint = textWrapperView.measuredHeight / 2f
val desiredPoint = backgroundHeight / 2f val desiredPoint = backgroundHeight / 2f
textView.translationY = desiredPoint - originPoint textWrapperView.translationY = desiredPoint - originPoint
} }
} }
} }

Wyświetl plik

@ -36,6 +36,10 @@ class StoryTextView @JvmOverloads constructor(
} }
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {
if (layout == null) {
invalidate()
}
if (wrappedBackgroundPaint.color != Color.TRANSPARENT && layout != null) { if (wrappedBackgroundPaint.color != Color.TRANSPARENT && layout != null) {
canvas.getClipBounds(canvasBounds) canvas.getClipBounds(canvasBounds)
textBounds.set(canvasBounds) textBounds.set(canvasBounds)

Wyświetl plik

@ -1,40 +1,49 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" <merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
tools:viewBindingIgnore="true"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout"> tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout"
tools:viewBindingIgnore="true">
<ImageView <ImageView
android:importantForAccessibility="no"
android:id="@+id/text_story_post_background" android:id="@+id/text_story_post_background"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:importantForAccessibility="no" />
<org.thoughtcrime.securesms.stories.StoryTextView <org.thoughtcrime.securesms.components.ClippedCardView
android:id="@+id/text_story_post_text" android:id="@+id/text_story_text_background"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:layout_marginStart="20dp" android:layout_marginStart="20dp"
android:layout_marginEnd="20dp" android:layout_marginEnd="20dp"
android:focusable="false" app:cardCornerRadius="18dp"
android:gravity="center" app:cardElevation="0dp"
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:layout_constrainedWidth="true" app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent">
tools:ignore="SpUsage"
tools:text="TEST" /> <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 <org.thoughtcrime.securesms.stories.StoryLinkPreviewView
android:id="@+id/text_story_post_link_preview" android:id="@+id/text_story_post_link_preview"