mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 10:55:55 +03:00
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:
parent
f025554612
commit
19f328bf9d
4 changed files with 82 additions and 31 deletions
|
@ -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<FragmentFtueSplashCarouselBinding>() {
|
||||
|
||||
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 {
|
||||
|
|
|
@ -35,7 +35,7 @@ abstract class SplashCarouselItem : VectorEpoxyModel<SplashCarouselItem.Holder>(
|
|||
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Item> = 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<Item>
|
||||
) {
|
||||
data class Item(
|
||||
@StringRes val title: Int,
|
||||
val title: EpoxyCharSequence,
|
||||
@StringRes val body: Int,
|
||||
@DrawableRes val image: Int,
|
||||
@DrawableRes val pageBackground: Int
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue