@@ -5,21 +5,19 @@ import androidx.compose.foundation.layout.Arrangement
55import androidx.compose.foundation.layout.Column
66import androidx.compose.foundation.layout.Row
77import androidx.compose.foundation.layout.RowScope
8- import androidx.compose.foundation.layout.fillMaxHeight
98import androidx.compose.foundation.layout.padding
10- import androidx.compose.material.icons.Icons
11- import androidx.compose.material.icons.outlined.AccountCircle
12- import androidx.compose.material3.Icon
139import androidx.compose.material3.MaterialTheme
1410import androidx.compose.material3.Text
1511import androidx.compose.runtime.Composable
1612import androidx.compose.ui.Alignment
1713import androidx.compose.ui.Modifier
1814import androidx.compose.ui.res.stringResource
1915import androidx.compose.ui.tooling.preview.Preview
16+ import androidx.compose.ui.tooling.preview.PreviewParameter
2017import androidx.compose.ui.unit.dp
2118import com.edricchan.studybuddy.core.auth.common.R
2219import com.edricchan.studybuddy.core.auth.model.User
20+ import com.edricchan.studybuddy.core.auth.preview.UserPreviewParameterProvider
2321import com.edricchan.studybuddy.ui.theming.compose.StudyBuddyTheme
2422
2523@Composable
@@ -37,28 +35,84 @@ fun AccountInfoRow(
3735 metadata()
3836}
3937
38+ @Composable
39+ private fun AccountInfoMetadataTitleText (
40+ modifier : Modifier = Modifier ,
41+ text : String
42+ ) {
43+ Text (
44+ modifier = modifier,
45+ text = text,
46+ style = MaterialTheme .typography.titleMedium
47+ )
48+ }
49+
50+ @Composable
51+ private fun AccountInfoMetadataSubtitleText (
52+ modifier : Modifier = Modifier ,
53+ text : String
54+ ) {
55+ Text (
56+ modifier = modifier,
57+ text = text,
58+ style = MaterialTheme .typography.titleSmall
59+ )
60+ }
61+
62+ @Composable
63+ private fun AccountInfoMetadata (
64+ modifier : Modifier = Modifier ,
65+ displayName : String? ,
66+ email : String?
67+ ) = Column (modifier = modifier) {
68+ when {
69+ ! email.isNullOrBlank() && ! displayName.isNullOrBlank() -> {
70+ AccountInfoMetadataTitleText (
71+ text = displayName
72+ )
73+ AccountInfoMetadataSubtitleText (
74+ text = email
75+ )
76+ }
77+
78+ // Show just the email address as title text if we don't have a display name present
79+ ! email.isNullOrBlank() -> {
80+ AccountInfoMetadataTitleText (
81+ text = email
82+ )
83+ }
84+
85+ // Show just the display name as title text if there's no email address
86+ ! displayName.isNullOrBlank() -> {
87+ AccountInfoMetadataTitleText (
88+ text = displayName
89+ )
90+ }
91+
92+ else -> {
93+ AccountInfoMetadataTitleText (
94+ text = stringResource(R .string.account_anon_display_name)
95+ )
96+ }
97+ }
98+ }
99+
40100@Composable
41101fun AccountInfoRow (
42102 modifier : Modifier = Modifier ,
43- displayName : String ,
103+ displayName : String? ,
44104 email : String? ,
45105 photoUri : Uri ? ,
46106) = AccountInfoRow (
47107 modifier = modifier,
48108 profileImage = {
49- photoUri?.let {
50- ProfileImage (displayName = displayName, photoUri = it)
51- } ? : Icon (
52- modifier = Modifier .fillMaxHeight(),
53- imageVector = Icons .Outlined .AccountCircle ,
54- contentDescription = stringResource(R .string.account_profile_content_desc, displayName)
55- )
109+ ProfileImage (displayName = displayName, photoUri = photoUri)
56110 },
57111 metadata = {
58- Column {
59- Text (text = displayName, style = MaterialTheme .typography.titleMedium)
60- email?. let { Text (text = it, style = MaterialTheme .typography.titleSmall) }
61- }
112+ AccountInfoMetadata (
113+ displayName = displayName,
114+ email = email
115+ )
62116 }
63117)
64118
@@ -68,20 +122,18 @@ fun AccountInfoRow(
68122 user : User
69123) = AccountInfoRow (
70124 modifier = modifier,
71- displayName = user.displayName ? : stringResource( R .string.account_anon_display_name) ,
125+ displayName = user.displayName,
72126 email = user.email,
73127 photoUri = user.photoUri
74128)
75129
76- @Preview(showBackground = true )
130+ @Preview
77131@Composable
78- private fun AccountInfoRowPreview () {
132+ private fun AccountInfoRowPreview (@PreviewParameter( UserPreviewParameterProvider :: class ) user : User ) {
79133 StudyBuddyTheme {
80134 AccountInfoRow (
81135 modifier = Modifier .padding(16 .dp),
82- displayName = " John Appleseed" ,
83- email = " example@example.com" ,
84- photoUri = null
136+ user = user
85137 )
86138 }
87139}
0 commit comments