Skip to content

Commit

Permalink
Merge pull request #695 from radixdlt/bugfix/new-line-data
Browse files Browse the repository at this point in the history
Display data in new line when needed
  • Loading branch information
micbakos-rdx authored Dec 11, 2023
2 parents 0ccd09b + ccafad3 commit 3f91b13
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ fun AssetMetadataRow(

@Composable
fun Metadata.View(modifier: Modifier) {
if (this is Metadata.Primitive && this.valueType == MetadataType.Url) {
if (isRenderedInNewLine) {
Column(
modifier = modifier,
verticalArrangement = Arrangement.spacedBy(RadixTheme.dimensions.paddingSmall)
) {
KeyView()
ValueView()
ValueView(isRenderedInNewLine = true)
}
} else {
Row(
modifier = modifier,
horizontalArrangement = Arrangement.SpaceBetween
) {
KeyView()
ValueView()
ValueView(isRenderedInNewLine = false)
}
}
}
Expand All @@ -88,7 +88,8 @@ fun Metadata.KeyView(

@Composable
fun Metadata.ValueView(
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
isRenderedInNewLine: Boolean
) {
val context = LocalContext.current
when (this) {
Expand All @@ -97,7 +98,7 @@ fun Metadata.ValueView(
text = stringResource(id = R.string.assetDetails_NFTDetails_complexData),
style = RadixTheme.typography.body1HighImportance,
color = RadixTheme.colors.gray1,
textAlign = TextAlign.End,
textAlign = if (isRenderedInNewLine) TextAlign.Start else TextAlign.End,
maxLines = 2
)

Expand All @@ -116,21 +117,22 @@ fun Metadata.ValueView(
text = value,
style = RadixTheme.typography.body1HighImportance,
color = RadixTheme.colors.gray1,
textAlign = TextAlign.End,
textAlign = if (isRenderedInNewLine) TextAlign.Start else TextAlign.End,
maxLines = 2
)

MetadataType.String -> ExpandableText(
modifier = modifier,
text = value,
style = RadixTheme.typography.body1HighImportance.copy(
color = RadixTheme.colors.gray1,
textAlign = TextAlign.End
textAlign = if (isRenderedInNewLine) TextAlign.Start else TextAlign.End,
),
toggleStyle = RadixTheme.typography.body1HighImportance.copy(
color = RadixTheme.colors.gray2,
textAlign = TextAlign.End
color = RadixTheme.colors.gray2
),
)

MetadataType.Address, MetadataType.NonFungibleGlobalId, MetadataType.NonFungibleLocalId ->
ActionableAddressView(
modifier = modifier,
Expand All @@ -144,7 +146,7 @@ fun Metadata.ValueView(
text = value.toBigDecimalOrNull()?.displayableQuantity() ?: value,
style = RadixTheme.typography.body1HighImportance,
color = RadixTheme.colors.gray1,
textAlign = TextAlign.End,
textAlign = if (isRenderedInNewLine) TextAlign.Start else TextAlign.End,
maxLines = 2
)

Expand All @@ -153,7 +155,7 @@ fun Metadata.ValueView(
modifier = modifier
.fillMaxWidth()
.clickable { context.openUrl(value) },
horizontalArrangement = Arrangement.SpaceBetween,
horizontalArrangement = Arrangement.spacedBy(RadixTheme.dimensions.paddingDefault),
verticalAlignment = Alignment.CenterVertically
) {
Text(
Expand All @@ -170,3 +172,10 @@ fun Metadata.ValueView(
}
}
}

private const val ASSET_METADATA_SHORT_STRING_THRESHOLD = 40
private val Metadata.isRenderedInNewLine: Boolean
get() = this is Metadata.Primitive && (
valueType is MetadataType.Url ||
(valueType is MetadataType.String && value.length > ASSET_METADATA_SHORT_STRING_THRESHOLD)
)
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ private fun NonFungibleAssetDialogContent(
) {
BottomSheetDialogWrapper(
modifier = modifier,
onDismiss = onDismiss
onDismiss = onDismiss,
title = if (state.item != null && state.localId != null) {
state.item.name
} else if (state.localId == null && state.resource != null) {
state.resource.name
} else {
""
}
) {
Box(modifier = Modifier.fillMaxHeight(fraction = 0.9f)) {
Column(
Expand All @@ -91,6 +98,7 @@ private fun NonFungibleAssetDialogContent(
nft = state.item,
cropped = false
)
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingLarge))
} else if (state.item == null) {
Box(
modifier = Modifier
Expand All @@ -102,8 +110,27 @@ private fun NonFungibleAssetDialogContent(
shape = RoundedCornerShape(NFTCornerRadius)
)
)
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingLarge))
}

if (!state.item?.description.isNullOrBlank()) {
Text(
modifier = Modifier
.padding(horizontal = RadixTheme.dimensions.paddingXLarge)
.fillMaxWidth(),
text = state.item?.description.orEmpty(),
style = RadixTheme.typography.body2Regular,
color = RadixTheme.colors.gray1
)
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingLarge))
HorizontalDivider(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = RadixTheme.dimensions.paddingLarge),
color = RadixTheme.colors.gray4
)
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingLarge))
}
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingLarge))

AssetMetadataRow(
modifier = Modifier
Expand All @@ -128,64 +155,32 @@ private fun NonFungibleAssetDialogContent(
)
}
}
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingDefault))
if (state.item != null) {
state.item.name?.let { name ->
AssetMetadataRow(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = RadixTheme.dimensions.paddingXLarge),
key = stringResource(id = R.string.assetDetails_name)
) {
Text(
text = name,
style = RadixTheme.typography.body1HighImportance,
color = RadixTheme.colors.gray1
)
}
}
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingLarge))

state.item.description?.let { description ->
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingDefault))
AssetMetadataRow(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = RadixTheme.dimensions.paddingXLarge),
key = stringResource(id = R.string.assetDetails_NFTDetails_description)
) {
Text(
text = description,
style = RadixTheme.typography.body1HighImportance,
color = RadixTheme.colors.gray1
)
}
}
if (!state.item?.nonStandardMetadata.isNullOrEmpty()) {
HorizontalDivider(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = RadixTheme.dimensions.paddingLarge),
color = RadixTheme.colors.gray4
)

state.item.nonStandardMetadata.forEach { metadata ->
state.item?.nonStandardMetadata?.forEach { metadata ->
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingDefault))
metadata.View(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = RadixTheme.dimensions.paddingXLarge)
)
}
} else {
Box(
modifier = Modifier
.fillMaxWidth()
.height(16.dp)
.padding(horizontal = RadixTheme.dimensions.paddingXLarge)
.radixPlaceholder(visible = true)
)

Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingLarge))
}
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingDefault))
}

if (state.localId != null) {
HorizontalDivider(
Modifier
.fillMaxWidth()
.padding(top = RadixTheme.dimensions.paddingDefault),
modifier = Modifier.fillMaxWidth(),
color = RadixTheme.colors.gray4
)
}
Expand Down Expand Up @@ -240,7 +235,7 @@ private fun NonFungibleAssetDialogContent(
.padding(horizontal = RadixTheme.dimensions.paddingXLarge),
address = state.resourceAddress
)
if (!state.resource?.name.isNullOrBlank()) {
if (!state.resource?.name.isNullOrBlank() && state.localId != null) {
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingDefault))
AssetMetadataRow(
modifier = Modifier
Expand Down

0 comments on commit 3f91b13

Please sign in to comment.