styling last full stop in the carousel titles to use the accent colour

- also meant extracting out a separate state creation factory to avoid having too much logic inside the fragment
This commit is contained in:
Adam Brown 2022-01-05 14:00:51 +00:00
parent f025554612
commit 19f328bf9d
4 changed files with 82 additions and 31 deletions

View file

@ -49,7 +49,8 @@ private const val CAROUSEL_TRANSITION_TIME_MS = 500L
class FtueAuthSplashCarouselFragment @Inject constructor( class FtueAuthSplashCarouselFragment @Inject constructor(
private val vectorPreferences: VectorPreferences, private val vectorPreferences: VectorPreferences,
private val vectorFeatures: VectorFeatures, private val vectorFeatures: VectorFeatures,
private val carouselController: SplashCarouselController private val carouselController: SplashCarouselController,
private val carouselStateFactory: SplashCarouselStateFactory
) : AbstractFtueAuthFragment<FragmentFtueSplashCarouselBinding>() { ) : AbstractFtueAuthFragment<FragmentFtueSplashCarouselBinding>() {
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueSplashCarouselBinding { override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueSplashCarouselBinding {
@ -65,7 +66,7 @@ class FtueAuthSplashCarouselFragment @Inject constructor(
val carouselAdapter = carouselController.adapter val carouselAdapter = carouselController.adapter
views.splashCarousel.adapter = carouselAdapter views.splashCarousel.adapter = carouselAdapter
TabLayoutMediator(views.carouselIndicator, views.splashCarousel) { _, _ -> }.attach() TabLayoutMediator(views.carouselIndicator, views.splashCarousel) { _, _ -> }.attach()
carouselController.setData(SplashCarouselState()) carouselController.setData(carouselStateFactory.create())
views.loginSplashSubmit.debouncedClicks { getStarted() } views.loginSplashSubmit.debouncedClicks { getStarted() }
views.loginSplashAlreadyHaveAccount.apply { views.loginSplashAlreadyHaveAccount.apply {

View file

@ -35,7 +35,7 @@ abstract class SplashCarouselItem : VectorEpoxyModel<SplashCarouselItem.Holder>(
holder.view.setBackgroundResource(item.pageBackground) holder.view.setBackgroundResource(item.pageBackground)
holder.image.setImageResource(item.image) holder.image.setImageResource(item.image)
holder.title.setText(item.title) holder.title.text = item.title.charSequence
holder.body.setText(item.body) holder.body.setText(item.body)
} }

View file

@ -18,38 +18,13 @@ package im.vector.app.features.onboarding.ftueauth
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import im.vector.app.R import im.vector.app.core.epoxy.charsequence.EpoxyCharSequence
data class SplashCarouselState( data class SplashCarouselState(
val items: List<Item> = listOf( val items: List<Item>
Item(
R.string.ftue_auth_carousel_1_title,
R.string.ftue_auth_carousel_1_body,
R.drawable.onboarding_carousel_conversations,
R.drawable.bg_carousel_page_1
),
Item(
R.string.ftue_auth_carousel_2_title,
R.string.ftue_auth_carousel_2_body,
R.drawable.onboarding_carousel_ems,
R.drawable.bg_carousel_page_2
),
Item(
R.string.ftue_auth_carousel_3_title,
R.string.ftue_auth_carousel_3_body,
R.drawable.onboarding_carousel_connect,
R.drawable.bg_carousel_page_3
),
Item(
R.string.ftue_auth_carousel_4_title,
R.string.ftue_auth_carousel_4_body,
R.drawable.onboarding_carousel_universal,
R.drawable.bg_carousel_page_4
)
)
) { ) {
data class Item( data class Item(
@StringRes val title: Int, val title: EpoxyCharSequence,
@StringRes val body: Int, @StringRes val body: Int,
@DrawableRes val image: Int, @DrawableRes val image: Int,
@DrawableRes val pageBackground: Int @DrawableRes val pageBackground: Int

View file

@ -0,0 +1,75 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.features.onboarding.ftueauth
import android.content.Context
import androidx.annotation.AttrRes
import im.vector.app.R
import im.vector.app.core.epoxy.charsequence.EpoxyCharSequence
import im.vector.app.core.epoxy.charsequence.toEpoxyCharSequence
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.themes.ThemeUtils
import me.gujun.android.span.span
import javax.inject.Inject
class SplashCarouselStateFactory @Inject constructor(
private val context: Context,
private val stringProvider: StringProvider
) {
fun create() = SplashCarouselState(listOf(
SplashCarouselState.Item(
R.string.ftue_auth_carousel_1_title.colorTerminatingFullStop(R.attr.colorAccent),
R.string.ftue_auth_carousel_1_body,
R.drawable.onboarding_carousel_conversations,
R.drawable.bg_carousel_page_1
),
SplashCarouselState.Item(
R.string.ftue_auth_carousel_2_title.colorTerminatingFullStop(R.attr.colorAccent),
R.string.ftue_auth_carousel_2_body,
R.drawable.onboarding_carousel_ems,
R.drawable.bg_carousel_page_2
),
SplashCarouselState.Item(
R.string.ftue_auth_carousel_3_title.colorTerminatingFullStop(R.attr.colorAccent),
R.string.ftue_auth_carousel_3_body,
R.drawable.onboarding_carousel_connect,
R.drawable.bg_carousel_page_3
),
SplashCarouselState.Item(
R.string.ftue_auth_carousel_4_title.colorTerminatingFullStop(R.attr.colorAccent),
R.string.ftue_auth_carousel_4_body,
R.drawable.onboarding_carousel_universal,
R.drawable.bg_carousel_page_4
)
))
private fun Int.colorTerminatingFullStop(@AttrRes color: Int): EpoxyCharSequence {
val string = stringProvider.getString(this)
val fullStop = "."
return (if (string.endsWith(fullStop)) {
span {
+string.removeSuffix(fullStop)
span(fullStop) {
textColor = ThemeUtils.getColor(context, color)
}
}
} else {
string
}).toEpoxyCharSequence()
}
}