mirror of
https://github.com/AdrianKuta/android-challange-adrian-kuta.git
synced 2025-07-02 05:58:00 +02:00
Refactor: Introduce SearchForm and PassengersOptions composables
This commit refactors the HomeScreen by extracting the search form logic into a new `SearchForm` composable and the passenger selection into a `PassengersOptions` composable. Key changes: - Created `PassengersOptions.kt` with a composable function to handle adult, teen, and child passenger counts. - Created `SearchForm.kt` with a composable function that encapsulates airport selection, date picking, passenger options, and the search button. - Updated `HomeScreen.kt`: - Replaced the previous inline form layout with the new `SearchForm` composable. - Made the screen content vertically scrollable using `Box` and `verticalScroll`. - Passed a new `onSearch` lambda to the `HomeScreenContent`. - Updated `HomeScreenViewModel.kt`: - Modified `updateAdultCount`, `updateTeenCount`, and `updateChildCount` to accept the new count directly instead of a diff. - Added a `search()` function (currently logs to Timber). - Ensured child count does not exceed adult count when adult count changes. - Updated `Counter.kt` in `ui/sharedui`: - Changed `onCountChange` parameter to `onValueChange` which now receives the new absolute value. - Added a `maxVal` parameter to limit the maximum value of the counter.
This commit is contained in:
@ -34,10 +34,11 @@ import dev.adriankuta.flights.ui.designsystem.theme.FlightsTheme
|
||||
@Composable
|
||||
fun Counter(
|
||||
value: Int,
|
||||
onCountChange: (diff: Int) -> Unit,
|
||||
onValueChange: (newValue: Int) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
label: String? = null,
|
||||
minVal: Int = 0,
|
||||
maxVal: Int = Int.MAX_VALUE,
|
||||
) {
|
||||
val view = LocalView.current
|
||||
|
||||
@ -84,7 +85,7 @@ fun Counter(
|
||||
modifier = Modifier.weight(1f),
|
||||
onClick = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP)
|
||||
onCountChange(-1)
|
||||
onValueChange(value - 1)
|
||||
},
|
||||
shape = MaterialTheme.shapes.medium,
|
||||
enabled = value > minVal,
|
||||
@ -99,10 +100,10 @@ fun Counter(
|
||||
modifier = Modifier.weight(1f),
|
||||
onClick = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP)
|
||||
onCountChange(1)
|
||||
onValueChange(value + 1)
|
||||
},
|
||||
shape = MaterialTheme.shapes.medium,
|
||||
enabled = value < 20,
|
||||
enabled = value < maxVal,
|
||||
) {
|
||||
Text(
|
||||
text = "+",
|
||||
@ -124,7 +125,8 @@ private fun CounterPreview() {
|
||||
Counter(
|
||||
value = tapCounter,
|
||||
label = "Taps",
|
||||
onCountChange = { tapCounter += it },
|
||||
onValueChange = { tapCounter += it },
|
||||
maxVal = 20,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user