Skip to content

Commit

Permalink
Adds Paintable class to represent generic image
Browse files Browse the repository at this point in the history
  • Loading branch information
fstanis committed Dec 13, 2023
1 parent 29421eb commit 6daba44
Show file tree
Hide file tree
Showing 70 changed files with 637 additions and 612 deletions.
18 changes: 9 additions & 9 deletions auth/composables/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
package com.google.android.horologist.auth.composables.chips {

public final class AccountChipKt {
method @androidx.compose.runtime.Composable public static void AccountChip(com.google.android.horologist.auth.composables.model.AccountUiModel account, kotlin.jvm.functions.Function0<kotlin.Unit> onClick, optional androidx.compose.ui.Modifier modifier, optional Object? defaultAvatar, optional boolean largeAvatar, optional androidx.compose.ui.graphics.painter.Painter? placeholder, optional androidx.wear.compose.material.ChipColors colors, optional boolean enabled);
method @androidx.compose.runtime.Composable public static void AccountChip(String email, kotlin.jvm.functions.Function0<kotlin.Unit> onClick, optional androidx.compose.ui.Modifier modifier, optional Object? avatar, optional Object? defaultAvatar, optional boolean largeAvatar, optional androidx.compose.ui.graphics.painter.Painter? placeholder, optional androidx.wear.compose.material.ChipColors colors, optional boolean enabled);
method @androidx.compose.runtime.Composable public static void AccountChip(com.google.android.horologist.auth.composables.model.AccountUiModel account, kotlin.jvm.functions.Function0<kotlin.Unit> onClick, optional androidx.compose.ui.Modifier modifier, optional com.google.android.horologist.compose.material.Paintable? defaultAvatar, optional boolean largeAvatar, optional androidx.wear.compose.material.ChipColors colors, optional boolean enabled);
method @androidx.compose.runtime.Composable public static void AccountChip(String email, kotlin.jvm.functions.Function0<kotlin.Unit> onClick, optional androidx.compose.ui.Modifier modifier, optional com.google.android.horologist.compose.material.Paintable? avatar, optional com.google.android.horologist.compose.material.Paintable? defaultAvatar, optional boolean largeAvatar, optional androidx.wear.compose.material.ChipColors colors, optional boolean enabled);
}

public final class CreateAccountChipKt {
Expand All @@ -27,7 +27,7 @@ package com.google.android.horologist.auth.composables.chips {
package com.google.android.horologist.auth.composables.dialogs {

public final class SignedInConfirmationDialogKt {
method @androidx.compose.runtime.Composable public static void SignedInConfirmationDialog(kotlin.jvm.functions.Function0<kotlin.Unit> onDismissOrTimeout, optional androidx.compose.ui.Modifier modifier, optional String? name, optional String? email, optional Object? avatar, optional java.time.Duration duration);
method @androidx.compose.runtime.Composable public static void SignedInConfirmationDialog(kotlin.jvm.functions.Function0<kotlin.Unit> onDismissOrTimeout, optional androidx.compose.ui.Modifier modifier, optional String? name, optional String? email, optional com.google.android.horologist.compose.material.Paintable? avatar, optional java.time.Duration duration);
method @androidx.compose.runtime.Composable public static void SignedInConfirmationDialog(kotlin.jvm.functions.Function0<kotlin.Unit> onDismissOrTimeout, optional androidx.compose.ui.Modifier modifier, com.google.android.horologist.auth.composables.model.AccountUiModel accountUiModel, optional java.time.Duration duration);
}

Expand All @@ -36,15 +36,15 @@ package com.google.android.horologist.auth.composables.dialogs {
package com.google.android.horologist.auth.composables.model {

public final class AccountUiModel {
ctor public AccountUiModel(String email, optional String? name, optional Object? avatar);
ctor public AccountUiModel(String email, optional String? name, optional com.google.android.horologist.compose.material.Paintable? avatar);
method public String component1();
method public String? component2();
method public Object? component3();
method public com.google.android.horologist.auth.composables.model.AccountUiModel copy(String email, String? name, Object? avatar);
method public Object? getAvatar();
method public com.google.android.horologist.compose.material.Paintable? component3();
method public com.google.android.horologist.auth.composables.model.AccountUiModel copy(String email, String? name, com.google.android.horologist.compose.material.Paintable? avatar);
method public com.google.android.horologist.compose.material.Paintable? getAvatar();
method public String getEmail();
method public String? getName();
property public final Object? avatar;
property public final com.google.android.horologist.compose.material.Paintable? avatar;
property public final String email;
property public final String? name;
}
Expand All @@ -63,7 +63,7 @@ package com.google.android.horologist.auth.composables.screens {
}

public final class SelectAccountScreenKt {
method @androidx.compose.runtime.Composable public static void SelectAccountScreen(java.util.List<com.google.android.horologist.auth.composables.model.AccountUiModel> accounts, kotlin.jvm.functions.Function2<? super java.lang.Integer,? super com.google.android.horologist.auth.composables.model.AccountUiModel,kotlin.Unit> onAccountClicked, com.google.android.horologist.compose.layout.ScalingLazyColumnState columnState, optional androidx.compose.ui.Modifier modifier, optional String title, optional Object? defaultAvatar);
method @androidx.compose.runtime.Composable public static void SelectAccountScreen(java.util.List<com.google.android.horologist.auth.composables.model.AccountUiModel> accounts, kotlin.jvm.functions.Function2<? super java.lang.Integer,? super com.google.android.horologist.auth.composables.model.AccountUiModel,kotlin.Unit> onAccountClicked, com.google.android.horologist.compose.layout.ScalingLazyColumnState columnState, optional androidx.compose.ui.Modifier modifier, optional String title, optional com.google.android.horologist.compose.material.Paintable? defaultAvatar);
}

public final class SignInPlaceholderScreenKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.text.style.LineBreak
import androidx.wear.compose.material.ChipColors
import androidx.wear.compose.material.ChipDefaults
import androidx.wear.compose.material.MaterialTheme
import com.google.android.horologist.auth.composables.model.AccountUiModel
import com.google.android.horologist.compose.material.Chip
import com.google.android.horologist.compose.material.ImageVectorPaintable.Companion.asPaintable
import com.google.android.horologist.compose.material.Paintable

/**
* A [Chip] to display the [AccountUiModel]'s email address and avatar.
Expand All @@ -38,9 +39,8 @@ public fun AccountChip(
account: AccountUiModel,
onClick: () -> Unit,
modifier: Modifier = Modifier,
defaultAvatar: Any? = Icons.Default.AccountCircle,
defaultAvatar: Paintable? = Icons.Default.AccountCircle.asPaintable(),
largeAvatar: Boolean = true,
placeholder: Painter? = null,
colors: ChipColors = ChipDefaults.primaryChipColors(),
enabled: Boolean = true,
) {
Expand All @@ -51,7 +51,6 @@ public fun AccountChip(
avatar = account.avatar,
defaultAvatar = defaultAvatar,
largeAvatar = largeAvatar,
placeholder = placeholder,
colors = colors,
enabled = enabled,
)
Expand All @@ -67,10 +66,9 @@ public fun AccountChip(
email: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
avatar: Any? = null,
defaultAvatar: Any? = Icons.Default.AccountCircle,
avatar: Paintable? = null,
defaultAvatar: Paintable? = Icons.Default.AccountCircle.asPaintable(),
largeAvatar: Boolean = true,
placeholder: Painter? = null,
colors: ChipColors = ChipDefaults.primaryChipColors(),
enabled: Boolean = true,
) {
Expand All @@ -91,7 +89,6 @@ public fun AccountChip(
modifier = modifier,
icon = avatar ?: defaultAvatar,
largeIcon = largeAvatar,
placeholder = placeholder,
colors = colors,
enabled = enabled,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.wear.compose.material.ChipDefaults
import androidx.wear.compose.material.Icon
import com.google.android.horologist.auth.composables.R
import com.google.android.horologist.compose.material.Chip
import com.google.android.horologist.compose.material.ImageVectorPaintable.Companion.asPaintable
import com.google.android.horologist.compose.material.util.DECORATIVE_ELEMENT_CONTENT_DESCRIPTION

/**
Expand Down Expand Up @@ -71,7 +72,7 @@ public fun CreateAccountChip(
label = label,
onClick = onClick,
modifier = modifier,
icon = Icons.AutoMirrored.Outlined.SendToMobile,
icon = Icons.AutoMirrored.Outlined.SendToMobile.asPaintable(),
colors = colors,
enabled = enabled,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.wear.compose.material.ChipColors
import androidx.wear.compose.material.ChipDefaults
import com.google.android.horologist.auth.composables.R
import com.google.android.horologist.compose.material.Chip
import com.google.android.horologist.compose.material.ImageVectorPaintable.Companion.asPaintable

/**
* An opinionated [Chip] to represent the "Guest mode" action.
Expand All @@ -45,7 +46,7 @@ public fun GuestModeChip(
label = label,
onClick = onClick,
modifier = modifier,
icon = Icons.AutoMirrored.Default.ArrowForward,
icon = Icons.AutoMirrored.Default.ArrowForward.asPaintable(),
colors = colors,
enabled = enabled,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.wear.compose.material.ChipColors
import androidx.wear.compose.material.ChipDefaults
import com.google.android.horologist.auth.composables.R
import com.google.android.horologist.compose.material.Chip
import com.google.android.horologist.compose.material.ImageVectorPaintable.Companion.asPaintable

/**
* An opinionated [Chip] to represent the "Other options to authentication" action.
Expand All @@ -43,7 +44,7 @@ public fun OtherOptionsChip(
label = label,
onClick = onClick,
modifier = modifier,
icon = Icons.AutoMirrored.Outlined.SendToMobile,
icon = Icons.AutoMirrored.Outlined.SendToMobile.asPaintable(),
colors = colors,
enabled = enabled,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.wear.compose.material.ChipColors
import androidx.wear.compose.material.ChipDefaults
import com.google.android.horologist.auth.composables.R
import com.google.android.horologist.compose.material.Chip
import com.google.android.horologist.compose.material.ImageVectorPaintable.Companion.asPaintable

/**
* An opinionated [Chip] to represent the "Sign in" action.
Expand All @@ -45,7 +46,7 @@ public fun SignInChip(
label = label,
onClick = onClick,
modifier = modifier,
icon = Icons.Default.AccountCircle,
icon = Icons.Default.AccountCircle.asPaintable(),
colors = colors,
enabled = enabled,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ import androidx.compose.ui.unit.sp
import androidx.wear.compose.material.MaterialTheme
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.dialog.DialogDefaults
import coil.compose.rememberAsyncImagePainter
import com.google.android.horologist.auth.composables.R
import com.google.android.horologist.auth.composables.model.AccountUiModel
import com.google.android.horologist.compose.material.Confirmation
import com.google.android.horologist.compose.material.Paintable
import com.google.android.horologist.compose.material.util.DECORATIVE_ELEMENT_CONTENT_DESCRIPTION
import java.time.Duration

Expand All @@ -63,7 +63,7 @@ public fun SignedInConfirmationDialog(
modifier: Modifier = Modifier,
name: String? = null,
email: String? = null,
avatar: Any? = null,
avatar: Paintable? = null,
duration: Duration = Duration.ofMillis(DialogDefaults.ShortDurationMillis),
) {
Confirmation(
Expand Down Expand Up @@ -108,7 +108,7 @@ private fun SignedInConfirmationDialogContent(
modifier: Modifier = Modifier,
name: String? = null,
email: String? = null,
avatar: Any? = null,
avatar: Paintable? = null,
) {
val configuration = LocalConfiguration.current
val horizontalPadding = (configuration.screenWidthDp * HORIZONTAL_PADDING_SCREEN_PERCENTAGE).dp
Expand All @@ -121,18 +121,17 @@ private fun SignedInConfirmationDialogContent(
horizontalAlignment = Alignment.CenterHorizontally,
) {
val hasName = !name.isNullOrEmpty()
val hasAvatar = avatar != null

Box(
modifier = Modifier
.size(60.dp)
.background(color = Color(AVATAR_BACKGROUND_COLOR), shape = CircleShape),
contentAlignment = Alignment.Center,
) {
if (hasAvatar) {
if (avatar != null) {
Image(
modifier = Modifier.clip(CircleShape),
painter = rememberAsyncImagePainter(model = avatar),
painter = avatar.rememberPainter(),
contentDescription = DECORATIVE_ELEMENT_CONTENT_DESCRIPTION,
contentScale = ContentScale.Fit,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

package com.google.android.horologist.auth.composables.model

import com.google.android.horologist.compose.material.Paintable

/**
* A UI model to represent an account.
*/
public data class AccountUiModel(
val email: String,
val name: String? = null,
val avatar: Any? = null,
val avatar: Paintable? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import com.google.android.horologist.auth.composables.chips.AccountChip
import com.google.android.horologist.auth.composables.model.AccountUiModel
import com.google.android.horologist.compose.layout.ScalingLazyColumn
import com.google.android.horologist.compose.layout.ScalingLazyColumnState
import com.google.android.horologist.compose.material.ImageVectorPaintable.Companion.asPaintable
import com.google.android.horologist.compose.material.Paintable
import com.google.android.horologist.compose.material.Title

private const val HORIZONTAL_PADDING_SCREEN_PERCENTAGE = 0.052
Expand All @@ -49,7 +51,7 @@ public fun SelectAccountScreen(
columnState: ScalingLazyColumnState,
modifier: Modifier = Modifier,
title: String = stringResource(id = R.string.horologist_select_account_title),
defaultAvatar: Any? = Icons.Default.AccountCircle,
defaultAvatar: Paintable? = Icons.Default.AccountCircle.asPaintable(),
) {
val configuration = LocalConfiguration.current
val horizontalPadding = (configuration.screenWidthDp * HORIZONTAL_PADDING_SCREEN_PERCENTAGE).dp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.google.android.horologist.compose.material.DrawableResPaintable
import com.google.android.horologist.compose.tools.coil.FakeImageLoader
import com.google.android.horologist.screenshots.ScreenshotBaseTest
import com.google.android.horologist.screenshots.ScreenshotTestRule.Companion.screenshotTestRuleParams
Expand All @@ -46,7 +47,7 @@ class SignedInConfirmationDialogTest : ScreenshotBaseTest(
onDismissOrTimeout = {},
name = "Maggie",
email = "maggie@example.com",
avatar = android.R.drawable.sym_def_app_icon,
avatar = DrawableResPaintable(android.R.drawable.sym_def_app_icon),
)
}
}
Expand All @@ -61,7 +62,7 @@ class SignedInConfirmationDialogTest : ScreenshotBaseTest(
SignedInConfirmationDialog(
onDismissOrTimeout = {},
email = "maggie@example.com",
avatar = android.R.drawable.sym_def_app_icon,
avatar = DrawableResPaintable(android.R.drawable.sym_def_app_icon),
)
}
}
Expand All @@ -76,7 +77,7 @@ class SignedInConfirmationDialogTest : ScreenshotBaseTest(
onDismissOrTimeout = {},
name = "",
email = "maggie@example.com",
avatar = android.R.drawable.sym_def_app_icon,
avatar = DrawableResPaintable(android.R.drawable.sym_def_app_icon),
)
}
}
Expand All @@ -100,7 +101,7 @@ class SignedInConfirmationDialogTest : ScreenshotBaseTest(
SignedInConfirmationDialog(
onDismissOrTimeout = {},
name = "Maggie",
avatar = android.R.drawable.sym_def_app_icon,
avatar = DrawableResPaintable(android.R.drawable.sym_def_app_icon),
)
}
}
Expand All @@ -122,7 +123,7 @@ class SignedInConfirmationDialogTest : ScreenshotBaseTest(
onDismissOrTimeout = {},
name = "Wolfeschlegelsteinhausenbergerdorff",
email = "wolfeschlegelsteinhausenbergerdorff@example.com",
avatar = android.R.drawable.sym_def_app_icon,
avatar = DrawableResPaintable(android.R.drawable.sym_def_app_icon),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Face
import com.google.android.horologist.auth.composables.model.AccountUiModel
import com.google.android.horologist.compose.layout.ScalingLazyColumnDefaults
import com.google.android.horologist.compose.material.ImageVectorPaintable.Companion.asPaintable
import com.google.android.horologist.screenshots.ScreenshotBaseTest
import com.google.android.horologist.screenshots.ScreenshotTestRule.Companion.screenshotTestRuleParams
import org.junit.Test
Expand All @@ -37,7 +38,7 @@ class SelectAccountScreenTest : ScreenshotBaseTest(
accounts = listOf(
AccountUiModel(
email = "maggie@example.com",
avatar = Icons.Default.Face,
avatar = Icons.Default.Face.asPaintable(),
),
AccountUiModel(email = "thisisaverylongemail@example.com"),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.google.android.horologist.auth.ui.googlesignin.mapper

import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.horologist.auth.composables.model.AccountUiModel
import com.google.android.horologist.compose.material.CoilPaintable

/**
* Functions to map models from Google Sign In into a [AccountUiModel].
Expand All @@ -33,6 +34,6 @@ public object AccountUiModelMapper {
): AccountUiModel = AccountUiModel(
email = account.email ?: defaultEmail,
name = account.displayName,
avatar = account.photoUrl,
avatar = CoilPaintable(account.photoUrl),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.google.android.horologist.auth.ui.mapper

import com.google.android.horologist.auth.composables.model.AccountUiModel
import com.google.android.horologist.auth.data.common.model.AuthUser
import com.google.android.horologist.compose.material.CoilPaintable

/**
* Functions to map models from other layers and / or packages into a [AccountUiModel].
Expand All @@ -30,6 +31,6 @@ public object AccountUiModelMapper {
public fun map(authUser: AuthUser, defaultEmail: String = ""): AccountUiModel = AccountUiModel(
email = authUser.email ?: defaultEmail,
name = authUser.displayName,
avatar = authUser.avatarUri,
avatar = CoilPaintable(authUser.avatarUri),
)
}
Loading

0 comments on commit 6daba44

Please sign in to comment.