Skip to content

Commit 691bfd7

Browse files
committed
Add common AccountInfoRow composable (#585)
* Add string for default display name
1 parent 148ffbb commit 691bfd7

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

core/auth/ui/common/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
<!-- Content description for the user's profile picture. -->
77
<string name="account_profile_content_desc">Profile photo for %1$s</string>
88

9+
<!-- The user's display name if no user is signed in. -->
10+
<string name="account_anon_display_name">Anonymous/Not signed in</string>
11+
912
<!-- Auth required dialog strings -->
1013
<eat-comment />
1114

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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

Comments
 (0)