From eb4d31e955e22e871519d9d943ab06109afb69ff Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 28 Apr 2022 11:19:05 +0100 Subject: [PATCH] extracting reusable logic for styling terminating full stops and applying to the waiting for verification title --- .../im/vector/app/core/utils/SpannableUtils.kt | 15 +++++++++++++++ .../ftueauth/FtueAuthWaitForEmailFragment.kt | 8 ++++++++ .../ftueauth/SplashCarouselStateFactory.kt | 18 +++++------------- ...agment_ftue_wait_for_email_verification.xml | 4 ++-- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/utils/SpannableUtils.kt b/vector/src/main/java/im/vector/app/core/utils/SpannableUtils.kt index 69702fc793..292468b68f 100644 --- a/vector/src/main/java/im/vector/app/core/utils/SpannableUtils.kt +++ b/vector/src/main/java/im/vector/app/core/utils/SpannableUtils.kt @@ -22,6 +22,7 @@ import android.text.style.ForegroundColorSpan import android.text.style.StyleSpan import androidx.annotation.ColorInt import me.gujun.android.span.Span +import me.gujun.android.span.span fun Spannable.styleMatchingText(match: String, typeFace: Int): Spannable { if (match.isEmpty()) return this @@ -56,3 +57,17 @@ fun Span.bullet(text: CharSequence = "", build() }) } + +fun String.colorTerminatingFullStop(@ColorInt color: Int): CharSequence { + val fullStop = "." + return if (this.endsWith(fullStop)) { + span { + +this@colorTerminatingFullStop.removeSuffix(fullStop) + span(fullStop) { + textColor = color + } + } + } else { + this + } +} diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthWaitForEmailFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthWaitForEmailFragment.kt index 408253a97c..648b24f095 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthWaitForEmailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthWaitForEmailFragment.kt @@ -21,12 +21,15 @@ import android.os.Parcelable import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.annotation.AttrRes import androidx.core.view.isVisible import com.airbnb.mvrx.args import im.vector.app.R +import im.vector.app.core.utils.colorTerminatingFullStop import im.vector.app.databinding.FragmentFtueWaitForEmailVerificationBinding import im.vector.app.features.onboarding.OnboardingAction import im.vector.app.features.onboarding.RegisterAction +import im.vector.app.features.themes.ThemeUtils import kotlinx.parcelize.Parcelize import javax.inject.Inject @@ -53,12 +56,17 @@ class FtueAuthWaitForEmailFragment @Inject constructor() : AbstractFtueAuthFragm } private fun setupUi() { + views.emailVerificationTitle.text = R.string.ftue_auth_email_verification_title.colorTerminatingFullStop(R.attr.colorSecondary) views.emailVerificationSubtitle.text = getString(R.string.ftue_auth_email_verification_subtitle, params.email) views.emailVerificationResendEmail.debouncedClicks { viewModel.handle(OnboardingAction.PostRegisterAction(RegisterAction.SendAgainThreePid)) } } + private fun Int.colorTerminatingFullStop(@AttrRes color: Int): CharSequence { + return getString(this).colorTerminatingFullStop(ThemeUtils.getColor(requireContext(), color)) + } + override fun onResume() { super.onResume() showLoadingIfReturningToScreen() diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/SplashCarouselStateFactory.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/SplashCarouselStateFactory.kt index 23f7014374..6d34764584 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/SplashCarouselStateFactory.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/SplashCarouselStateFactory.kt @@ -18,11 +18,13 @@ package im.vector.app.features.onboarding.ftueauth import android.content.Context import androidx.annotation.AttrRes +import androidx.annotation.ColorInt import androidx.annotation.DrawableRes import im.vector.app.R import im.vector.app.core.resources.LocaleProvider import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.isEnglishSpeaking +import im.vector.app.core.utils.colorTerminatingFullStop import im.vector.app.features.themes.ThemeProvider import im.vector.app.features.themes.ThemeUtils import im.vector.lib.core.utils.epoxy.charsequence.EpoxyCharSequence @@ -79,18 +81,8 @@ class SplashCarouselStateFactory @Inject constructor( } private fun Int.colorTerminatingFullStop(@AttrRes color: Int): EpoxyCharSequence { - val string = stringProvider.getString(this) - val fullStop = "." - val charSequence = if (string.endsWith(fullStop)) { - span { - +string.removeSuffix(fullStop) - span(fullStop) { - textColor = ThemeUtils.getColor(context, color) - } - } - } else { - string - } - return charSequence.toEpoxyCharSequence() + return stringProvider.getString(this) + .colorTerminatingFullStop(ThemeUtils.getColor(context, color)) + .toEpoxyCharSequence() } } diff --git a/vector/src/main/res/layout/fragment_ftue_wait_for_email_verification.xml b/vector/src/main/res/layout/fragment_ftue_wait_for_email_verification.xml index 14bc5fcd86..8ce1c25707 100644 --- a/vector/src/main/res/layout/fragment_ftue_wait_for_email_verification.xml +++ b/vector/src/main/res/layout/fragment_ftue_wait_for_email_verification.xml @@ -57,12 +57,12 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:gravity="center" - android:text="@string/ftue_auth_email_verification_title" android:transitionName="loginTitleTransition" app:layout_constraintBottom_toTopOf="@id/emailVerificationSubtitle" app:layout_constraintEnd_toEndOf="@id/ftueAuthGutterEnd" app:layout_constraintStart_toStartOf="@id/ftueAuthGutterStart" - app:layout_constraintTop_toBottomOf="@id/emailVerificationSpace2" /> + app:layout_constraintTop_toBottomOf="@id/emailVerificationSpace2" + tools:text="@string/ftue_auth_email_verification_title" />