Fix capitalization retention for text stories.

This commit is contained in:
Alex Hart 2022-03-23 12:50:32 -03:00 committed by Greyson Parrelli
parent 2b3f16d3ad
commit 954e45ed97
5 changed files with 31 additions and 16 deletions

View file

@ -100,11 +100,13 @@ class ScaleTransition : Transition {
end.view.scaleX = (startWidth / endWidth) * startScaleX
end.view.scaleY = (startHeight / endHeight) * startScaleY
return ObjectAnimator.ofPropertyValuesHolder(end.view,
return ObjectAnimator.ofPropertyValuesHolder(
end.view,
ofFloat(View.TRANSLATION_X, 0f),
ofFloat(View.TRANSLATION_Y, 0f),
ofFloat(View.SCALE_X, 1f),
ofFloat(View.SCALE_Y, 1f)).apply {
ofFloat(View.SCALE_Y, 1f)
).apply {
addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) {
resetValues(start.view)
@ -113,4 +115,4 @@ class ScaleTransition : Transition {
})
}
}
}
}

View file

@ -1,7 +1,6 @@
package org.thoughtcrime.securesms.stories
import android.content.Context
import android.graphics.Color
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.util.AttributeSet
@ -10,11 +9,9 @@ import android.view.View
import androidx.annotation.ColorInt
import androidx.annotation.Px
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.doOnNextLayout
import androidx.core.view.isVisible
import com.airbnb.lottie.SimpleColorFilter
import com.google.android.material.imageview.ShapeableImageView
import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.conversation.colors.ChatColors
@ -120,6 +117,12 @@ class StoryTextPostView @JvmOverloads constructor(
setText(
state.body.ifEmpty {
context.getString(R.string.TextStoryPostCreationFragment__tap_to_add_text)
}.let {
if (state.textFont.isAllCaps) {
it.toString().toUpperCase(Locale.getDefault())
} else {
it
}
},
state.body.isEmpty()
)
@ -137,13 +140,20 @@ class StoryTextPostView @JvmOverloads constructor(
textAlignment = TextAlignment.CENTER
val font = TextFont.fromStyle(storyTextPost.style)
setPostBackground(ChatColors.forChatColor(ChatColors.Id.NotSet, storyTextPost.background).chatBubbleMask)
setText(storyTextPost.body, false)
if (font.isAllCaps) {
setText(storyTextPost.body.toUpperCase(Locale.getDefault()), false)
} else {
setText(storyTextPost.body, false)
}
setTextColor(storyTextPost.textForegroundColor)
setTextBackgroundColor(storyTextPost.textBackgroundColor)
setTextGravity(TextAlignment.CENTER)
when (val fontResult = Fonts.resolveFont(context, Locale.getDefault(), TextFont.fromStyle(storyTextPost.style))) {
when (val fontResult = Fonts.resolveFont(context, Locale.getDefault(), font)) {
is Fonts.FontResult.Immediate -> setTypeface(fontResult.typeface)
is Fonts.FontResult.Async -> setTypeface(fontResult.future.get())
}

View file

@ -4,7 +4,6 @@ import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.RectF
import android.util.AttributeSet
import androidx.annotation.ColorInt
@ -12,7 +11,8 @@ import org.signal.core.util.DimensionUnit
import org.thoughtcrime.securesms.components.emoji.EmojiTextView
class StoryTextView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
context: Context,
attrs: AttributeSet? = null
) : EmojiTextView(context, attrs) {
private val textBounds: RectF = RectF()
@ -55,4 +55,4 @@ class StoryTextView @JvmOverloads constructor(
super.onDraw(canvas)
}
}
}

View file

@ -34,11 +34,14 @@ class MyStoriesFragment : DSLSettingsFragment(
override fun bindAdapter(adapter: DSLSettingsAdapter) {
MyStoriesItem.register(adapter)
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
requireActivity().finish()
requireActivity().onBackPressedDispatcher.addCallback(
viewLifecycleOwner,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
requireActivity().finish()
}
}
})
)
lifecycleDisposable.bindTo(viewLifecycleOwner)
viewModel.state.observe(viewLifecycleOwner) {

View file

@ -706,7 +706,7 @@ class StoryViewerPageFragment :
sharedViewModel.setIsChildScrolling(isXMagnitudeGreaterThanYMagnitude || isFirstAndHasYTranslationOrNegativeY)
if (isFirstStory) {
val delta = max(0f, (e2.rawY - e1.rawY)) / 3f
val percent = INTERPOLATOR.getInterpolation(delta/maxSlide)
val percent = INTERPOLATOR.getInterpolation(delta / maxSlide)
val distance = maxSlide * percent
viewToTranslate.animate().cancel()