|
| 1 | +package com.edricchan.studybuddy.core.auth.ui |
| 2 | + |
| 3 | +import android.net.Uri |
| 4 | +import androidx.compose.foundation.layout.Arrangement |
| 5 | +import androidx.compose.foundation.layout.Column |
| 6 | +import androidx.compose.foundation.layout.Row |
| 7 | +import androidx.compose.foundation.layout.RowScope |
| 8 | +import androidx.compose.foundation.layout.padding |
| 9 | +import androidx.compose.material3.MaterialTheme |
| 10 | +import androidx.compose.material3.Text |
| 11 | +import androidx.compose.runtime.Composable |
| 12 | +import androidx.compose.ui.Alignment |
| 13 | +import androidx.compose.ui.Modifier |
| 14 | +import androidx.compose.ui.res.stringResource |
| 15 | +import androidx.compose.ui.tooling.preview.Preview |
| 16 | +import androidx.compose.ui.unit.dp |
| 17 | +import com.edricchan.studybuddy.core.auth.common.R |
| 18 | +import com.edricchan.studybuddy.core.auth.model.User |
| 19 | +import com.edricchan.studybuddy.ui.theming.compose.StudyBuddyTheme |
| 20 | + |
| 21 | +@Composable |
| 22 | +fun AccountInfoRow( |
| 23 | + modifier: Modifier = Modifier, |
| 24 | + profileImage: @Composable RowScope.() -> Unit, |
| 25 | + metadata: @Composable RowScope.() -> Unit |
| 26 | +) = Row( |
| 27 | + modifier = modifier, |
| 28 | + verticalAlignment = Alignment.CenterVertically, |
| 29 | + horizontalArrangement = Arrangement.spacedBy(16.dp) |
| 30 | +) { |
| 31 | + profileImage() |
| 32 | + |
| 33 | + metadata() |
| 34 | +} |
| 35 | + |
| 36 | +@Composable |
| 37 | +fun AccountInfoRow( |
| 38 | + modifier: Modifier = Modifier, |
| 39 | + displayName: String, |
| 40 | + email: String?, |
| 41 | + photoUri: Uri?, |
| 42 | +) = AccountInfoRow( |
| 43 | + modifier = modifier, |
| 44 | + profileImage = { |
| 45 | + ProfileImage(displayName = displayName, photoUri = photoUri) |
| 46 | + }, |
| 47 | + metadata = { |
| 48 | + Column { |
| 49 | + Text(text = displayName, style = MaterialTheme.typography.titleMedium) |
| 50 | + email?.let { Text(text = it, style = MaterialTheme.typography.titleSmall) } |
| 51 | + } |
| 52 | + } |
| 53 | +) |
| 54 | + |
| 55 | +@Composable |
| 56 | +fun AccountInfoRow( |
| 57 | + modifier: Modifier = Modifier, |
| 58 | + user: User |
| 59 | +) = AccountInfoRow( |
| 60 | + modifier = modifier, |
| 61 | + displayName = user.displayName ?: stringResource(R.string.account_anon_display_name), |
| 62 | + email = user.email, |
| 63 | + photoUri = user.photoUri |
| 64 | +) |
| 65 | + |
| 66 | +@Preview(showBackground = true) |
| 67 | +@Composable |
| 68 | +private fun AccountInfoRowPreview() { |
| 69 | + StudyBuddyTheme { |
| 70 | + AccountInfoRow( |
| 71 | + modifier = Modifier.padding(16.dp), |
| 72 | + displayName = "John Appleseed", |
| 73 | + email = "example@example.com", |
| 74 | + photoUri = null |
| 75 | + ) |
| 76 | + } |
| 77 | +} |
0 commit comments