Skip to content

Commit

Permalink
Quick: swap inpunt/output btn
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrlzy committed Dec 21, 2024
1 parent d370d54 commit b73d7e9
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ object CurrUtils {
"#." + "#".repeat(fractionSize),
DecimalFormatSymbols(Locale.ENGLISH),
)
df.roundingMode = RoundingMode.CEILING
return df.format(number)
}

Expand Down
12 changes: 12 additions & 0 deletions core/presentation/src/main/res/drawable/ic_refresh.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="17dp"
android:height="20dp"
android:viewportWidth="17"
android:viewportHeight="20">
<path
android:pathData="M2.608,15.893C-0.647,12.638 -0.647,7.362 2.608,4.108C3.273,3.443 3.83,2.917 4.295,2.5L1.834,2.5C1.373,2.5 1,2.127 1,1.667C1,1.207 1.373,0.833 1.834,0.833L6.834,0.833C7.294,0.833 7.667,1.207 7.667,1.667V6.667C7.667,7.127 7.294,7.5 6.834,7.5C6.373,7.5 6,7.127 6,6.667L6,3.229C5.486,3.656 4.768,4.304 3.786,5.286C1.183,7.89 1.183,12.111 3.786,14.714C4.71,15.638 5.834,16.232 7.018,16.501C7.467,16.603 7.748,17.049 7.646,17.498C7.544,17.947 7.098,18.228 6.649,18.126C5.168,17.79 3.76,17.045 2.608,15.893Z"
android:fillColor="#000000"/>
<path
android:pathData="M9.983,3.499C9.534,3.398 9.252,2.951 9.354,2.502C9.456,2.053 9.903,1.772 10.351,1.874C11.833,2.21 13.241,2.955 14.393,4.108C17.647,7.362 17.647,12.638 14.393,15.893C13.728,16.558 13.171,17.084 12.706,17.5H15.167C15.627,17.5 16,17.873 16,18.333C16,18.794 15.627,19.167 15.167,19.167H10.167C9.707,19.167 9.334,18.794 9.334,18.333V13.333C9.334,12.873 9.707,12.5 10.167,12.5C10.627,12.5 11,12.873 11,13.333V16.772C11.514,16.345 12.232,15.697 13.214,14.714C15.818,12.111 15.818,7.89 13.214,5.286C12.291,4.363 11.167,3.768 9.983,3.499Z"
android:fillColor="#000000"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
Expand All @@ -25,6 +26,7 @@ import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -60,7 +62,7 @@ import dev.arkbuilders.rate.core.presentation.AppSharedFlowKey
import dev.arkbuilders.rate.core.presentation.R
import dev.arkbuilders.rate.core.presentation.theme.ArkColor
import dev.arkbuilders.rate.core.presentation.ui.AppButton
import dev.arkbuilders.rate.core.presentation.ui.AppHorDiv16
import dev.arkbuilders.rate.core.presentation.ui.AppHorDiv
import dev.arkbuilders.rate.core.presentation.ui.AppTopBarBack
import dev.arkbuilders.rate.core.presentation.ui.ArkBasicTextField
import dev.arkbuilders.rate.core.presentation.ui.DropDownWithIcon
Expand Down Expand Up @@ -150,6 +152,7 @@ fun AddQuickScreen(
),
)
},
onSwapClick = viewModel::onSwapClick,
onAddAsset = viewModel::onAddQuickPair,
)
}
Expand All @@ -165,6 +168,7 @@ private fun Content(
onCurrencyRemove: (Int) -> Unit = {},
onGroupSelect: (String) -> Unit = {},
onCodeChange: (Int) -> Unit = {},
onSwapClick: () -> Unit = {},
onAddAsset: () -> Unit = {},
) {
var showNewGroupDialog by remember { mutableStateOf(false) }
Expand All @@ -184,7 +188,7 @@ private fun Content(
.weight(1f)
.verticalScroll(rememberScrollState()),
) {
Currencies(state, onAmountChanged, onCurrencyRemove, onCodeChange)
Currencies(state, onAmountChanged, onCurrencyRemove, onCodeChange, onSwapClick)
Button(
modifier = Modifier.padding(start = 16.dp, top = 16.dp),
shape = RoundedCornerShape(8.dp),
Expand Down Expand Up @@ -277,6 +281,7 @@ private fun Currencies(
onAmountChanged: (String) -> Unit,
onCurrencyRemove: (Int) -> Unit,
onCodeChange: (Int) -> Unit,
onSwapClick: () -> Unit,
) {
val from = state.currencies.first()
Text(
Expand All @@ -292,7 +297,7 @@ private fun Currencies(
onAmountChanged = onAmountChanged,
onCodeChange = onCodeChange,
)
AppHorDiv16(modifier = Modifier.padding(top = 16.dp))
SwapBtn(modifier = Modifier.padding(top = 16.dp), onClick = onSwapClick)
Text(
modifier = Modifier.padding(top = 16.dp, start = 16.dp),
text = "To",
Expand Down Expand Up @@ -468,3 +473,24 @@ private fun ToResult(
}
}
}

@Composable
private fun SwapBtn(
modifier: Modifier = Modifier,
onClick: () -> Unit,
) {
Row(modifier = modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
AppHorDiv(modifier = Modifier.weight(1f).padding(start = 16.dp, end = 12.dp))
OutlinedButton(
modifier = Modifier.size(40.dp),
shape = CircleShape,
border = BorderStroke(1.dp, ArkColor.BorderSecondary),
contentPadding = PaddingValues(0.dp),
onClick = onClick,
colors = ButtonDefaults.outlinedButtonColors(contentColor = Color.Black),
) {
Icon(painter = painterResource(R.drawable.ic_refresh), contentDescription = null)
}
AppHorDiv(modifier = Modifier.weight(1f).padding(start = 12.dp, end = 16.dp))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,32 @@ class AddQuickViewModel(
checkFinishEnabled()
}

fun onSwapClick() =
intent {
if (state.currencies.size < 2)
return@intent

val newFrom =
state.currencies.last().let { amount ->
if (amount.value.isEmpty())
return@let amount

val withoutCommas = amount.value.replace(",", "")
amount.copy(value = CurrUtils.roundOff(withoutCommas.toBigDecimalArk()))
}
val newList =
state.currencies.toMutableList().apply {
removeLast()
add(0, newFrom)
}

val calc = calcToResult(newList)

reduce {
state.copy(currencies = calc)
}
}

fun onAddQuickPair() =
intent {
val from = state.currencies.first()
Expand Down

0 comments on commit b73d7e9

Please sign in to comment.