Skip to content

feat: Replace UserAvatar module with Avatar and remove it altogether #461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Coil/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ android {
}

dependencies {
implementation(project(":Core:Auth"))
api(project(":Core:Auth"))
implementation(project(":Core:Avatar"))
implementation(project(":Core:Network"))

Expand Down
3 changes: 2 additions & 1 deletion CrossAppLoginUI/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ android {
dependencies {

implementation(project(":Core"))
implementation(project(":Core:Avatar"))
implementation(project(":Core:Coil"))
implementation(project(":Core:Compose:Basics"))
implementation(project(":Core:Compose:Margin"))
implementation(project(":Core:Compose:MaterialThemeFromXml"))
implementation(project(":Core:CrossAppLogin"))
implementation(project(":Core:UserAvatar"))

implementation(core.androidx.core.ktx)
implementation(core.material)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,61 @@
package com.infomaniak.core.crossloginui.components

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import com.infomaniak.core.avatar.components.Avatar
import com.infomaniak.core.avatar.getBackgroundColorResBasedOnId
import com.infomaniak.core.avatar.models.AvatarColors
import com.infomaniak.core.avatar.models.AvatarType
import com.infomaniak.core.avatar.models.AvatarUrlData
import com.infomaniak.core.coil.ImageLoaderProvider
import com.infomaniak.core.crossloginui.data.CrossLoginDefaults
import com.infomaniak.core.crossloginui.previews.AccountsPreviewParameter
import com.infomaniak.core.login.crossapp.ExternalAccount
import com.infomaniak.core.useravatar.AvatarData
import com.infomaniak.core.useravatar.exposed.UserAvatar

@Composable
internal fun Avatar(modifier: Modifier = Modifier, account: ExternalAccount, strokeColor: Color? = null) {
UserAvatar(
internal fun CrossLoginAvatar(modifier: Modifier = Modifier, account: ExternalAccount, strokeColor: Color? = null) {
val context = LocalContext.current
val unauthenticatedImageLoader = remember(context) { ImageLoaderProvider.newImageLoader(context) }

Avatar(
avatarType = AvatarType.getUrlOrInitials(
account.avatarUrl?.let { AvatarUrlData(it, unauthenticatedImageLoader) },
initials = account.initials,
colors = AvatarColors(
// TODO: Adapt colors correctly for each app
containerColor = Color(context.getBackgroundColorResBasedOnId(account.id.toInt())),
// TODO: Adapt colors correctly for each app
contentColor = getDefaultIconColor(),
),
),
modifier = modifier,
avatarData = AvatarData(id = account.id.toString(), uri = account.avatarUrl, userInitials = account.initials),
border = strokeColor?.let { BorderStroke(width = 1.dp, color = it) },
)
}

// Copied from old UserAvatar module to keep old behavior
// TODO: Remove this when using CoreUi
private const val iconColorDark = 0xFF333333

@Composable
private fun getDefaultIconColor() = if (isSystemInDarkTheme()) Color(iconColorDark) else Color.White

@Preview
@Composable
private fun Preview(@PreviewParameter(AccountsPreviewParameter::class) accounts: List<ExternalAccount>) {
MaterialTheme {
Surface {
Avatar(
CrossLoginAvatar(
account = accounts.first(),
strokeColor = CrossLoginDefaults.colors().avatarStrokeColor,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal fun SingleAccount(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically,
) {
Avatar(
CrossLoginAvatar(
modifier = Modifier
.size(Dimens.bigAvatarSize)
.clip(CircleShape),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal fun ThreeAccountsView(

Row {
// Left
Avatar(
CrossLoginAvatar(
modifier = Modifier.size(Dimens.iconSize),
account = accounts[1],
strokeColor = avatarStrokeColor,
Expand All @@ -53,15 +53,15 @@ internal fun ThreeAccountsView(
Spacer(Modifier.width(width = Dimens.avatarsBoxWidth - (Dimens.iconSize + Dimens.iconSize)))

// Right
Avatar(
CrossLoginAvatar(
modifier = Modifier.size(Dimens.iconSize),
account = accounts[2],
strokeColor = avatarStrokeColor,
)
}

// Center
Avatar(
CrossLoginAvatar(
modifier = Modifier.size(Dimens.avatarsBoxHeight),
account = accounts[0],
strokeColor = avatarStrokeColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal fun TwoAccountsView(
) {

// Right
Avatar(
CrossLoginAvatar(
modifier = Modifier
.size(Dimens.avatarsBoxHeight)
.align(Alignment.CenterEnd),
Expand All @@ -54,7 +54,7 @@ internal fun TwoAccountsView(
)

// Left
Avatar(
CrossLoginAvatar(
modifier = Modifier
.size(Dimens.avatarsBoxHeight)
.align(Alignment.CenterStart),
Expand Down
1 change: 1 addition & 0 deletions MyKSuite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies {

implementation(project(":Core"))
implementation(project(":Core:Avatar"))
implementation(project(":Core:Coil"))
implementation(project(":Core:Compose:Basics"))
implementation(project(":Core:Compose:Margin"))
implementation(project(":Core:Compose:MaterialThemeFromXml"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ package com.infomaniak.core.myksuite.ui.data
import android.os.Parcelable
import androidx.annotation.ColorInt
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import coil3.SingletonImageLoader
import coil3.compose.LocalPlatformContext
import androidx.compose.ui.platform.LocalContext
import com.infomaniak.core.avatar.models.AvatarColors
import com.infomaniak.core.avatar.models.AvatarType
import com.infomaniak.core.avatar.models.AvatarUrlData
import com.infomaniak.core.coil.ImageLoaderProvider
import kotlinx.parcelize.Parcelize

@Parcelize
Expand All @@ -38,8 +39,11 @@ data class AvatarData(
) : Parcelable {
@Composable
fun toAvatarType(): AvatarType {
val context = LocalContext.current
val unauthenticatedImageLoader = remember(context) { ImageLoaderProvider.newImageLoader(context) }

return AvatarType.getUrlOrInitials(
avatarUrlData = uri?.let { AvatarUrlData(it, SingletonImageLoader.get(LocalPlatformContext.current)) },
avatarUrlData = uri?.let { AvatarUrlData(it, unauthenticatedImageLoader) },
initials = userInitials,
colors = AvatarColors(
containerColor = Color(backgroundColor),
Expand Down
52 changes: 0 additions & 52 deletions UserAvatar/build.gradle.kts

This file was deleted.

Empty file removed UserAvatar/consumer-rules.pro
Empty file.
21 changes: 0 additions & 21 deletions UserAvatar/proguard-rules.pro

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading