-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add search screen body & search result UI & test OfflineRepository
- Loading branch information
1 parent
5341424
commit 52a5d03
Showing
22 changed files
with
1,028 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/nabilbdev/searchflight/SearchFlightApp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.nabilbdev.searchflight | ||
|
||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.ui.Modifier | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import com.nabilbdev.searchflight.ui.AppViewModelProvider | ||
import com.nabilbdev.searchflight.ui.screens.search.LoadUiState | ||
import com.nabilbdev.searchflight.ui.screens.search.MySearchBar | ||
import com.nabilbdev.searchflight.ui.screens.search.SearchScreen | ||
import com.nabilbdev.searchflight.ui.screens.search.SearchScreenViewModel | ||
import com.nabilbdev.searchflight.ui.screens.search.SearchUiState | ||
import com.nabilbdev.searchflight.ui.screens.search.SelectUiState | ||
|
||
@Composable | ||
fun SearchFlightApp() { | ||
|
||
val viewModel: SearchScreenViewModel = viewModel(factory = AppViewModelProvider.Factory) | ||
val searchUiState: SearchUiState = viewModel.searchUiState.collectAsState().value | ||
val selectUiState: SelectUiState = viewModel.selectUiState.collectAsState().value | ||
val loadUiState: LoadUiState = viewModel.loadUiState.collectAsState().value | ||
|
||
Scaffold( | ||
topBar = { | ||
MySearchBar( | ||
query = searchUiState.searchQuery, | ||
errorMessage = loadUiState.errorMessage, | ||
allAirportsList = selectUiState.allAirportList, | ||
airportListByQuery = searchUiState.airportListByQuery, | ||
viewModel = viewModel | ||
) | ||
} | ||
) { innerPadding -> | ||
SearchScreen( | ||
popularCitiesAirports = searchUiState.popularCityAirports, | ||
isLoadingAirports = loadUiState.isLoadingPopularCityAirports, | ||
modifier = Modifier.padding(innerPadding) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/nabilbdev/searchflight/ui/AppViewModelProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.nabilbdev.searchflight.ui | ||
|
||
import android.app.Application | ||
import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory | ||
import androidx.lifecycle.viewmodel.CreationExtras | ||
import androidx.lifecycle.viewmodel.initializer | ||
import androidx.lifecycle.viewmodel.viewModelFactory | ||
import com.nabilbdev.searchflight.SearchFlightApplication | ||
import com.nabilbdev.searchflight.ui.screens.search.SearchScreenViewModel | ||
|
||
/** | ||
* Provides Factory to create instance of ViewModel for the entire SearchFlight app | ||
*/ | ||
object AppViewModelProvider { | ||
val Factory = viewModelFactory { | ||
initializer { | ||
SearchScreenViewModel( | ||
searchFlightRepository = searchFLightApplication().container.searchFlightRepository | ||
) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Extension function to queries for [Application] object and returns an instance of | ||
* [SearchFlightApplication]. | ||
*/ | ||
fun CreationExtras.searchFLightApplication(): SearchFlightApplication = | ||
(this[AndroidViewModelFactory.APPLICATION_KEY] as SearchFlightApplication) |
67 changes: 67 additions & 0 deletions
67
app/src/main/java/com/nabilbdev/searchflight/ui/components/AirportCard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.nabilbdev.searchflight.ui.components | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.aspectRatio | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.Card | ||
import androidx.compose.material3.CardDefaults | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.unit.dp | ||
import com.nabilbdev.searchflight.data.local.entity.Airport | ||
|
||
@Composable | ||
fun AirportCard( | ||
airport: Airport, | ||
imageVector: ImageVector, | ||
modifier: Modifier = Modifier | ||
) { | ||
Card( | ||
modifier = modifier | ||
.aspectRatio(4f / 2f), | ||
shape = CardDefaults.elevatedShape | ||
) { | ||
|
||
Row( | ||
horizontalArrangement = Arrangement.Center, | ||
verticalAlignment = Alignment.Top, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(10.dp), | ||
) { | ||
Text( | ||
text = airport.name, | ||
fontWeight = FontWeight.Bold, | ||
maxLines = 2, | ||
overflow = TextOverflow.Ellipsis, | ||
style = MaterialTheme.typography.bodySmall, | ||
modifier = Modifier | ||
.weight(0.5f) | ||
) | ||
Box( | ||
modifier = Modifier | ||
.weight(0.2f), | ||
contentAlignment = Alignment.TopEnd | ||
) { | ||
Icon( | ||
imageVector = imageVector, | ||
contentDescription = null, | ||
tint = MaterialTheme.colorScheme.primary, | ||
modifier = Modifier | ||
.size(20.dp) | ||
) | ||
} | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
app/src/main/java/com/nabilbdev/searchflight/ui/components/BasicVerticalGrid.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.nabilbdev.searchflight.ui.components | ||
|
||
import androidx.compose.animation.AnimatedVisibility | ||
import androidx.compose.animation.fadeIn | ||
import androidx.compose.animation.fadeOut | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.LinearProgressIndicator | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.unit.dp | ||
import com.nabilbdev.searchflight.data.local.entity.Airport | ||
|
||
@Composable | ||
fun CommonAirportVerticalGrid( | ||
titleContent: String, | ||
airportList: List<Airport>, | ||
imageVector: ImageVector, | ||
modifier: Modifier = Modifier, | ||
isLoadingAirports: Boolean = false | ||
) { | ||
AnimatedVisibility(visible = isLoadingAirports, exit = fadeOut()) { | ||
Box(modifier = modifier.fillMaxSize(), contentAlignment = Alignment.Center) { | ||
LinearProgressIndicator() | ||
} | ||
} | ||
AnimatedVisibility(visible = !isLoadingAirports, enter = fadeIn()) { | ||
CustomVerticalGrid( | ||
titleContent = titleContent, | ||
airportList = airportList, | ||
imageVector = imageVector | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Create a custom grid layout using a combination of Row and Column | ||
*/ | ||
@Composable | ||
fun CustomVerticalGrid( | ||
titleContent: String, | ||
airportList: List<Airport>, | ||
imageVector: ImageVector, | ||
modifier: Modifier = Modifier | ||
) { | ||
Column { | ||
Text(text = titleContent, style = MaterialTheme.typography.titleLarge) | ||
Spacer(modifier = modifier.height(8.dp)) | ||
airportList.chunked(2).forEach { halfList -> | ||
Row(modifier = modifier.fillMaxWidth()) { | ||
halfList.forEach { airport -> | ||
AirportCard( | ||
airport = airport, | ||
imageVector = imageVector, | ||
modifier = Modifier | ||
.weight(1f) | ||
.padding(4.dp) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.