-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8644 from wmontwe/add-account-avatar
Add account avatar
- Loading branch information
Showing
6 changed files
with
147 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
plugins { | ||
id(ThunderbirdPlugins.Library.androidCompose) | ||
} | ||
|
||
android { | ||
namespace = "app.k9mail.feature.account.avatar" | ||
resourcePrefix = "account_avatar_" | ||
} | ||
|
||
dependencies { | ||
implementation(projects.core.ui.compose.designsystem) | ||
implementation(projects.core.common) | ||
|
||
testImplementation(projects.core.ui.compose.testing) | ||
} |
30 changes: 30 additions & 0 deletions
30
...ure/account/avatar/src/debug/kotlin/app/k9mail/feature/account/avatar/ui/AvatarPreview.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package app.k9mail.feature.account.avatar.ui | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import app.k9mail.core.ui.compose.designsystem.PreviewWithThemes | ||
|
||
@Composable | ||
@Preview(showBackground = true) | ||
internal fun AvatarPreview() { | ||
PreviewWithThemes { | ||
Avatar( | ||
color = Color(0xFFe57373), | ||
name = "example", | ||
selected = false, | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
@Preview(showBackground = true) | ||
internal fun AvatarSelectedPreview() { | ||
PreviewWithThemes { | ||
Avatar( | ||
color = Color(0xFFe57373), | ||
name = "example", | ||
selected = true, | ||
) | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
feature/account/avatar/src/main/kotlin/app/k9mail/feature/account/avatar/ui/Avatar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package app.k9mail.feature.account.avatar.ui | ||
|
||
import androidx.compose.animation.core.animateDpAsState | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
import app.k9mail.core.ui.compose.designsystem.atom.Surface | ||
import app.k9mail.core.ui.compose.designsystem.atom.text.TextTitleMedium | ||
import app.k9mail.core.ui.compose.theme2.MainTheme | ||
|
||
val selectedAvatarSize = 40.dp | ||
|
||
@Composable | ||
fun Avatar( | ||
color: Color, | ||
name: String, | ||
selected: Boolean, | ||
modifier: Modifier = Modifier, | ||
onClick: (() -> Unit)? = null, | ||
) { | ||
val avatarSize by animateDpAsState( | ||
targetValue = if (selected) selectedAvatarSize else MainTheme.sizes.iconAvatar, | ||
label = "Avatar size", | ||
) | ||
|
||
Box( | ||
modifier = modifier | ||
.clip(CircleShape) | ||
.clickable(enabled = onClick != null && !selected, onClick = { onClick?.invoke() }), | ||
contentAlignment = Alignment.Center, | ||
) { | ||
AvatarOutline( | ||
color = color, | ||
modifier = Modifier.size(avatarSize), | ||
) { | ||
AvatarPlaceholder( | ||
displayName = name, | ||
) | ||
// TODO: Add image loading | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun AvatarOutline( | ||
color: Color, | ||
modifier: Modifier = Modifier, | ||
content: @Composable () -> Unit, | ||
) { | ||
Surface( | ||
modifier = modifier | ||
.clip(CircleShape) | ||
.border(2.dp, color, CircleShape) | ||
.padding(2.dp), | ||
color = color.copy(alpha = 0.3f), | ||
) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.border(2.dp, MainTheme.colors.surfaceContainerLowest, CircleShape), | ||
contentAlignment = Alignment.Center, | ||
) { | ||
content() | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun AvatarPlaceholder( | ||
displayName: String, | ||
modifier: Modifier = Modifier, | ||
) { | ||
TextTitleMedium( | ||
text = extractNameInitials(displayName).uppercase(), | ||
modifier = modifier, | ||
) | ||
} | ||
|
||
private fun extractNameInitials(displayName: String): String { | ||
return displayName.take(2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters