Skip to content

Commit 345ad97

Browse files
committed
refactor: replace NumberPadSimple with NumberPad of simple type
1 parent 3737984 commit 345ad97

File tree

12 files changed

+68
-113
lines changed

12 files changed

+68
-113
lines changed

app/src/main/java/to/bitkit/ui/components/AuthCheckView.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ private fun PinPad(
205205
pin = pin,
206206
modifier = Modifier.padding(vertical = 16.dp),
207207
)
208-
NumberPadSimple(
209-
modifier = Modifier.height(310.dp),
208+
NumberPad(
210209
onPress = { key ->
211210
if (key == KEY_DELETE) {
212211
if (pin.isNotEmpty()) {
@@ -216,6 +215,8 @@ private fun PinPad(
216215
pin += key
217216
}
218217
},
218+
type = NumberPadType.SIMPLE,
219+
modifier = Modifier.height(310.dp),
219220
)
220221
}
221222
}

app/src/main/java/to/bitkit/ui/components/NumberPad.kt

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.compose.foundation.lazy.grid.items
1212
import androidx.compose.material3.Icon
1313
import androidx.compose.material3.Text
1414
import androidx.compose.runtime.Composable
15+
import androidx.compose.runtime.getValue
1516
import androidx.compose.ui.Alignment
1617
import androidx.compose.ui.Modifier
1718
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
@@ -51,19 +52,16 @@ private val pressHaptic = HapticFeedbackType.VirtualKey
5152
private val errorHaptic = HapticFeedbackType.Reject
5253

5354
/**
54-
* Numeric keyboard. Can be used together with [NumberPadTextField] for amounts.
55+
* Numeric keyboard.
5556
*/
5657
@Composable
5758
fun NumberPad(
58-
viewModel: AmountInputViewModel,
59+
onPress: (String) -> Unit,
5960
modifier: Modifier = Modifier,
60-
currencies: CurrencyState = LocalCurrencies.current,
61-
type: NumberPadType = viewModel.getNumberPadType(currencies),
61+
type: NumberPadType = NumberPadType.SIMPLE,
6262
availableHeight: Dp? = null,
63-
errorKey: String? = viewModel.uiState.collectAsStateWithLifecycle().value.errorKey,
64-
onPress: (String) -> Unit = { key -> viewModel.handleNumberPadInput(key, currencies) },
63+
errorKey: String? = null,
6564
) {
66-
6765
BoxWithConstraints(modifier = modifier) {
6866
val constraintsHeight = this.maxHeight
6967
val effectiveHeight = availableHeight ?: constraintsHeight
@@ -139,6 +137,27 @@ fun NumberPad(
139137
}
140138
}
141139

140+
/**
141+
* Numeric keyboard for amount input. Can be used together with [NumberPadTextField].
142+
*/
143+
@Composable
144+
fun NumberPad(
145+
viewModel: AmountInputViewModel,
146+
modifier: Modifier = Modifier,
147+
currencies: CurrencyState = LocalCurrencies.current,
148+
type: NumberPadType = viewModel.getNumberPadType(currencies),
149+
availableHeight: Dp? = null,
150+
) {
151+
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
152+
NumberPad(
153+
onPress = { key -> viewModel.handleNumberPadInput(key, currencies) },
154+
modifier = modifier,
155+
type = type,
156+
availableHeight = availableHeight,
157+
errorKey = uiState.errorKey,
158+
)
159+
}
160+
142161
enum class NumberPadType { SIMPLE, INTEGER, DECIMAL }
143162

144163
@Composable

app/src/main/java/to/bitkit/ui/components/NumberPadSimple.kt

Lines changed: 0 additions & 83 deletions
This file was deleted.

app/src/main/java/to/bitkit/ui/screens/transfer/external/ExternalFeeCustomScreen.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ import to.bitkit.ui.components.Display
3131
import to.bitkit.ui.components.FillHeight
3232
import to.bitkit.ui.components.KEY_DELETE
3333
import to.bitkit.ui.components.LargeRow
34-
import to.bitkit.ui.components.NumberPadSimple
34+
import to.bitkit.ui.components.NumberPad
35+
import to.bitkit.ui.components.NumberPadType
3536
import to.bitkit.ui.components.PrimaryButton
3637
import to.bitkit.ui.components.VerticalSpacer
3738
import to.bitkit.ui.currencyViewModel
@@ -159,8 +160,9 @@ private fun Content(
159160

160161
FillHeight()
161162

162-
NumberPadSimple(
163+
NumberPad(
163164
onPress = onKeyPress,
165+
type = NumberPadType.SIMPLE,
164166
modifier = Modifier
165167
.height(350.dp)
166168
.testTag("FeeCustomNumberPad")

app/src/main/java/to/bitkit/ui/screens/wallets/send/SendFeeCustomScreen.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import to.bitkit.ui.components.BodyM
2323
import to.bitkit.ui.components.BottomSheetPreview
2424
import to.bitkit.ui.components.FillHeight
2525
import to.bitkit.ui.components.LargeRow
26-
import to.bitkit.ui.components.NumberPadSimple
26+
import to.bitkit.ui.components.NumberPad
27+
import to.bitkit.ui.components.NumberPadType
2728
import to.bitkit.ui.components.PrimaryButton
2829
import to.bitkit.ui.components.VerticalSpacer
2930
import to.bitkit.ui.components.settings.SectionHeader
@@ -95,8 +96,9 @@ private fun Content(
9596

9697
FillHeight()
9798

98-
NumberPadSimple(
99+
NumberPad(
99100
onPress = onKeyPress,
101+
type = NumberPadType.SIMPLE,
100102
modifier = Modifier.height(350.dp)
101103
)
102104
PrimaryButton(

app/src/main/java/to/bitkit/ui/screens/wallets/send/SendPinCheckScreen.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import to.bitkit.ui.components.BodyM
2828
import to.bitkit.ui.components.BodyS
2929
import to.bitkit.ui.components.BottomSheetPreview
3030
import to.bitkit.ui.components.KEY_DELETE
31-
import to.bitkit.ui.components.NumberPadSimple
31+
import to.bitkit.ui.components.NumberPad
32+
import to.bitkit.ui.components.NumberPadType
3233
import to.bitkit.ui.components.PinDots
3334
import to.bitkit.ui.scaffold.SheetTopBar
3435
import to.bitkit.ui.shared.modifiers.sheetHeight
@@ -139,8 +140,9 @@ private fun PinCheckContent(
139140

140141
Spacer(modifier = Modifier.weight(1f))
141142

142-
NumberPadSimple(
143+
NumberPad(
143144
onPress = onKeyPress,
145+
type = NumberPadType.SIMPLE,
144146
modifier = Modifier
145147
.height(350.dp)
146148
.background(Colors.Black)

app/src/main/java/to/bitkit/ui/settings/pin/ChangePinConfirmScreen.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import to.bitkit.ui.appViewModel
2727
import to.bitkit.ui.components.BodyM
2828
import to.bitkit.ui.components.BodyS
2929
import to.bitkit.ui.components.KEY_DELETE
30-
import to.bitkit.ui.components.NumberPadSimple
30+
import to.bitkit.ui.components.NumberPad
31+
import to.bitkit.ui.components.NumberPadType
3132
import to.bitkit.ui.components.PinDots
3233
import to.bitkit.ui.navigateToChangePinResult
3334
import to.bitkit.ui.navigateToHome
@@ -122,9 +123,10 @@ private fun ChangePinConfirmContent(
122123

123124
Spacer(modifier = Modifier.weight(1f))
124125

125-
NumberPadSimple(
126-
modifier = Modifier.height(350.dp),
126+
NumberPad(
127127
onPress = onKeyPress,
128+
type = NumberPadType.SIMPLE,
129+
modifier = Modifier.height(350.dp),
128130
)
129131
}
130132
}

app/src/main/java/to/bitkit/ui/settings/pin/ChangePinNewScreen.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import to.bitkit.R
2121
import to.bitkit.env.Env
2222
import to.bitkit.ui.components.BodyM
2323
import to.bitkit.ui.components.KEY_DELETE
24-
import to.bitkit.ui.components.NumberPadSimple
24+
import to.bitkit.ui.components.NumberPad
25+
import to.bitkit.ui.components.NumberPadType
2526
import to.bitkit.ui.components.PinDots
2627
import to.bitkit.ui.navigateToChangePinConfirm
2728
import to.bitkit.ui.navigateToHome
@@ -93,9 +94,10 @@ private fun ChangePinNewContent(
9394

9495
Spacer(modifier = Modifier.weight(1f))
9596

96-
NumberPadSimple(
97-
modifier = Modifier.height(350.dp),
97+
NumberPad(
9898
onPress = onKeyPress,
99+
type = NumberPadType.SIMPLE,
100+
modifier = Modifier.height(350.dp),
99101
)
100102
}
101103
}

app/src/main/java/to/bitkit/ui/settings/pin/ChangePinScreen.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import to.bitkit.ui.appViewModel
2626
import to.bitkit.ui.components.BodyM
2727
import to.bitkit.ui.components.BodyS
2828
import to.bitkit.ui.components.KEY_DELETE
29-
import to.bitkit.ui.components.NumberPadSimple
29+
import to.bitkit.ui.components.NumberPad
30+
import to.bitkit.ui.components.NumberPadType
3031
import to.bitkit.ui.components.PinDots
3132
import to.bitkit.ui.navigateToChangePinNew
3233
import to.bitkit.ui.navigateToHome
@@ -133,9 +134,10 @@ private fun ChangePinContent(
133134

134135
Spacer(modifier = Modifier.weight(1f))
135136

136-
NumberPadSimple(
137-
modifier = Modifier.height(350.dp),
137+
NumberPad(
138138
onPress = onKeyPress,
139+
type = NumberPadType.SIMPLE,
140+
modifier = Modifier.height(350.dp),
139141
)
140142
}
141143
}

app/src/main/java/to/bitkit/ui/settings/pin/PinChooseScreen.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import to.bitkit.R
2020
import to.bitkit.env.Env
2121
import to.bitkit.ui.components.BodyM
2222
import to.bitkit.ui.components.KEY_DELETE
23-
import to.bitkit.ui.components.NumberPadSimple
23+
import to.bitkit.ui.components.NumberPad
24+
import to.bitkit.ui.components.NumberPadType
2425
import to.bitkit.ui.components.PinDots
2526
import to.bitkit.ui.scaffold.SheetTopBar
2627
import to.bitkit.ui.shared.util.gradientBackground
@@ -58,7 +59,7 @@ fun PinChooseScreen(
5859

5960
Spacer(modifier = Modifier.height(32.dp))
6061

61-
NumberPadSimple(
62+
NumberPad(
6263
onPress = { key ->
6364
if (key == KEY_DELETE) {
6465
if (pin.isNotEmpty()) {
@@ -71,6 +72,7 @@ fun PinChooseScreen(
7172
}
7273
}
7374
},
75+
type = NumberPadType.SIMPLE,
7476
modifier = Modifier
7577
.height(350.dp)
7678
.background(Colors.Black)

0 commit comments

Comments
 (0)