-
Notifications
You must be signed in to change notification settings - Fork 133
[WOOMOB-1400] - Observe booking object from DB on the details screen #14682
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5230f5a
Expose function to observe booking from DB
AdamGrzybkowski 221c2b6
Add observeBooking function to BookingRepository
AdamGrzybkowski 16f6336
Observe booking in the ViewModel
AdamGrzybkowski 6bd0c81
Create BookingMapper class to map to ui models
AdamGrzybkowski ddc5ed9
Map Booking object to the UI models in ViewModel
AdamGrzybkowski 13614a8
Add tests for BookingMapper
AdamGrzybkowski b43c1fd
Use the BookingMapper in the BookingListViewModel
AdamGrzybkowski c33ad87
Add tests for the BookingDetailsViewModel
AdamGrzybkowski 4533d98
Introduce BookingUiState object to wrap all ui models
AdamGrzybkowski 509794d
Set orderId in BookingDetailsViewModel state
AdamGrzybkowski b168757
Update the code so that the DB is not observed when app in background
AdamGrzybkowski acb05f5
Merge remote-tracking branch 'origin/trunk' into issue/WOOMOB-1400_ob…
AdamGrzybkowski 2df6a27
Use FormatStyle.FULL instead of hardcoded date format
AdamGrzybkowski 152b266
Rename Booking.toUiModel to toListItem
AdamGrzybkowski 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
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/bookings/BookingMapper.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,69 @@ | ||
package com.woocommerce.android.ui.bookings | ||
|
||
import com.woocommerce.android.ui.bookings.compose.BookingAppointmentDetailsModel | ||
import com.woocommerce.android.ui.bookings.compose.BookingAttendanceStatus | ||
import com.woocommerce.android.ui.bookings.compose.BookingStatus | ||
import com.woocommerce.android.ui.bookings.compose.BookingSummaryModel | ||
import com.woocommerce.android.ui.bookings.list.BookingListItem | ||
import com.woocommerce.android.util.CurrencyFormatter | ||
import org.wordpress.android.fluxc.persistence.entity.BookingEntity | ||
import java.time.Duration | ||
import java.time.ZoneOffset | ||
import java.time.format.DateTimeFormatter | ||
import java.time.format.FormatStyle | ||
import javax.inject.Inject | ||
|
||
class BookingMapper @Inject constructor( | ||
private val currencyFormatter: CurrencyFormatter, | ||
) { | ||
private val summaryDateFormatter: DateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime( | ||
FormatStyle.MEDIUM, | ||
FormatStyle.SHORT | ||
).withZone(ZoneOffset.UTC) | ||
|
||
private val detailsDateFormatter: DateTimeFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL) | ||
.withZone(ZoneOffset.UTC) | ||
private val timeRangeFormatter: DateTimeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT) | ||
.withZone(ZoneOffset.UTC) | ||
|
||
fun Booking.toBookingSummaryModel(): BookingSummaryModel { | ||
return BookingSummaryModel( | ||
date = summaryDateFormatter.format(start), | ||
// TODO replace mocked values when product and customer data are available | ||
name = "Women’s Haircut", | ||
customerName = "Margarita Nikolaevna", | ||
attendanceStatus = BookingAttendanceStatus.BOOKED, | ||
status = status.toUiModel() | ||
) | ||
} | ||
|
||
fun Booking.toListItem(): BookingListItem { | ||
return BookingListItem( | ||
id = id.value, | ||
summary = toBookingSummaryModel() | ||
) | ||
} | ||
|
||
fun Booking.toAppointmentDetailsModel(): BookingAppointmentDetailsModel { | ||
val durationMinutes = Duration.between(start, end).toMinutes() | ||
return BookingAppointmentDetailsModel( | ||
date = detailsDateFormatter.format(start), | ||
time = "${timeRangeFormatter.format(start)} - ${timeRangeFormatter.format(end)}", | ||
// TODO replace mocked values when available from API | ||
staff = "Marianne Renoir", | ||
location = "238 Willow Creek Drive, Montgomery AL 36109", | ||
duration = "$durationMinutes min", | ||
price = currencyFormatter.formatCurrency(cost, currency) | ||
AdamGrzybkowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
} | ||
|
||
private fun BookingEntity.Status.toUiModel(): BookingStatus = when (this) { | ||
BookingEntity.Status.Paid -> BookingStatus.Paid | ||
BookingEntity.Status.PendingConfirmation -> BookingStatus.PendingConfirmation | ||
BookingEntity.Status.Cancelled -> BookingStatus.Cancelled | ||
BookingEntity.Status.Complete -> BookingStatus.Complete | ||
BookingEntity.Status.Confirmed -> BookingStatus.Confirmed | ||
BookingEntity.Status.Unpaid -> BookingStatus.Unpaid | ||
is BookingEntity.Status.Unknown -> BookingStatus.Unknown(this.key) | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,43 +4,19 @@ import com.woocommerce.android.ui.bookings.compose.BookingAppointmentDetailsMode | |
import com.woocommerce.android.ui.bookings.compose.BookingAttendanceStatus | ||
import com.woocommerce.android.ui.bookings.compose.BookingCustomerDetailsModel | ||
import com.woocommerce.android.ui.bookings.compose.BookingPaymentDetailsModel | ||
import com.woocommerce.android.ui.bookings.compose.BookingStatus | ||
import com.woocommerce.android.ui.bookings.compose.BookingSummaryModel | ||
|
||
data class BookingDetailsViewState( | ||
val toolbarTitle: String = "", | ||
val orderId: Long = 0L, | ||
val bookingSummary: BookingSummaryModel = BookingSummaryModel( | ||
date = "05/07/2025, 11:00 AM", | ||
name = "Women’s Haircut", | ||
customerName = "Margarita Nikolaevna", | ||
attendanceStatus = BookingAttendanceStatus.NO_SHOW, | ||
status = BookingStatus.Paid | ||
), | ||
val bookingsAppointmentDetails: BookingAppointmentDetailsModel = BookingAppointmentDetailsModel( | ||
date = "Monday, 05 July 2025", | ||
time = "11:00 am - 12:00 pm", | ||
staff = "Marianne Renoir", | ||
location = "238 Willow Creek Drive, Montgomery AL 36109", | ||
duration = "60 min", | ||
price = "$55.00" | ||
), | ||
val bookingCustomerDetails: BookingCustomerDetailsModel = BookingCustomerDetailsModel( | ||
name = "Margarita Nikolaevna", | ||
email = "margarita@example.com", | ||
phone = "+1 555-123-4567", | ||
billingAddressLines = listOf( | ||
"238 Willow Creek Drive", | ||
"Montgomery AL 36109", | ||
"United States" | ||
) | ||
), | ||
val bookingPaymentDetails: BookingPaymentDetailsModel = BookingPaymentDetailsModel( | ||
service = "$55.00", | ||
tax = "$4.50", | ||
discount = "-", | ||
total = "$59.50" | ||
), | ||
val bookingUiState: BookingUiState? = null, | ||
val onCancelBooking: () -> Unit = {}, | ||
val onAttendanceStatusSelected: (BookingAttendanceStatus) -> Unit = { _ -> } | ||
) | ||
|
||
data class BookingUiState( | ||
val bookingSummary: BookingSummaryModel, | ||
val bookingsAppointmentDetails: BookingAppointmentDetailsModel, | ||
val bookingCustomerDetails: BookingCustomerDetailsModel, | ||
val bookingPaymentDetails: BookingPaymentDetailsModel, | ||
) | ||
Comment on lines
+17
to
+22
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. All those models would be nullable after this PR, so it's handy to wrap them in a single class to avoid multiple null checks. |
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.
cc @hichamboushaba I've used the UTC based on your discussion.