extracting reusable logic for styling terminating full stops and applying to the waiting for verification title

This commit is contained in:
Adam Brown 2022-04-28 11:19:05 +01:00
parent 817d692471
commit eb4d31e955
4 changed files with 30 additions and 15 deletions

View File

@ -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
}
}

View File

@ -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()

View File

@ -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()
}
}

View File

@ -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" />
<TextView
android:id="@+id/emailVerificationSubtitle"