mirror of
https://github.com/AdrianKuta/android-challange-adrian-kuta.git
synced 2025-07-02 06:27:58 +02:00
Refactor: Improve flight search UI and logic
This commit introduces several enhancements to the flight search user interface and underlying logic. Key changes: - Added an extension function `Flight.hasFlights()` to check if a flight object contains any actual flight data. This is located in `ui/home/src/main/kotlin/dev/adriankuta/flights/ui/home/extensions/FlightExt.kt`. - In `StationsScreen.kt`: - The origin airport display now includes a "Origin airport" label. - The search input field placeholder text dynamically changes based on whether an origin airport has been selected (e.g., "Search origin airport" vs. "Search destination airport"). - In `StationsScreenViewModel.kt`: - When an airport is selected, the search query is now automatically cleared. - Added new string resources in `ui/stations/src/main/res/values/strings.xml` for the dynamic placeholder text: `search_origin_airport` and `search_destination_airport`. - In `SearchResults.kt`: - Implemented an `EmptyListComponent` to display a user-friendly message with an icon when no flights are found for the given search criteria. - The `SearchResults` composable now utilizes `itemsIndexed` for better handling of dividers between trip cards. - Dividers are no longer shown after the last item in the list of trips or trip dates. - Added previews for the empty list state (`EmptyListPreview` and `SearchResultsEmptyPreview`).
This commit is contained in:
@ -71,9 +71,21 @@ private fun StationsScreen(
|
||||
LaunchedEffect(selectedOriginAirport) {
|
||||
selectedOriginAirport?.let { airportInfo = it }
|
||||
}
|
||||
AirportInfoCompact(
|
||||
data = airportInfo,
|
||||
)
|
||||
Column {
|
||||
Text(
|
||||
text = "Origin airport",
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
)
|
||||
AirportInfoCompact(
|
||||
data = airportInfo,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val hintRes = if (selectedOriginAirport == null) {
|
||||
R.string.search_origin_airport
|
||||
} else {
|
||||
R.string.search_destination_airport
|
||||
}
|
||||
|
||||
OutlinedTextField(
|
||||
@ -82,7 +94,7 @@ private fun StationsScreen(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
placeholder = { Text(text = stringResource(R.string.search_airports)) },
|
||||
placeholder = { Text(text = stringResource(hintRes)) },
|
||||
leadingIcon = { Icon(Icons.Default.Search, contentDescription = null) },
|
||||
singleLine = true,
|
||||
)
|
||||
|
@ -45,6 +45,7 @@ internal class StationsScreenViewModel @Inject constructor(
|
||||
|
||||
fun onAirportSelected(airport: AirportInfo) {
|
||||
_selectedOriginAirport.value = airport
|
||||
_searchQuery.value = ""
|
||||
}
|
||||
|
||||
fun clearSelectedAirport() {
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="stations_screen_title">Stations</string>
|
||||
<string name="search_airports">Search airports</string>
|
||||
<string name="search_origin_airport">Search origin airport</string>
|
||||
<string name="search_destination_airport">Search destination airport</string>
|
||||
</resources>
|
||||
|
Reference in New Issue
Block a user