Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/src/androidTest/java/to/bitkit/ui/components/KeyboardTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class KeyboardTest {
@Test
fun keyboard_displaysAllButtons() {
composeTestRule.setContent {
Keyboard(onClick = {})
Keyboard(onClick = {}, onClickBackspace = {})
}

composeTestRule.onNodeWithTag("KeyboardButton_1").assertIsDisplayed()
Expand All @@ -39,21 +39,21 @@ class KeyboardTest {
composeTestRule.onNodeWithTag("KeyboardButton_9").assertIsDisplayed()
composeTestRule.onNodeWithTag("KeyboardButton_.").assertIsDisplayed()
composeTestRule.onNodeWithTag("KeyboardButton_0").assertIsDisplayed()
composeTestRule.onNodeWithTag("KeyboardButton_").assertIsDisplayed()
composeTestRule.onNodeWithTag("KeyboardButton_backspace").assertIsDisplayed()
}

@Test
fun keyboard_tripleZero_when_not_decimal() {
composeTestRule.setContent {
Keyboard(onClick = {}, isDecimal = false)
Keyboard(onClick = {}, isDecimal = false, onClickBackspace = {})
}
composeTestRule.onNodeWithTag("KeyboardButton_000").assertIsDisplayed()
}

@Test
fun keyboard_decimal_when_decimal() {
composeTestRule.setContent {
Keyboard(onClick = {}, isDecimal = true)
Keyboard(onClick = {}, isDecimal = true, onClickBackspace = {})
}
composeTestRule.onNodeWithTag("KeyboardButton_.").assertIsDisplayed()
}
Expand All @@ -62,7 +62,7 @@ class KeyboardTest {
fun keyboard_button_click_triggers_callback() {
var clickedValue = ""
composeTestRule.setContent {
Keyboard(onClick = { clickedValue = it })
Keyboard(onClick = { clickedValue = it }, onClickBackspace = {})
}

composeTestRule.onNodeWithTag("KeyboardButton_5").performClick()
Expand All @@ -80,7 +80,7 @@ class KeyboardTest {
fun keyboard_button_click_tripleZero() {
var clickedValue = ""
composeTestRule.setContent {
Keyboard(onClick = { clickedValue = it }, isDecimal = false)
Keyboard(onClick = { clickedValue = it }, onClickBackspace = {}, isDecimal = false)
}

composeTestRule.onNodeWithTag("KeyboardButton_000").performClick()
Expand Down
57 changes: 45 additions & 12 deletions app/src/main/java/to/bitkit/ui/components/Keyboard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,34 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
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.style.TextAlign
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import to.bitkit.R
import to.bitkit.ui.theme.AppThemeSurface
import to.bitkit.ui.theme.Colors
import to.bitkit.ui.theme.InterFontFamily

@Composable
fun Keyboard(
onClick: (String) -> Unit,
isDecimal: Boolean = true,
modifier: Modifier = Modifier
onClickBackspace: () -> Unit,
modifier: Modifier = Modifier,
isDecimal: Boolean = true
) {
LazyVerticalGrid(
verticalArrangement = Arrangement.spacedBy(34.dp),
Expand All @@ -45,7 +51,17 @@ fun Keyboard(
item { KeyboardButton(text = "9", onClick = onClick) }
item { KeyboardButton(text = if (isDecimal) "." else "000", onClick = onClick) }
item { KeyboardButton(text = "0", onClick = onClick) }
item { KeyboardButton(text = "", onClick = onClick) }
item {
Icon(
painter = painterResource(R.drawable.ic_backspace),
contentDescription = stringResource(R.string.common__delete),
modifier = Modifier
.sizeIn(minHeight = 30.dp)
.padding(vertical = 4.dp)
.clickable(onClick = onClickBackspace)
.testTag("KeyboardButton_backspace")
)
}
}
}

Expand All @@ -65,12 +81,14 @@ private fun KeyboardButton(
textAlign = TextAlign.Center,
color = Colors.White,
),
modifier = Modifier.clickable(
onClick = {
onClick(text)
},
onClickLabel = text
).testTag("KeyboardButton_$text"),
modifier = Modifier
.clickable(
onClick = {
onClick(text)
},
onClickLabel = text
)
.testTag("KeyboardButton_$text"),
)
}

Expand All @@ -79,7 +97,10 @@ private fun KeyboardButton(
private fun Preview() {
AppThemeSurface {
Column(modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Bottom) {
Keyboard(modifier = Modifier.fillMaxWidth().padding(41.dp), onClick = {})
Keyboard(
modifier = Modifier
.fillMaxWidth()
.padding(41.dp), onClick = {}, onClickBackspace = {})
}
}
}
Expand All @@ -89,7 +110,13 @@ private fun Preview() {
private fun Preview2() {
AppThemeSurface {
Column(modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Bottom) {
Keyboard(isDecimal = false, modifier = Modifier.fillMaxWidth().padding(41.dp), onClick = {})
Keyboard(
isDecimal = false,
modifier = Modifier
.fillMaxWidth()
.padding(41.dp),
onClick = {},
onClickBackspace = {})
}
}
}
Expand All @@ -99,7 +126,13 @@ private fun Preview2() {
private fun Preview3() {
AppThemeSurface {
Column(modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Bottom) {
Keyboard(isDecimal = false, modifier = Modifier.fillMaxWidth().padding(41.dp), onClick = {})
Keyboard(
isDecimal = false,
modifier = Modifier
.fillMaxWidth()
.padding(41.dp),
onClick = {},
onClickBackspace = {})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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 okhttp3.internal.toLongOrDefault
import to.bitkit.R
import to.bitkit.models.NodeLifecycleState
import to.bitkit.models.PrimaryDisplay
Expand Down Expand Up @@ -63,7 +64,7 @@ fun SendAmountScreen(
Column(
modifier = Modifier.padding(horizontal = 16.dp)
) {
BalanceHeaderView(sats = uiState.amountInput.toLong(), modifier = Modifier.fillMaxWidth())
BalanceHeaderView(sats = uiState.amountInput.toLongOrDefault(0), modifier = Modifier.fillMaxWidth())

Spacer(modifier = Modifier.height(24.dp))

Expand Down Expand Up @@ -117,6 +118,7 @@ fun SendAmountScreen(

Keyboard(
onClick = { number -> onEvent(SendEvent.AmountChange(number)) },
onClickBackspace = { onEvent(SendEvent.BackSpaceClick) },
isDecimal = currencyUiState.primaryDisplay == PrimaryDisplay.FIAT,
modifier = Modifier.fillMaxWidth(),
)
Expand Down
21 changes: 17 additions & 4 deletions app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class AppViewModel @Inject constructor(

SendEvent.SpeedAndFee -> toast(Exception("Coming soon: Speed and Fee"))
SendEvent.SwipeToPay -> onPay()
SendEvent.BackSpaceClick -> onClickBackspace()
}
}
}
Expand Down Expand Up @@ -270,11 +271,22 @@ class AppViewModel @Inject constructor(

private fun onAmountChange(value: String) {
val newInput = if (_sendUiState.value.amountInput == "0") value else _sendUiState.value.amountInput + value
val isAmountValid = validateAmount(newInput)
if (isAmountValid) {
_sendUiState.update { it.copy( amountInput = newInput,) }
_sendUiState.update {
it.copy(
amountInput = newInput,
isAmountInputValid = validateAmount(newInput)
)
}
}

private fun onClickBackspace() {
val newInput = if (_sendUiState.value.amountInput.length <= 1) "0" else _sendUiState.value.amountInput.dropLast(1)
_sendUiState.update {
it.copy(
amountInput = newInput,
isAmountInputValid = validateAmount(newInput)
)
}
_sendUiState.update { it.copy(isAmountInputValid = isAmountValid,) }
}

private fun onPaymentMethodSwitch() {
Expand Down Expand Up @@ -742,6 +754,7 @@ sealed class SendEvent {
data object AmountReset : SendEvent()
data class AmountContinue(val amount: String) : SendEvent()
data class AmountChange(val value: String) : SendEvent()
data object BackSpaceClick : SendEvent()

data object SwipeToPay : SendEvent()
data object SpeedAndFee : SendEvent()
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/ic_backspace.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="18dp"
android:viewportWidth="24"
android:viewportHeight="18">
<path
android:pathData="M11.214,6.525C10.922,6.232 10.922,5.757 11.214,5.464C11.507,5.172 11.982,5.172 12.275,5.464L14.75,7.939L17.225,5.464C17.518,5.172 17.993,5.172 18.285,5.464C18.578,5.757 18.578,6.232 18.285,6.525L15.811,9L18.285,11.475C18.578,11.768 18.578,12.243 18.285,12.535C17.993,12.828 17.518,12.828 17.225,12.535L14.75,10.061L12.275,12.535C11.982,12.828 11.507,12.828 11.215,12.535C10.922,12.243 10.922,11.768 11.215,11.475L13.689,9L11.214,6.525Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M8.121,1.379L0.5,9L8.121,16.621C8.684,17.184 9.447,17.5 10.243,17.5H20.5C22.157,17.5 23.5,16.157 23.5,14.5V3.5C23.5,1.843 22.157,0.5 20.5,0.5H10.243C9.447,0.5 8.684,0.816 8.121,1.379ZM20.5,16.2H10.243C9.792,16.2 9.359,16.021 9.041,15.702L2.339,9L9.041,2.298C9.359,1.979 9.792,1.8 10.243,1.8H20.5C21.439,1.8 22.2,2.561 22.2,3.5V14.5C22.2,15.439 21.439,16.2 20.5,16.2Z"
android:fillColor="#ffffff"
android:fillType="evenOdd"/>
</vector>