diff --git a/vector/src/main/java/im/vector/app/core/extensions/Context.kt b/vector/src/main/java/im/vector/app/core/extensions/Context.kt index 59847da7c9..758bbe9b07 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/Context.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/Context.kt @@ -17,9 +17,32 @@ package im.vector.app.core.extensions import android.content.Context +import android.graphics.drawable.Drawable +import androidx.annotation.ColorInt +import androidx.annotation.ColorRes +import androidx.annotation.DrawableRes +import androidx.core.content.ContextCompat import dagger.hilt.EntryPoints import im.vector.app.core.di.SingletonEntryPoint +import kotlin.math.round fun Context.singletonEntryPoint(): SingletonEntryPoint { return EntryPoints.get(applicationContext, SingletonEntryPoint::class.java) } + +fun Context.getResTintedDrawable(@DrawableRes drawableRes: Int, @ColorRes tint: Int, alpha: Float? = null): Drawable? { + return getTintedDrawable(drawableRes, ContextCompat.getColor(this, tint), alpha) +} + +fun Context.getTintedDrawable(@DrawableRes drawableRes: Int, @ColorInt tint: Int, alpha: Float? = null) = ContextCompat.getDrawable(this, drawableRes) + ?.mutate() + ?.also { drawable -> + drawable.setTint(tint) + alpha?.let { + drawable.alpha = it.toAndroidAlpha() + } + } + +private fun Float.toAndroidAlpha(): Int { + return round(this * 255).toInt() +} diff --git a/vector/src/main/java/im/vector/app/core/extensions/TextView.kt b/vector/src/main/java/im/vector/app/core/extensions/TextView.kt index 048dddf9e5..cb34b95fa1 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/TextView.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/TextView.kt @@ -16,6 +16,7 @@ package im.vector.app.core.extensions +import android.graphics.drawable.Drawable import android.text.Spannable import android.text.SpannableString import android.text.TextPaint @@ -121,7 +122,11 @@ fun TextView.setLeftDrawable(@DrawableRes iconRes: Int, @AttrRes tintColor: Int? } else { ContextCompat.getDrawable(context, iconRes) } - setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null) + setLeftDrawable(icon) +} + +fun TextView.setLeftDrawable(drawable: Drawable?) { + setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null) } /** diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthUseCaseFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthUseCaseFragment.kt index 6310eaea95..5325b25e93 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthUseCaseFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthUseCaseFragment.kt @@ -16,21 +16,36 @@ package im.vector.app.features.onboarding.ftueauth +import android.graphics.Color +import android.graphics.drawable.Drawable +import android.graphics.drawable.LayerDrawable import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView +import androidx.annotation.ColorRes +import androidx.annotation.DrawableRes import androidx.annotation.StringRes +import androidx.core.content.ContextCompat import im.vector.app.R +import im.vector.app.core.extensions.getResTintedDrawable +import im.vector.app.core.extensions.getTintedDrawable +import im.vector.app.core.extensions.setLeftDrawable import im.vector.app.core.extensions.setTextWithColoredPart import im.vector.app.databinding.FragmentFtueAuthUseCaseBinding import im.vector.app.features.login.ServerType import im.vector.app.features.onboarding.FtueUseCase import im.vector.app.features.onboarding.OnboardingAction +import im.vector.app.features.themes.ThemeProvider import javax.inject.Inject -class FtueAuthUseCaseFragment @Inject constructor() : AbstractFtueAuthFragment() { +private const val DARK_MODE_ICON_BACKGROUND_ALPHA = 0.30f +private const val LIGHT_MODE_ICON_BACKGROUND_ALPHA = 0.15f + +class FtueAuthUseCaseFragment @Inject constructor( + private val themeProvider: ThemeProvider +) : AbstractFtueAuthFragment() { override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueAuthUseCaseBinding { return FragmentFtueAuthUseCaseBinding.inflate(inflater, container, false) @@ -42,9 +57,24 @@ class FtueAuthUseCaseFragment @Inject constructor() : AbstractFtueAuthFragment LIGHT_MODE_ICON_BACKGROUND_ALPHA + false -> DARK_MODE_ICON_BACKGROUND_ALPHA + } + val iconBackground = context.getResTintedDrawable(R.drawable.bg_feature_icon, tint, alpha = alpha) + val whiteLayer = context.getTintedDrawable(R.drawable.bg_feature_icon, Color.WHITE) + return LayerDrawable(arrayOf(whiteLayer, iconBackground, ContextCompat.getDrawable(context, icon))) + } } diff --git a/vector/src/main/res/drawable/bg_feature_icon.xml b/vector/src/main/res/drawable/bg_feature_icon.xml new file mode 100644 index 0000000000..299f1a4a2e --- /dev/null +++ b/vector/src/main/res/drawable/bg_feature_icon.xml @@ -0,0 +1,9 @@ + + + diff --git a/vector/src/main/res/drawable/ic_communities.xml b/vector/src/main/res/drawable/ic_communities.xml deleted file mode 100644 index f550de8106..0000000000 --- a/vector/src/main/res/drawable/ic_communities.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - diff --git a/vector/src/main/res/drawable/ic_friends_and_family.xml b/vector/src/main/res/drawable/ic_friends_and_family.xml deleted file mode 100644 index d7ac86f240..0000000000 --- a/vector/src/main/res/drawable/ic_friends_and_family.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - diff --git a/vector/src/main/res/drawable/ic_teams.xml b/vector/src/main/res/drawable/ic_teams.xml deleted file mode 100644 index 8745cfd2d4..0000000000 --- a/vector/src/main/res/drawable/ic_teams.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - diff --git a/vector/src/main/res/drawable/ic_use_case_communities.xml b/vector/src/main/res/drawable/ic_use_case_communities.xml new file mode 100644 index 0000000000..a511da6d2e --- /dev/null +++ b/vector/src/main/res/drawable/ic_use_case_communities.xml @@ -0,0 +1,10 @@ + + + diff --git a/vector/src/main/res/drawable/ic_use_case_friends.xml b/vector/src/main/res/drawable/ic_use_case_friends.xml new file mode 100644 index 0000000000..e4dea36774 --- /dev/null +++ b/vector/src/main/res/drawable/ic_use_case_friends.xml @@ -0,0 +1,10 @@ + + + diff --git a/vector/src/main/res/drawable/ic_use_case_teams.xml b/vector/src/main/res/drawable/ic_use_case_teams.xml new file mode 100644 index 0000000000..29b3def8cb --- /dev/null +++ b/vector/src/main/res/drawable/ic_use_case_teams.xml @@ -0,0 +1,10 @@ + + + diff --git a/vector/src/main/res/layout/fragment_ftue_auth_use_case.xml b/vector/src/main/res/layout/fragment_ftue_auth_use_case.xml index 594fc80696..d7e7bdc31a 100644 --- a/vector/src/main/res/layout/fragment_ftue_auth_use_case.xml +++ b/vector/src/main/res/layout/fragment_ftue_auth_use_case.xml @@ -89,7 +89,6 @@ android:padding="16dp" android:text="@string/ftue_auth_use_case_option_one" android:textColor="?vctr_content_primary" - app:drawableStartCompat="@drawable/ic_friends_and_family" app:layout_constraintBottom_toTopOf="@id/useCaseOptionTwo" app:layout_constraintEnd_toEndOf="@id/useCaseGutterEnd" app:layout_constraintStart_toStartOf="@id/useCaseGutterStart" @@ -107,7 +106,6 @@ android:padding="16dp" android:text="@string/ftue_auth_use_case_option_two" android:textColor="?vctr_content_primary" - app:drawableStartCompat="@drawable/ic_teams" app:layout_constraintBottom_toTopOf="@id/useCaseOptionThree" app:layout_constraintEnd_toEndOf="@id/useCaseGutterEnd" app:layout_constraintStart_toStartOf="@id/useCaseGutterStart" @@ -125,7 +123,6 @@ android:padding="16dp" android:text="@string/ftue_auth_use_case_option_three" android:textColor="?vctr_content_primary" - app:drawableStartCompat="@drawable/ic_communities" app:layout_constraintBottom_toTopOf="@id/useCaseSkip" app:layout_constraintEnd_toEndOf="@id/useCaseGutterEnd" app:layout_constraintStart_toStartOf="@id/useCaseGutterStart"