-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edured-103: Prepare to add enable/disable biometric calls.
Refactoring expandable card so it can more easily separate functionality for expanded actions. ConnectionCard shows information for linked institutions.
- Loading branch information
Iulia Stana
committed
May 4, 2023
1 parent
e02e18c
commit 91344a2
Showing
6 changed files
with
255 additions
and
20 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
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
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
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,217 @@ | ||
package nl.eduid.ui | ||
|
||
import androidx.compose.animation.animateContentSize | ||
import androidx.compose.foundation.BorderStroke | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.sizeIn | ||
import androidx.compose.foundation.shape.CornerSize | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.ButtonDefaults | ||
import androidx.compose.material3.Divider | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import androidx.constraintlayout.compose.ConstraintLayout | ||
import androidx.constraintlayout.compose.Dimension | ||
import nl.eduid.R | ||
import nl.eduid.screens.personalinfo.PersonalInfo | ||
import nl.eduid.ui.theme.BlueButton | ||
import nl.eduid.ui.theme.BlueText | ||
import nl.eduid.ui.theme.ButtonRed | ||
import nl.eduid.ui.theme.EduidAppAndroidTheme | ||
import nl.eduid.ui.theme.TextBlack | ||
import nl.eduid.ui.theme.TextGrayScale | ||
import java.util.Locale | ||
|
||
@Composable | ||
fun ConnectionCard( | ||
title: String, | ||
subtitle: String, | ||
institutionInfo: PersonalInfo.InstitutionAccount? = null, | ||
isExpanded: Boolean = false, | ||
onRemoveConnection: (id: String) -> Unit = { }, | ||
) { | ||
val isOpen = remember { mutableStateOf(isExpanded) } | ||
Spacer(Modifier.height(6.dp)) | ||
Box(modifier = Modifier | ||
.clip(RoundedCornerShape(6.dp)) | ||
.border( | ||
width = 3.dp, color = BlueButton | ||
) | ||
.sizeIn(minHeight = 72.dp) | ||
.fillMaxWidth() | ||
.clickable { | ||
if (institutionInfo != null) { | ||
isOpen.value = !isOpen.value | ||
} | ||
} | ||
.animateContentSize()) { | ||
ConstraintLayout( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(start = 18.dp, end = 18.dp, top = 12.dp, bottom = 12.dp) | ||
) { | ||
val (titleArea, endImage, expandedArea) = createRefs() | ||
|
||
Column(horizontalAlignment = Alignment.Start, | ||
modifier = Modifier.constrainAs(titleArea) { | ||
top.linkTo(parent.top) | ||
start.linkTo(parent.start) | ||
end.linkTo(endImage.start) | ||
width = Dimension.fillToConstraints | ||
}) { | ||
Text( | ||
text = title.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }, | ||
style = MaterialTheme.typography.bodyLarge.copy( | ||
textAlign = TextAlign.Start, | ||
fontWeight = FontWeight.Bold, | ||
lineHeight = 20.sp | ||
), | ||
) | ||
Spacer(Modifier.height(4.dp)) | ||
Text( | ||
text = subtitle, | ||
style = MaterialTheme.typography.bodySmall.copy( | ||
textAlign = TextAlign.Start, | ||
color = TextGrayScale, | ||
), | ||
) | ||
} | ||
if (isOpen.value && institutionInfo != null) { | ||
Column(horizontalAlignment = Alignment.Start, | ||
modifier = Modifier.constrainAs(expandedArea) { | ||
top.linkTo(titleArea.bottom, margin = 24.dp) | ||
start.linkTo(parent.start) | ||
end.linkTo(parent.end) | ||
}) { | ||
InstitutionInfoBlock(institutionInfo, onRemoveConnection) | ||
} | ||
} | ||
Image(painter = painterResource(R.drawable.chevron_down), | ||
contentDescription = "", | ||
modifier = Modifier | ||
.constrainAs(endImage) { | ||
top.linkTo(titleArea.top) | ||
bottom.linkTo(titleArea.bottom) | ||
end.linkTo(parent.end) | ||
} | ||
.padding(start = 12.dp)) | ||
} | ||
} | ||
Spacer(Modifier.height(16.dp)) | ||
} | ||
|
||
@Composable | ||
private fun InstitutionInfoBlock( | ||
institutionInfo: PersonalInfo.InstitutionAccount, | ||
onDeleteButtonClicked: (id: String) -> Unit, | ||
) = Column( | ||
Modifier.fillMaxWidth() | ||
) { | ||
InfoRow( | ||
label = stringResource( | ||
R.string.personalinfo_verified_by_on, | ||
institutionInfo.institution, | ||
institutionInfo.createdStamp.getDateString() | ||
) | ||
) | ||
InfoRow( | ||
label = stringResource(R.string.personalinfo_institution), | ||
value = institutionInfo.institution | ||
) | ||
InfoRow( | ||
label = stringResource(R.string.personalinfo_affiliations), | ||
value = institutionInfo.affiliationString | ||
) | ||
InfoRow( | ||
label = stringResource(R.string.personalinfo_expires), | ||
value = institutionInfo.expiryStamp.getDateString() | ||
) | ||
Button( | ||
shape = RoundedCornerShape(CornerSize(6.dp)), | ||
onClick = { onDeleteButtonClicked(institutionInfo.id) }, | ||
border = BorderStroke(1.dp, Color.Red), | ||
colors = ButtonDefaults.outlinedButtonColors(contentColor = ButtonRed), | ||
modifier = Modifier | ||
.sizeIn(minHeight = 48.dp) | ||
.fillMaxWidth(), | ||
) { | ||
Text( | ||
text = stringResource(R.string.infotab_remove_connection), | ||
style = MaterialTheme.typography.bodyLarge.copy( | ||
color = ButtonRed, fontWeight = FontWeight.SemiBold | ||
) | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun InfoRow(label: String, value: String = "") { | ||
Row( | ||
modifier = Modifier.fillMaxWidth() | ||
) { | ||
Text( | ||
modifier = Modifier.weight(1f), | ||
text = label, | ||
style = MaterialTheme.typography.bodyMedium.copy( | ||
textAlign = TextAlign.Start, | ||
color = BlueText, | ||
), | ||
) | ||
if (value.isNotEmpty()) { | ||
Text( | ||
modifier = Modifier.weight(1f), | ||
text = value, | ||
style = MaterialTheme.typography.bodyMedium.copy( | ||
textAlign = TextAlign.Start, | ||
color = BlueText, | ||
), | ||
) | ||
} | ||
} | ||
Spacer(Modifier.height(12.dp)) | ||
Divider(color = TextBlack, thickness = 1.dp) | ||
Spacer(Modifier.height(12.dp)) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun PreviewConnectionCard() = EduidAppAndroidTheme { | ||
ConnectionCard( | ||
title = "Librarian", | ||
subtitle = "Urangutan", | ||
institutionInfo = PersonalInfo.InstitutionAccount( | ||
id = "id", | ||
role = "Librarian", | ||
roleProvider = "Library", | ||
institution = "Unseen University", | ||
affiliationString = "Librarian", | ||
createdStamp = 0L, | ||
expiryStamp = 0L | ||
), | ||
isExpanded = true | ||
) | ||
} |
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
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