Skip to content

Commit 5179aab

Browse files
committed
Persist Booking Type filter in DataStore
This change introduces the functionality to save and retrieve the "Booking Type" filter to and from the DataStore.
1 parent de8fc3e commit 5179aab

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/bookings/filter/data/BookingFilterRepository.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class BookingFilterRepository @Inject constructor(
2424
private val selectedSite: SelectedSite,
2525
) {
2626
// Keys are built per-site to keep selections isolated across sites
27+
private fun bookingTypeKey(siteId: Int) = stringPreferencesKey("bfilters_${siteId}_booking_type")
2728
private fun customerIdKey(siteId: Int) = longPreferencesKey("bfilters_${siteId}_customer_id")
2829
private fun customerNameKey(siteId: Int) = stringPreferencesKey("bfilters_${siteId}_customer_name")
2930
private fun dateBeforeKey(siteId: Int) = longPreferencesKey("bfilters_${siteId}_date_before")
@@ -34,6 +35,7 @@ class BookingFilterRepository @Inject constructor(
3435
val bookingFiltersFlow: Flow<BookingFilters> = siteIdFlow.flatMapLatest { siteId ->
3536
dataStore.data.map { prefs ->
3637
BookingFilters(
38+
bookingType = prefs.getBookingType(siteId),
3739
customer = prefs.getCustomerValue(siteId),
3840
dateRange = prefs.getDateRangeValue(siteId)
3941
)
@@ -43,6 +45,16 @@ class BookingFilterRepository @Inject constructor(
4345
suspend fun save(bookingFilters: BookingFilters) {
4446
val siteId = selectedSite.getSelectedSiteId()
4547
dataStore.edit { prefs ->
48+
// Booking type
49+
val bookingTypeKey = bookingTypeKey(siteId)
50+
val bookingType = bookingFilters.bookingType
51+
if (bookingType != null) {
52+
prefs[bookingTypeKey] = bookingType.value.name
53+
} else {
54+
// Clear if not provided
55+
prefs.remove(bookingTypeKey)
56+
}
57+
4658
// Customer
4759
val customerIdKey = customerIdKey(siteId)
4860
val customerNameKey = customerNameKey(siteId)
@@ -77,6 +89,12 @@ class BookingFilterRepository @Inject constructor(
7789
}
7890
}
7991

92+
private fun Preferences.getBookingType(siteId: Int): BookingsFilterOption.BookingType? {
93+
val stored = this[bookingTypeKey(siteId)] ?: return null
94+
val type = runCatching { BookingsFilterOption.BookingType.Type.valueOf(stored) }.getOrNull()
95+
return type?.let { BookingsFilterOption.BookingType(value = it) }
96+
}
97+
8098
private fun Preferences.getCustomerValue(siteId: Int): BookingsFilterOption.Customer? {
8199
val customerId = this[customerIdKey(siteId)]
82100
val customerName = this[customerNameKey(siteId)]

libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/bookings/BookingsRestClient.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ class BookingsRestClient @Inject constructor(
109109
BookingsFilterOption.TeamMember -> TODO()
110110
BookingsFilterOption.AttendanceStatus -> TODO()
111111
BookingsFilterOption.PaymentStatus -> TODO()
112-
is BookingsFilterOption.BookingType -> TODO()
112+
is BookingsFilterOption.BookingType -> {
113+
// TODO add query for booking type filtering
114+
}
115+
113116
is BookingsFilterOption.Customer -> set("customer", filter.customerId.toString())
114117

115118
BookingsFilterOption.Location -> TODO()

0 commit comments

Comments
 (0)