diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSplashCarouselFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSplashCarouselFragment.kt index 053c54946e..038e020cf6 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSplashCarouselFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthSplashCarouselFragment.kt @@ -49,7 +49,8 @@ private const val CAROUSEL_TRANSITION_TIME_MS = 500L class FtueAuthSplashCarouselFragment @Inject constructor( private val vectorPreferences: VectorPreferences, private val vectorFeatures: VectorFeatures, - private val carouselController: SplashCarouselController + private val carouselController: SplashCarouselController, + private val carouselStateFactory: SplashCarouselStateFactory ) : AbstractFtueAuthFragment() { override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueSplashCarouselBinding { @@ -65,7 +66,7 @@ class FtueAuthSplashCarouselFragment @Inject constructor( val carouselAdapter = carouselController.adapter views.splashCarousel.adapter = carouselAdapter TabLayoutMediator(views.carouselIndicator, views.splashCarousel) { _, _ -> }.attach() - carouselController.setData(SplashCarouselState()) + carouselController.setData(carouselStateFactory.create()) views.loginSplashSubmit.debouncedClicks { getStarted() } views.loginSplashAlreadyHaveAccount.apply { diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/SplashCarouselItem.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/SplashCarouselItem.kt index 1230d8109a..dc56820424 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/SplashCarouselItem.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/SplashCarouselItem.kt @@ -35,7 +35,7 @@ abstract class SplashCarouselItem : VectorEpoxyModel( holder.view.setBackgroundResource(item.pageBackground) holder.image.setImageResource(item.image) - holder.title.setText(item.title) + holder.title.text = item.title.charSequence holder.body.setText(item.body) } diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/SplashCarouselState.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/SplashCarouselState.kt index c86e78d139..5328722a99 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/SplashCarouselState.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/SplashCarouselState.kt @@ -18,38 +18,13 @@ package im.vector.app.features.onboarding.ftueauth import androidx.annotation.DrawableRes import androidx.annotation.StringRes -import im.vector.app.R +import im.vector.app.core.epoxy.charsequence.EpoxyCharSequence data class SplashCarouselState( - val items: List = listOf( - 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 - ) - ) + val items: List ) { data class Item( - @StringRes val title: Int, + val title: EpoxyCharSequence, @StringRes val body: Int, @DrawableRes val image: Int, @DrawableRes val pageBackground: Int 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 new file mode 100644 index 0000000000..0e64d8048f --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/SplashCarouselStateFactory.kt @@ -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() + } +}