From 9ae623473aba19e9844514cf0c43cfd5a215dff4 Mon Sep 17 00:00:00 2001 From: mdrlzy Date: Sun, 27 Oct 2024 20:40:55 +0600 Subject: [PATCH] Fix text overflow --- .../pairalert/AddPairAlertScreen.kt | 64 ++++----- .../pairalert/PairAlertConditionScreen.kt | 3 + .../presentation/portfolio/AddAssetScreen.kt | 18 ++- .../presentation/portfolio/EditAssetScreen.kt | 36 +++-- .../presentation/portfolio/PortfolioScreen.kt | 74 +++++++--- .../rate/presentation/quick/AddQuickScreen.kt | 24 +++- .../rate/presentation/quick/QuickScreen.kt | 7 +- ...eldPlaceholder.kt => ArkBasicTextField.kt} | 26 ++-- .../rate/presentation/ui/LargeNumberText.kt | 127 ++++++++++++++++++ .../presentation/ui/LargeNumberTooltipBox.kt | 32 +++++ .../rate/presentation/ui/Search.kt | 18 ++- 11 files changed, 338 insertions(+), 91 deletions(-) rename app/src/main/java/dev/arkbuilders/rate/presentation/ui/{BasicTextFieldPlaceholder.kt => ArkBasicTextField.kt} (79%) create mode 100644 app/src/main/java/dev/arkbuilders/rate/presentation/ui/LargeNumberText.kt create mode 100644 app/src/main/java/dev/arkbuilders/rate/presentation/ui/LargeNumberTooltipBox.kt diff --git a/app/src/main/java/dev/arkbuilders/rate/presentation/pairalert/AddPairAlertScreen.kt b/app/src/main/java/dev/arkbuilders/rate/presentation/pairalert/AddPairAlertScreen.kt index e469ae74d..e255953df 100644 --- a/app/src/main/java/dev/arkbuilders/rate/presentation/pairalert/AddPairAlertScreen.kt +++ b/app/src/main/java/dev/arkbuilders/rate/presentation/pairalert/AddPairAlertScreen.kt @@ -18,7 +18,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.foundation.text.BasicTextField import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Card @@ -62,6 +61,7 @@ import dev.arkbuilders.rate.presentation.shared.AppSharedFlowKey import dev.arkbuilders.rate.presentation.theme.ArkColor import dev.arkbuilders.rate.presentation.ui.AppButton import dev.arkbuilders.rate.presentation.ui.AppTopBarBack +import dev.arkbuilders.rate.presentation.ui.ArkBasicTextField import dev.arkbuilders.rate.presentation.ui.GroupCreateDialog import dev.arkbuilders.rate.presentation.ui.GroupSelectPopup import dev.arkbuilders.rate.presentation.ui.NotifyAddedSnackbarVisuals @@ -392,7 +392,7 @@ private fun EditCondition( ) { val ctx = LocalContext.current Column( - modifier = Modifier.padding(top = 48.dp), + modifier = Modifier.padding(top = 48.dp, start = 16.dp, end = 16.dp), horizontalAlignment = Alignment.CenterHorizontally, ) { Row( @@ -469,16 +469,7 @@ private fun EditCondition( .padding(top = 24.dp), horizontalArrangement = Arrangement.Center, ) { - if (!state.oneTimeNotRecurrent) { - Text( - modifier = Modifier.align(Alignment.CenterVertically), - text = stringResource(R.string.every), - fontSize = 20.sp, - fontWeight = FontWeight.Medium, - color = ArkColor.TextPrimary, - ) - } - BasicTextField( + ArkBasicTextField( modifier = Modifier .width(IntrinsicSize.Min) @@ -499,25 +490,38 @@ private fun EditCondition( keyboardOptions = KeyboardOptions.Default .copy(keyboardType = KeyboardType.Number), + prefix = { + if (!state.oneTimeNotRecurrent) { + Text( + modifier = Modifier.align(Alignment.CenterVertically), + text = stringResource(R.string.every), + fontSize = 20.sp, + fontWeight = FontWeight.Medium, + color = ArkColor.TextPrimary, + ) + } + }, + suffix = { + if (state.priceOrPercent.isLeft()) { + Text( + modifier = Modifier.align(Alignment.Top), + text = CurrUtils.getSymbolOrCode(state.baseCode), + fontSize = 20.sp, + fontWeight = FontWeight.Medium, + color = ArkColor.TextPrimary, + ) + } + if (state.priceOrPercent.isRight()) { + Text( + modifier = Modifier.align(Alignment.Top), + text = "%", + fontSize = 36.sp, + fontWeight = FontWeight.SemiBold, + color = ArkColor.TextPrimary, + ) + } + }, ) - if (state.priceOrPercent.isLeft()) { - Text( - modifier = Modifier.align(Alignment.Top), - text = CurrUtils.getSymbolOrCode(state.baseCode), - fontSize = 20.sp, - fontWeight = FontWeight.Medium, - color = ArkColor.TextPrimary, - ) - } - if (state.priceOrPercent.isRight()) { - Text( - modifier = Modifier.align(Alignment.Top), - text = "%", - fontSize = 36.sp, - fontWeight = FontWeight.SemiBold, - color = ArkColor.TextPrimary, - ) - } } Row( modifier = Modifier.padding(top = 24.dp), diff --git a/app/src/main/java/dev/arkbuilders/rate/presentation/pairalert/PairAlertConditionScreen.kt b/app/src/main/java/dev/arkbuilders/rate/presentation/pairalert/PairAlertConditionScreen.kt index 950386340..e5c97151f 100644 --- a/app/src/main/java/dev/arkbuilders/rate/presentation/pairalert/PairAlertConditionScreen.kt +++ b/app/src/main/java/dev/arkbuilders/rate/presentation/pairalert/PairAlertConditionScreen.kt @@ -13,10 +13,12 @@ import androidx.compose.foundation.layout.Arrangement 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.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.CircleShape @@ -347,6 +349,7 @@ private fun PairAlertItem( } } } + Spacer(Modifier.width(8.dp)) Switch( checked = pairAlert.enabled, onCheckedChange = { onEnableToggle(pairAlert, it) }, diff --git a/app/src/main/java/dev/arkbuilders/rate/presentation/portfolio/AddAssetScreen.kt b/app/src/main/java/dev/arkbuilders/rate/presentation/portfolio/AddAssetScreen.kt index 9e9de0774..deb72feda 100644 --- a/app/src/main/java/dev/arkbuilders/rate/presentation/portfolio/AddAssetScreen.kt +++ b/app/src/main/java/dev/arkbuilders/rate/presentation/portfolio/AddAssetScreen.kt @@ -36,6 +36,7 @@ import androidx.compose.ui.layout.onPlaced import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.tooling.preview.Preview @@ -59,7 +60,7 @@ import dev.arkbuilders.rate.presentation.shared.AppSharedFlowKey import dev.arkbuilders.rate.presentation.theme.ArkColor import dev.arkbuilders.rate.presentation.ui.AppButton import dev.arkbuilders.rate.presentation.ui.AppTopBarBack -import dev.arkbuilders.rate.presentation.ui.BasicTextFieldPlaceholder +import dev.arkbuilders.rate.presentation.ui.ArkBasicTextField import dev.arkbuilders.rate.presentation.ui.GroupCreateDialog import dev.arkbuilders.rate.presentation.ui.GroupSelectPopup import dev.arkbuilders.rate.presentation.ui.NotifyAddedSnackbarVisuals @@ -309,14 +310,25 @@ fun InputCurrency( tint = ArkColor.FGQuinary, ) } - BasicTextFieldPlaceholder( + ArkBasicTextField( modifier = Modifier.padding(start = 12.dp), value = amount.value, onValueChange = { onAssetValueChanged(pos, it) }, - placeholder = stringResource(R.string.input_value), + textStyle = + TextStyle.Default.copy( + color = ArkColor.TextPrimary, + fontSize = 16.sp, + ), keyboardOptions = KeyboardOptions.Default .copy(keyboardType = KeyboardType.Number), + placeholder = { + Text( + text = stringResource(R.string.input_value), + color = ArkColor.TextPlaceHolder, + fontSize = 16.sp, + ) + }, ) } diff --git a/app/src/main/java/dev/arkbuilders/rate/presentation/portfolio/EditAssetScreen.kt b/app/src/main/java/dev/arkbuilders/rate/presentation/portfolio/EditAssetScreen.kt index b3089d3bc..d16b21394 100644 --- a/app/src/main/java/dev/arkbuilders/rate/presentation/portfolio/EditAssetScreen.kt +++ b/app/src/main/java/dev/arkbuilders/rate/presentation/portfolio/EditAssetScreen.kt @@ -1,3 +1,5 @@ +@file:OptIn(ExperimentalMaterial3Api::class) + package dev.arkbuilders.rate.presentation.portfolio import androidx.compose.foundation.layout.Box @@ -10,10 +12,10 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.text.BasicTextField import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.verticalScroll import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.LocalTextStyle @@ -47,6 +49,7 @@ import dev.arkbuilders.rate.presentation.shared.AppSharedFlowKey import dev.arkbuilders.rate.presentation.theme.ArkColor import dev.arkbuilders.rate.presentation.ui.AppHorDiv import dev.arkbuilders.rate.presentation.ui.AppTopBarBack +import dev.arkbuilders.rate.presentation.ui.ArkBasicTextField import dev.arkbuilders.rate.presentation.ui.InfoMarketCapitalizationDialog import dev.arkbuilders.rate.presentation.ui.InfoValueOfCirculatingDialog import dev.arkbuilders.rate.presentation.ui.LoadingScreen @@ -112,9 +115,15 @@ private fun Content( .padding(horizontal = 16.dp) .verticalScroll(rememberScrollState()), ) { + val title = + if (name.name.isNotEmpty()) { + "${name.name} (${name.code})" + } else { + name.code + } Text( modifier = Modifier.padding(top = 32.dp), - text = "${name.name} (${name.code})", + text = title, color = ArkColor.TextPrimary, fontWeight = FontWeight.SemiBold, fontSize = 24.sp, @@ -124,7 +133,7 @@ private fun Content( Modifier.padding(top = 32.dp), verticalAlignment = Alignment.Top, ) { - BasicTextField( + ArkBasicTextField( modifier = Modifier .width(IntrinsicSize.Min) @@ -140,16 +149,17 @@ private fun Content( keyboardOptions = KeyboardOptions.Default .copy(keyboardType = KeyboardType.Number), - ) - Text( - modifier = - Modifier - .padding(start = 2.dp, top = 2.dp) - .align(Alignment.Top), - text = CurrUtils.getSymbolOrCode(name.code), - fontSize = 20.sp, - fontWeight = FontWeight.Medium, - color = ArkColor.TextPrimary, + suffix = { + Text( + modifier = + Modifier + .padding(start = 2.dp, top = 2.dp), + text = CurrUtils.getSymbolOrCode(name.code), + fontSize = 20.sp, + fontWeight = FontWeight.Medium, + color = ArkColor.TextPrimary, + ) + }, ) } TextButton( diff --git a/app/src/main/java/dev/arkbuilders/rate/presentation/portfolio/PortfolioScreen.kt b/app/src/main/java/dev/arkbuilders/rate/presentation/portfolio/PortfolioScreen.kt index ee1787886..9570a571f 100644 --- a/app/src/main/java/dev/arkbuilders/rate/presentation/portfolio/PortfolioScreen.kt +++ b/app/src/main/java/dev/arkbuilders/rate/presentation/portfolio/PortfolioScreen.kt @@ -1,4 +1,4 @@ -@file:OptIn(ExperimentalFoundationApi::class) +@file:OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class) package dev.arkbuilders.rate.presentation.portfolio @@ -18,6 +18,7 @@ import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.Icon import androidx.compose.material3.Scaffold @@ -54,6 +55,8 @@ import dev.arkbuilders.rate.presentation.ui.AppHorDiv16 import dev.arkbuilders.rate.presentation.ui.AppSwipeToDismiss import dev.arkbuilders.rate.presentation.ui.CurrIcon import dev.arkbuilders.rate.presentation.ui.GroupViewPager +import dev.arkbuilders.rate.presentation.ui.LargeNumberText +import dev.arkbuilders.rate.presentation.ui.LargeNumberTooltipBox import dev.arkbuilders.rate.presentation.ui.LoadingScreen import dev.arkbuilders.rate.presentation.ui.NoInternetScreen import dev.arkbuilders.rate.presentation.ui.NoResult @@ -239,16 +242,27 @@ private fun GroupPage( color = ArkColor.TextTertiary, fontWeight = FontWeight.Medium, ) - Row(modifier = Modifier.padding(top = 8.dp)) { + Row( + modifier = + Modifier + .padding(top = 8.dp, start = 24.dp, end = 24.dp), + ) { + LargeNumberTooltipBox(number = total, code = baseCode) { + LargeNumberText( + number = total, + color = ArkColor.TextPrimary, + fontWeight = FontWeight.SemiBold, + fontSize = 36.sp, + ) + } Text( - modifier = Modifier, - text = CurrUtils.prepareToDisplay(total), - color = ArkColor.TextPrimary, - fontWeight = FontWeight.SemiBold, - fontSize = 36.sp, - ) - Text( - modifier = Modifier.padding(start = 2.dp, top = 2.dp), + modifier = + Modifier + .padding( + start = 2.dp, + top = 2.dp, + ) + .weight(1f, fill = false), text = CurrUtils.getSymbolOrCode(baseCode), color = ArkColor.TextPrimary, fontWeight = FontWeight.SemiBold, @@ -298,30 +312,48 @@ private fun CurrencyItem( horizontalArrangement = Arrangement.SpaceBetween, ) { Text( + modifier = Modifier.padding(end = 8.dp), text = amount.asset.code, fontWeight = FontWeight.Medium, color = ArkColor.TextPrimary, ) - Text( - text = "${CurrUtils.prepareToDisplay( - amount.baseAmount.value, - )} ${amount.baseAmount.code}", - fontWeight = FontWeight.Medium, - color = ArkColor.TextPrimary, - ) + LargeNumberTooltipBox( + modifier = Modifier.weight(1f), + number = amount.baseAmount.value, + code = amount.baseAmount.code, + ) { + LargeNumberText( + number = amount.baseAmount.value, + code = amount.baseAmount.code, + fontWeight = FontWeight.Medium, + color = ArkColor.TextPrimary, + fontSize = 14.sp, + textAlign = TextAlign.End, + ) + } } Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, ) { Text( + modifier = Modifier.padding(end = 8.dp), text = CurrUtils.prepareToDisplay(amount.ratioToBase), color = ArkColor.TextTertiary, ) - Text( - text = "${CurrUtils.prepareToDisplay(amount.asset.value)} ${amount.asset.code}", - color = ArkColor.TextTertiary, - ) + LargeNumberTooltipBox( + modifier = Modifier.weight(1f), + number = amount.asset.value, + code = amount.asset.code, + ) { + LargeNumberText( + number = amount.asset.value, + code = amount.asset.code, + color = ArkColor.TextTertiary, + fontSize = 14.sp, + textAlign = TextAlign.End, + ) + } } } } diff --git a/app/src/main/java/dev/arkbuilders/rate/presentation/quick/AddQuickScreen.kt b/app/src/main/java/dev/arkbuilders/rate/presentation/quick/AddQuickScreen.kt index 7d72097c4..b7aba5e50 100644 --- a/app/src/main/java/dev/arkbuilders/rate/presentation/quick/AddQuickScreen.kt +++ b/app/src/main/java/dev/arkbuilders/rate/presentation/quick/AddQuickScreen.kt @@ -5,6 +5,7 @@ package dev.arkbuilders.rate.presentation.quick import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.border import androidx.compose.foundation.clickable +import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues @@ -39,6 +40,7 @@ import androidx.compose.ui.layout.onPlaced import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.tooling.preview.Preview @@ -64,7 +66,7 @@ import dev.arkbuilders.rate.presentation.theme.ArkColor import dev.arkbuilders.rate.presentation.ui.AppButton import dev.arkbuilders.rate.presentation.ui.AppHorDiv16 import dev.arkbuilders.rate.presentation.ui.AppTopBarBack -import dev.arkbuilders.rate.presentation.ui.BasicTextFieldPlaceholder +import dev.arkbuilders.rate.presentation.ui.ArkBasicTextField import dev.arkbuilders.rate.presentation.ui.GroupCreateDialog import dev.arkbuilders.rate.presentation.ui.GroupSelectPopup import dev.arkbuilders.rate.presentation.ui.NotifyAddedSnackbarVisuals @@ -355,14 +357,25 @@ private fun FromInput( tint = ArkColor.FGQuinary, ) } - BasicTextFieldPlaceholder( + ArkBasicTextField( modifier = Modifier.padding(start = 12.dp), value = amount, onValueChange = { onAmountChanged(it) }, - placeholder = stringResource(R.string.input_value), keyboardOptions = KeyboardOptions.Default .copy(keyboardType = KeyboardType.Number), + textStyle = + TextStyle.Default.copy( + color = ArkColor.TextPrimary, + fontSize = 16.sp, + ), + placeholder = { + Text( + text = stringResource(R.string.input_value), + color = ArkColor.TextPlaceHolder, + fontSize = 16.sp, + ) + }, ) } } @@ -420,7 +433,10 @@ private fun ToResult( ) } else { Text( - modifier = Modifier.padding(start = 12.dp), + modifier = + Modifier + .padding(start = 12.dp) + .horizontalScroll(rememberScrollState()), text = CurrUtils.prepareToDisplay(amount.toBigDecimalArk()), color = ArkColor.TextPrimary, fontSize = 16.sp, diff --git a/app/src/main/java/dev/arkbuilders/rate/presentation/quick/QuickScreen.kt b/app/src/main/java/dev/arkbuilders/rate/presentation/quick/QuickScreen.kt index b9b41204c..09ed436a2 100644 --- a/app/src/main/java/dev/arkbuilders/rate/presentation/quick/QuickScreen.kt +++ b/app/src/main/java/dev/arkbuilders/rate/presentation/quick/QuickScreen.kt @@ -455,9 +455,14 @@ private fun QuickItem( modifier = Modifier .constrainAs(content) { - linkTo(icons.end, chevron.start, bias = 0f) + start.linkTo(icons.end) + if (to.size > 1) + end.linkTo(chevron.start) + else + end.linkTo(parent.end, margin = 24.dp) top.linkTo(parent.top, margin = 16.dp) bottom.linkTo(parent.bottom, margin = 16.dp) + width = Dimension.fillToConstraints } .padding(start = if (expanded) 12.dp else 0.dp), verticalArrangement = Arrangement.Center, diff --git a/app/src/main/java/dev/arkbuilders/rate/presentation/ui/BasicTextFieldPlaceholder.kt b/app/src/main/java/dev/arkbuilders/rate/presentation/ui/ArkBasicTextField.kt similarity index 79% rename from app/src/main/java/dev/arkbuilders/rate/presentation/ui/BasicTextFieldPlaceholder.kt rename to app/src/main/java/dev/arkbuilders/rate/presentation/ui/ArkBasicTextField.kt index 6f0d99282..01f0306ea 100644 --- a/app/src/main/java/dev/arkbuilders/rate/presentation/ui/BasicTextFieldPlaceholder.kt +++ b/app/src/main/java/dev/arkbuilders/rate/presentation/ui/ArkBasicTextField.kt @@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.text.BasicTextField import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.Text import androidx.compose.material3.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.remember @@ -17,15 +16,16 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.input.VisualTransformation import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp -import dev.arkbuilders.rate.presentation.theme.ArkColor @Composable -fun BasicTextFieldPlaceholder( +fun ArkBasicTextField( modifier: Modifier = Modifier, value: String, onValueChange: (String) -> Unit, - placeholder: String, + textStyle: TextStyle = TextStyle.Default, + placeholder: (@Composable () -> Unit)? = null, + prefix: (@Composable () -> Unit)? = null, + suffix: (@Composable () -> Unit)? = null, leadingIcon: (@Composable () -> Unit)? = null, keyboardOptions: KeyboardOptions = KeyboardOptions.Default, ) { @@ -34,11 +34,7 @@ fun BasicTextFieldPlaceholder( modifier = modifier.fillMaxWidth(), value = value, onValueChange = { onValueChange(it) }, - textStyle = - TextStyle.Default.copy( - color = ArkColor.TextPrimary, - fontSize = 16.sp, - ), + textStyle = textStyle, keyboardOptions = keyboardOptions, interactionSource = interactionSource, singleLine = true, @@ -47,13 +43,6 @@ fun BasicTextFieldPlaceholder( value = value, innerTextField = innerTextField, leadingIcon = leadingIcon, - placeholder = { - Text( - text = placeholder, - color = ArkColor.TextPlaceHolder, - fontSize = 16.sp, - ) - }, contentPadding = PaddingValues(0.dp), colors = TextFieldDefaults.colors( @@ -66,6 +55,9 @@ fun BasicTextFieldPlaceholder( singleLine = true, visualTransformation = VisualTransformation.None, interactionSource = interactionSource, + placeholder = placeholder, + prefix = prefix, + suffix = suffix, ) } } diff --git a/app/src/main/java/dev/arkbuilders/rate/presentation/ui/LargeNumberText.kt b/app/src/main/java/dev/arkbuilders/rate/presentation/ui/LargeNumberText.kt new file mode 100644 index 000000000..ee1c888a1 --- /dev/null +++ b/app/src/main/java/dev/arkbuilders/rate/presentation/ui/LargeNumberText.kt @@ -0,0 +1,127 @@ +package dev.arkbuilders.rate.presentation.ui + +import androidx.compose.material3.LocalTextStyle +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.drawWithContent +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontStyle +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextDecoration +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.TextUnit +import dev.arkbuilders.rate.data.CurrUtils +import dev.arkbuilders.rate.data.divideArk +import java.math.BigDecimal + +@Composable +fun LargeNumberText( + modifier: Modifier = Modifier, + number: BigDecimal, + code: String? = null, + color: Color = Color.Unspecified, + fontSize: TextUnit = TextUnit.Unspecified, + fontStyle: FontStyle? = null, + fontWeight: FontWeight? = null, + fontFamily: FontFamily? = null, + letterSpacing: TextUnit = TextUnit.Unspecified, + textDecoration: TextDecoration? = null, + textAlign: TextAlign? = null, + lineHeight: TextUnit = TextUnit.Unspecified, + softWrap: Boolean = true, + style: TextStyle = LocalTextStyle.current, + overflow: TextOverflow = TextOverflow.Clip, +) { + var text by remember(key1 = number, key2 = code) { + val suffix = code?.let { " ${CurrUtils.getSymbolOrCode(code)}" } ?: "" + mutableStateOf("${CurrUtils.prepareToDisplay(number)}$suffix") + } + var textReadyToDraw by remember(key1 = number) { + mutableStateOf(false) + } + var currentScale by remember(key1 = number) { + mutableStateOf(Scale.ONE) + } + Text( + modifier = + modifier.drawWithContent { + if (textReadyToDraw) { + drawContent() + } + }, + text = text, + color = color, + textAlign = textAlign, + fontSize = fontSize, + fontFamily = fontFamily, + fontStyle = fontStyle, + fontWeight = fontWeight, + letterSpacing = letterSpacing, + textDecoration = textDecoration, + lineHeight = lineHeight, + style = style, + maxLines = 1, + minLines = 1, + softWrap = softWrap, + overflow = if (textReadyToDraw) overflow else TextOverflow.Clip, + onTextLayout = { result -> + if (result.hasVisualOverflow) { + if (currentScale == Scale.QUETTA) { + textReadyToDraw = true + } else { + currentScale = currentScale.next() + text = shortNumber(number, currentScale, code) + } + return@Text + } + textReadyToDraw = true + }, + ) +} + +private fun shortNumber( + number: BigDecimal, + scale: Scale, + code: String?, +): String { + val suffix = code?.let { " ${CurrUtils.getSymbolOrCode(code)}" } ?: "" + val rem = number.divideArk(scale.value) + return "${CurrUtils.prepareToDisplay(rem)}${scale.symbol}$suffix" +} + +private enum class Scale(val symbol: String, val value: BigDecimal) { + ONE("", BigDecimal(1)), + KILO("k", BigDecimal(10).pow(3)), + MEGA("M", BigDecimal(10).pow(6)), + GIGA("G", BigDecimal(10).pow(9)), + TERA("T", BigDecimal(10).pow(12)), + PETA("P", BigDecimal(10).pow(15)), + EXA("E", BigDecimal(10).pow(18)), + ZETTA("Z", BigDecimal(10).pow(21)), + YOTTA("Y", BigDecimal(10).pow(24)), + RONNA("R", BigDecimal(10).pow(27)), + QUETTA("Q", BigDecimal(10).pow(30)), +} + +private fun Scale.next() = + when (this) { + Scale.ONE -> Scale.KILO + Scale.KILO -> Scale.MEGA + Scale.MEGA -> Scale.GIGA + Scale.GIGA -> Scale.TERA + Scale.TERA -> Scale.PETA + Scale.PETA -> Scale.EXA + Scale.EXA -> Scale.ZETTA + Scale.ZETTA -> Scale.YOTTA + Scale.YOTTA -> Scale.RONNA + Scale.RONNA -> Scale.QUETTA + Scale.QUETTA -> error("QUETTA is last scale, use it") + } diff --git a/app/src/main/java/dev/arkbuilders/rate/presentation/ui/LargeNumberTooltipBox.kt b/app/src/main/java/dev/arkbuilders/rate/presentation/ui/LargeNumberTooltipBox.kt new file mode 100644 index 000000000..be63fc2de --- /dev/null +++ b/app/src/main/java/dev/arkbuilders/rate/presentation/ui/LargeNumberTooltipBox.kt @@ -0,0 +1,32 @@ +@file:OptIn(ExperimentalMaterial3Api::class) + +package dev.arkbuilders.rate.presentation.ui + +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.PlainTooltip +import androidx.compose.material3.Text +import androidx.compose.material3.TooltipBox +import androidx.compose.material3.TooltipDefaults +import androidx.compose.material3.rememberTooltipState +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import dev.arkbuilders.rate.data.CurrUtils +import java.math.BigDecimal + +@Composable +fun LargeNumberTooltipBox( + modifier: Modifier = Modifier, + number: BigDecimal, + code: String? = null, + content: @Composable () -> Unit, +) { + val suffix = code?.let { " ${CurrUtils.getSymbolOrCode(code)}" } ?: "" + TooltipBox( + modifier = modifier, + positionProvider = + TooltipDefaults.rememberPlainTooltipPositionProvider(), + tooltip = { PlainTooltip { Text("${CurrUtils.prepareToDisplay(number)}$suffix") } }, + state = rememberTooltipState(isPersistent = true), + content = content, + ) +} diff --git a/app/src/main/java/dev/arkbuilders/rate/presentation/ui/Search.kt b/app/src/main/java/dev/arkbuilders/rate/presentation/ui/Search.kt index 00666d422..f24467481 100644 --- a/app/src/main/java/dev/arkbuilders/rate/presentation/ui/Search.kt +++ b/app/src/main/java/dev/arkbuilders/rate/presentation/ui/Search.kt @@ -6,14 +6,17 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Icon +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.TextStyle import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import dev.arkbuilders.rate.R import dev.arkbuilders.rate.presentation.theme.ArkColor @@ -38,13 +41,17 @@ fun SearchTextField( .clip(RoundedCornerShape(8.dp)), verticalAlignment = Alignment.CenterVertically, ) { - BasicTextFieldPlaceholder( + ArkBasicTextField( modifier = Modifier .fillMaxWidth(), value = text, onValueChange = onValueChange, - placeholder = placeHolderText, + textStyle = + TextStyle.Default.copy( + color = ArkColor.TextPrimary, + fontSize = 16.sp, + ), leadingIcon = { Icon( painter = painterResource(id = R.drawable.ic_search), @@ -52,6 +59,13 @@ fun SearchTextField( tint = ArkColor.FGQuarterary, ) }, + placeholder = { + Text( + text = placeHolderText, + color = ArkColor.TextPlaceHolder, + fontSize = 16.sp, + ) + }, ) } }