Skip to content

Commit

Permalink
Add common AccountInfoRow composable (#585)
Browse files Browse the repository at this point in the history
* Add string for default display name
  • Loading branch information
EdricChan03 committed Dec 19, 2024
1 parent 148ffbb commit 691bfd7
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/auth/ui/common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<!-- Content description for the user's profile picture. -->
<string name="account_profile_content_desc">Profile photo for %1$s</string>

<!-- The user's display name if no user is signed in. -->
<string name="account_anon_display_name">Anonymous/Not signed in</string>

<!-- Auth required dialog strings -->
<eat-comment />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.edricchan.studybuddy.core.auth.ui

import android.net.Uri
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.edricchan.studybuddy.core.auth.common.R
import com.edricchan.studybuddy.core.auth.model.User
import com.edricchan.studybuddy.ui.theming.compose.StudyBuddyTheme

@Composable
fun AccountInfoRow(
modifier: Modifier = Modifier,
profileImage: @Composable RowScope.() -> Unit,
metadata: @Composable RowScope.() -> Unit
) = Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(16.dp)
) {
profileImage()

metadata()
}

@Composable
fun AccountInfoRow(
modifier: Modifier = Modifier,
displayName: String,
email: String?,
photoUri: Uri?,
) = AccountInfoRow(
modifier = modifier,
profileImage = {
ProfileImage(displayName = displayName, photoUri = photoUri)
},
metadata = {
Column {
Text(text = displayName, style = MaterialTheme.typography.titleMedium)
email?.let { Text(text = it, style = MaterialTheme.typography.titleSmall) }
}
}
)

@Composable
fun AccountInfoRow(
modifier: Modifier = Modifier,
user: User
) = AccountInfoRow(
modifier = modifier,
displayName = user.displayName ?: stringResource(R.string.account_anon_display_name),
email = user.email,
photoUri = user.photoUri
)

@Preview(showBackground = true)
@Composable
private fun AccountInfoRowPreview() {
StudyBuddyTheme {
AccountInfoRow(
modifier = Modifier.padding(16.dp),
displayName = "John Appleseed",
email = "[email protected]",
photoUri = null
)
}
}

0 comments on commit 691bfd7

Please sign in to comment.