-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add common
AccountInfoRow
composable (#585)
* Add string for default display name
- Loading branch information
1 parent
148ffbb
commit 691bfd7
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
core/auth/ui/compose/src/main/kotlin/com/edricchan/studybuddy/core/auth/ui/AccountInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} |