-
Notifications
You must be signed in to change notification settings - Fork 136
[Bookings] Type filter #14858
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
Merged
Merged
[Bookings] Type filter #14858
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1e482a7
Adds string resources for type filter
irfano 13b6c07
Add BookingTypeFilterUiState
irfano 0dc120f
Move `BookingFilterListItem` to its own file
irfano 8236942
Add single choice filter page
irfano a249bb6
Create booking type filter page
irfano 640ca4d
Add dummy state for booking type filter screen
irfano 3b08b52
Show new booking type page in filters screens
irfano 4db1805
Merge branch 'trunk' into issue/WOOMOB-1465-bookings-type-filter
irfano 2291267
Merge branch 'trunk' into issue/WOOMOB-1465-bookings-type-filter
irfano d77fed5
Move BookingType filter model to FluxC
irfano 7976b4c
Add BookingTypeFilterViewModel
irfano 60c9f47
Add BookingTypeFilterRoute composable
irfano 59ba3a9
Update booking type filter selection
irfano e1bee75
Fix detekt error
irfano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...merce/src/main/kotlin/com/woocommerce/android/ui/bookings/filter/BookingFilterListItem.kt
This file contains hidden or 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,12 @@ | ||
| package com.woocommerce.android.ui.bookings.filter | ||
|
|
||
| import androidx.annotation.StringRes | ||
|
|
||
| /** | ||
| * UI model simple filter item | ||
| */ | ||
| data class BookingFilterListItem( | ||
| @StringRes val title: Int, | ||
| val value: String? = null, | ||
| val onClick: () -> Unit = {} | ||
| ) | ||
This file contains hidden or 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 hidden or 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
74 changes: 74 additions & 0 deletions
74
...erce/src/main/kotlin/com/woocommerce/android/ui/bookings/filter/SingleChoiceFilterPage.kt
This file contains hidden or 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,74 @@ | ||
| package com.woocommerce.android.ui.bookings.filter | ||
|
|
||
| import androidx.compose.foundation.clickable | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.defaultMinSize | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.lazy.LazyColumn | ||
| import androidx.compose.foundation.lazy.items | ||
| import androidx.compose.material3.HorizontalDivider | ||
| 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.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.style.TextOverflow | ||
| import androidx.compose.ui.unit.dp | ||
| import com.woocommerce.android.R | ||
|
|
||
| @Composable | ||
| fun SingleChoiceFilterPage( | ||
| items: List<BookingFilterListItem>, | ||
| selectedValue: String?, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| LazyColumn(modifier = modifier) { | ||
| items(items) { item -> | ||
| SingleChoiceRow( | ||
| text = stringResource(item.title), | ||
| selected = item.value == selectedValue, | ||
| onClick = { item.onClick() } | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun SingleChoiceRow( | ||
| text: String, | ||
| selected: Boolean, | ||
| onClick: () -> Unit, | ||
| ) { | ||
| Column(modifier = Modifier.fillMaxWidth()) { | ||
| Row( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .defaultMinSize(minHeight = 64.dp) | ||
| .clickable(onClick = onClick) | ||
| .padding(horizontal = 16.dp), | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| Text( | ||
| text = text, | ||
| style = MaterialTheme.typography.titleMedium, | ||
| overflow = TextOverflow.Ellipsis, | ||
| modifier = Modifier.weight(1f) | ||
| ) | ||
| if (selected) { | ||
| Icon( | ||
| painter = painterResource(id = R.drawable.ic_done_secondary), | ||
| contentDescription = null, | ||
| modifier = Modifier.size(26.dp), | ||
| tint = MaterialTheme.colorScheme.primary | ||
| ) | ||
| } | ||
| } | ||
| HorizontalDivider(thickness = 0.5.dp) | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
.../src/main/kotlin/com/woocommerce/android/ui/bookings/filter/type/BookingTypeFilterPage.kt
This file contains hidden or 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,12 @@ | ||
| package com.woocommerce.android.ui.bookings.filter.type | ||
|
|
||
| import androidx.compose.runtime.Composable | ||
| import com.woocommerce.android.ui.bookings.filter.SingleChoiceFilterPage | ||
|
|
||
| @Composable | ||
| fun BookingTypeFilterPage(state: BookingTypeFilterUiState) { | ||
| SingleChoiceFilterPage( | ||
| items = state.items, | ||
| selectedValue = state.selectedType.filterValue, | ||
| ) | ||
| } |
51 changes: 51 additions & 0 deletions
51
...c/main/kotlin/com/woocommerce/android/ui/bookings/filter/type/BookingTypeFilterUiState.kt
|
Contributor
Author
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. I tried to use a structure similar to |
This file contains hidden or 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,51 @@ | ||
| package com.woocommerce.android.ui.bookings.filter.type | ||
|
|
||
| import androidx.annotation.StringRes | ||
| import com.woocommerce.android.R | ||
| import com.woocommerce.android.ui.bookings.filter.BookingFilterListItem | ||
|
|
||
| sealed interface BookingFilterType { | ||
| data object Any : BookingFilterType | ||
| data object Service : BookingFilterType | ||
| data object Event : BookingFilterType | ||
| } | ||
|
|
||
| data class BookingTypeFilterUiState( | ||
| val selectedType: BookingFilterType = BookingFilterType.Any, | ||
| val onTypeSelected: (BookingFilterType) -> Unit = {}, | ||
| ) { | ||
| val items: List<BookingFilterListItem> = availableBookingTypes().map { type -> | ||
| BookingFilterListItem( | ||
| title = type.titleRes, | ||
| value = type.filterValue, | ||
| onClick = { onTypeSelected(type) } | ||
| ) | ||
| } | ||
|
|
||
| val BookingFilterType.titleRes: Int | ||
| @StringRes get() = when (this) { | ||
| BookingFilterType.Any -> R.string.bookings_filter_default | ||
| BookingFilterType.Service -> R.string.bookings_filter_type_service | ||
| BookingFilterType.Event -> R.string.bookings_filter_type_event | ||
| } | ||
|
|
||
| private fun availableBookingTypes(): List<BookingFilterType> = listOf( | ||
| BookingFilterType.Any, | ||
| BookingFilterType.Service, | ||
| BookingFilterType.Event, | ||
| ) | ||
| } | ||
|
|
||
| val BookingFilterType.filterValue: String? | ||
| // TODO Update this with actual endpoint values | ||
| get() = when (this) { | ||
| BookingFilterType.Service -> "service" | ||
| BookingFilterType.Event -> "event" | ||
| BookingFilterType.Any -> null | ||
| } | ||
|
|
||
| // TODO After refactoring navigation for the filter screens, replace this with a ViewModel-backed UI state. | ||
| val DUMMY_BOOKING_TYPE_FILTER_UI_STATE = BookingTypeFilterUiState( | ||
| selectedType = BookingFilterType.Any, | ||
| onTypeSelected = {} | ||
| ) |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I extracted this from
BookingFilterListUiStateto make it reusable across all screens, not just the root page.