-
Notifications
You must be signed in to change notification settings - Fork 0
Implement Filtering UI #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
56670b0
db041a6
e95dbca
892ac11
074e75b
a71f3af
3b3d8d1
1df94ec
c90d948
74a29ad
ece224d
8845964
57ed6cd
b1c41ec
4ac9ec8
b36124e
04f9007
46a5370
903c2e1
072e774
7d807bb
b182f14
2259ebd
6924f02
c9a6192
727a0e0
cb090b2
6962eaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package com.cornellappdev.transit.ui.components.home | ||
|
|
||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.PaddingValues | ||
| import androidx.compose.foundation.layout.Row | ||
|
|
@@ -12,8 +13,12 @@ import androidx.compose.foundation.lazy.LazyColumn | |
| import androidx.compose.foundation.lazy.LazyListScope | ||
| import androidx.compose.foundation.lazy.LazyRow | ||
| import androidx.compose.foundation.lazy.items | ||
| import androidx.compose.material3.ExperimentalMaterial3Api | ||
| import androidx.compose.material3.HorizontalDivider | ||
| import androidx.compose.material3.ModalBottomSheet | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.text.AnnotatedString | ||
|
|
@@ -22,13 +27,15 @@ import androidx.compose.ui.tooling.preview.Preview | |
| import androidx.compose.ui.unit.dp | ||
| import androidx.compose.ui.unit.sp | ||
| import androidx.hilt.navigation.compose.hiltViewModel | ||
| import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
| import com.cornellappdev.transit.R | ||
| import com.cornellappdev.transit.models.Place | ||
| import com.cornellappdev.transit.models.ecosystem.DayOperatingHours | ||
| import com.cornellappdev.transit.models.ecosystem.DetailedEcosystemPlace | ||
| import com.cornellappdev.transit.models.ecosystem.Eatery | ||
| import com.cornellappdev.transit.models.ecosystem.StaticPlaces | ||
| import com.cornellappdev.transit.networking.ApiResponse | ||
| import com.cornellappdev.transit.ui.theme.FavoritesDividerGray | ||
| import com.cornellappdev.transit.ui.theme.robotoFamily | ||
| import com.cornellappdev.transit.ui.viewmodels.FilterState | ||
| import com.cornellappdev.transit.ui.viewmodels.HomeViewModel | ||
|
|
@@ -43,6 +50,7 @@ import com.cornellappdev.transit.util.ecosystem.toPlace | |
| * @param staticPlaces Collection of all places to populate filters with | ||
| * @param navigateToPlace Function called to navigate to route options | ||
| */ | ||
| @OptIn(ExperimentalMaterial3Api::class) | ||
| @Composable | ||
| fun EcosystemBottomSheetContent( | ||
| filters: List<FilterState>, | ||
|
|
@@ -54,7 +62,10 @@ fun EcosystemBottomSheetContent( | |
| navigateToPlace: (Place) -> Unit, | ||
| onDetailsClick: (DetailedEcosystemPlace) -> Unit, | ||
| onFavoriteStarClick: (Place) -> Unit, | ||
| showFilterSheet: Boolean, | ||
| onFilterSheetShow: () -> Unit, | ||
| onAddFavoritesClick: () -> Unit, | ||
| homeViewModel: HomeViewModel = hiltViewModel(), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't be passing view models to composables, they should ideally only be used on the screen composable. You should just add whatever fields or functions you need from the vm to this composable as parameters
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there are too many parameters, you can consider grouping some together into a data class |
||
| ) { | ||
| Column(modifier = modifier) { | ||
| Row( | ||
|
|
@@ -76,7 +87,7 @@ fun EcosystemBottomSheetContent( | |
| ) | ||
| } | ||
|
|
||
| LazyRow { | ||
| LazyRow(modifier = Modifier.padding(bottom = 12.dp)) { | ||
| items(filters) { | ||
| BottomSheetFilterItem( | ||
| imageResId = it.iconId, | ||
|
|
@@ -95,9 +106,35 @@ fun EcosystemBottomSheetContent( | |
| navigateToPlace = navigateToPlace, | ||
| onDetailsClick = onDetailsClick, | ||
| onFavoriteStarClick = onFavoriteStarClick, | ||
| onFilterButtonClick = onFilterSheetShow, | ||
| onAddFavoritesClick = onAddFavoritesClick | ||
| ) | ||
| } | ||
|
|
||
| val selectedFilters by homeViewModel.selectedFavoritesFilters.collectAsStateWithLifecycle() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above comment, but this should be passed in instead of using the home vm here |
||
|
|
||
| if (showFilterSheet) { | ||
| ModalBottomSheet( | ||
| onDismissRequest = { | ||
| homeViewModel.cancelFavoritesFilters() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above for all functions you are using from home view model |
||
| }, | ||
| dragHandle = null | ||
| ) { | ||
| FavoritesFilterBottomSheet( | ||
| onCancelClicked = { | ||
| homeViewModel.cancelFavoritesFilters() | ||
| }, | ||
| onApplyClicked = { | ||
| homeViewModel.applyFavoritesFilters() | ||
| }, | ||
| filters = homeViewModel.favoritesFilterList, | ||
| selectedFilters = selectedFilters, | ||
| onFilterToggle = { filter -> | ||
| homeViewModel.toggleFavoritesFilter(filter) | ||
| } | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
|
|
@@ -109,43 +146,74 @@ private fun BottomSheetFilteredContent( | |
| navigateToPlace: (Place) -> Unit, | ||
| onDetailsClick: (DetailedEcosystemPlace) -> Unit, | ||
| onFavoriteStarClick: (Place) -> Unit, | ||
| onAddFavoritesClick: () -> Unit | ||
| onAddFavoritesClick: () -> Unit, | ||
| onFilterButtonClick: () -> Unit | ||
| ) { | ||
| LazyColumn( | ||
| contentPadding = PaddingValues(start = 24.dp, end = 24.dp, top = 20.dp, bottom = 90.dp), | ||
| modifier = Modifier.fillMaxSize() | ||
| ) { | ||
| when (currentFilter) { | ||
| FilterState.FAVORITES -> { | ||
| favoriteList(favorites, navigateToPlace, onAddFavoritesClick) | ||
| val appliedFilters by homeViewModel.appliedFavoritesFilters.collectAsStateWithLifecycle() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
| Column { | ||
| if (currentFilter == FilterState.FAVORITES) { | ||
| Column(modifier = Modifier.padding(horizontal = 12.dp)) { | ||
| HorizontalDivider( | ||
| modifier = Modifier.padding(vertical = 8.dp), | ||
| color = FavoritesDividerGray | ||
| ) | ||
| FilterRow( | ||
| selectedFilters = appliedFilters, | ||
| onFilterClick = onFilterButtonClick, | ||
| onRemoveFilter = { filter -> homeViewModel.removeAppliedFilter(filter) } | ||
| ) | ||
| if (appliedFilters.isNotEmpty()) { | ||
| Spacer(modifier = Modifier.height(8.dp)) | ||
| } | ||
| } | ||
| } | ||
| val isFilterBarHidden = currentFilter == FilterState.FAVORITES && appliedFilters.isEmpty() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: might be worth abstracting to vm or using some sort of derived value from the data class |
||
| LazyColumn( | ||
| contentPadding = PaddingValues( | ||
| start = 12.dp, | ||
| end = 12.dp, | ||
| top = if (isFilterBarHidden) 0.dp else 8.dp, | ||
| bottom = 120.dp // Makes bottom content visible with padding at the end | ||
| ), | ||
| modifier = Modifier.fillMaxSize(), | ||
| verticalArrangement = Arrangement.spacedBy(20.dp) | ||
| ) { | ||
| when (currentFilter) { | ||
| FilterState.FAVORITES -> { | ||
| favoriteList( | ||
| favorites, | ||
| navigateToPlace, | ||
| onAddFavoritesClick | ||
| ) | ||
| } | ||
|
|
||
| FilterState.PRINTERS -> { | ||
| printerList(staticPlaces, navigateToPlace) | ||
| } | ||
| FilterState.PRINTERS -> { | ||
| printerList(staticPlaces, navigateToPlace) | ||
| } | ||
|
|
||
| FilterState.GYMS -> { | ||
| gymList(staticPlaces, navigateToPlace) | ||
| } | ||
| FilterState.GYMS -> { | ||
| gymList(staticPlaces, navigateToPlace) | ||
| } | ||
|
|
||
| FilterState.EATERIES -> { | ||
| eateryList( | ||
| eateriesApiResponse = staticPlaces.eateries, | ||
| onDetailsClick = onDetailsClick, | ||
| favorites = favorites, | ||
| onFavoriteStarClick = onFavoriteStarClick, | ||
| operatingHoursToString = homeViewModel::isOpenAnnotatedStringFromOperatingHours | ||
| ) | ||
| } | ||
| FilterState.EATERIES -> { | ||
| eateryList( | ||
| eateriesApiResponse = staticPlaces.eateries, | ||
| onDetailsClick = onDetailsClick, | ||
| favorites = favorites, | ||
| onFavoriteStarClick = onFavoriteStarClick, | ||
| operatingHoursToString = homeViewModel::isOpenAnnotatedStringFromOperatingHours | ||
| ) | ||
| } | ||
|
|
||
| FilterState.LIBRARIES -> { | ||
| libraryList( | ||
| staticPlaces, | ||
| navigateToPlace, | ||
| onDetailsClick, | ||
| favorites, | ||
| onFavoriteStarClick, | ||
| ) | ||
| FilterState.LIBRARIES -> { | ||
| libraryList( | ||
| staticPlaces, | ||
| navigateToPlace, | ||
| onDetailsClick, | ||
| favorites, | ||
| onFavoriteStarClick, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -160,8 +228,8 @@ private fun LazyListScope.favoriteList( | |
| onAddFavoritesClick: () -> Unit | ||
| ) { | ||
| item { | ||
| Spacer(modifier = Modifier.height(8.dp)) | ||
| AddFavoritesButton(onAddFavoritesClick = onAddFavoritesClick) | ||
| Spacer(Modifier.height(20.dp)) | ||
| } | ||
| items(favorites.toList()) { | ||
| BottomSheetLocationCard( | ||
|
|
@@ -170,7 +238,6 @@ private fun LazyListScope.favoriteList( | |
| ) { | ||
| //TODO: Eatery | ||
| } | ||
| Spacer(Modifier.height(10.dp)) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -196,7 +263,6 @@ private fun LazyListScope.gymList( | |
| ) { | ||
| //TODO: Eatery | ||
| } | ||
| Spacer(Modifier.height(10.dp)) | ||
| } | ||
|
|
||
| } | ||
|
|
@@ -271,7 +337,6 @@ private fun LazyListScope.eateryList( | |
| ) { | ||
| onDetailsClick(it) | ||
| } | ||
| Spacer(Modifier.height(10.dp)) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -307,7 +372,6 @@ private fun LazyListScope.libraryList( | |
| ) { | ||
| navigateToDetails(it) | ||
| } | ||
| Spacer(Modifier.height(10.dp)) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -337,6 +401,8 @@ private fun PreviewEcosystemBottomSheet() { | |
| navigateToPlace = {}, | ||
| onDetailsClick = {}, | ||
| onFavoriteStarClick = {}, | ||
| onAddFavoritesClick = {} | ||
| onAddFavoritesClick = {}, | ||
| showFilterSheet = true, | ||
| onFilterSheetShow = {} | ||
| ) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import is unused and should be removed. The text variable is not referenced anywhere in the file.