In Open Event Orga App (Github Repo), we allow the option to check the attendee details before checking him/her in or out. Originally, a dialog was shown showing the attendee details, which did not contain much information about the attendee, ticket or the order. The disadvantage of such design was also that it was tied to only one view. We couldn’t show the check in dialog elsewhere in the app, like during QR scanning. So we had to switch back to the attendee view for showing the check in dialog. We decided to create a usable detached component in the form of a bottom sheet containing all required information. This blog will outline the procedure we employed to design the bottom sheet UI.
The attendee check in dialog looked like this:
So, first we decide what we need to show on the check in bottom sheet:
- Attendee Name
- Attendee Email
- Attendee Check In Status
- Order Status ( Completed, Pending, etc )
- TIcket Type ( Free, Paid, Donation )
- Ticket Price
- Order Date
- Invoice Number
- Order ‘Paid Via’
As we are using Android Data Binding in our layout, we’ll start by including the variables required in the layout. Besides the obvious attendee variable, we need presenter instance to handle the check in and check out of the attendee and DateUtils class to parse the order date. Additionally, to handle the visibility of views, we need to include the View class too
<data>
<import type="org.fossasia.openevent.app.utils.DateUtils" />
<import type="android.view.View" />
<variable
name="presenter"
type="org.fossasia.openevent.app.event.checkin.contract.IAttendeeCheckInPresenter" />
<variable
name="checkinAttendee"
type="org.fossasia.openevent.app.data.models.Attendee" />
</data>
Then, we make the root layout to be CoordinatorLayout and add a NestedScrollView inside it, which contains a vertical linear layout in it. This vertical linear layout will contain our fields.
Note: For brevity, I’ll skip most of the layout attributes from the blog and only show the ones that correspond to the text
Firstly, we show the attendee name:
<TextView
style="@style/TextAppearance.AppCompat.Headline"
android:text='@{attendee.firstName + " " + attendee.lastName }'
tools:text="Name" />
The perks of using data binding can be seen here, as we are using string concatenation in layout itself. Furthermore, data binding also handles null checks for us if we add a question mark at the end of the variable name ( attendee.firstName? ).
But our server ensures that both these fields are not null, so we skip that part.
Next up, we display the attendee email
<TextView
android:text="@{ checkinAttendee.email }"
tools:text="xyz@example.com" />
And then the check in status of the attendee
<TextView
android:text="@{ checkinAttendee.checkedIn ? @string/checked_in : @string/checked_out }"
android:textColor="@{ checkinAttendee.checkedIn ? @color/light_green_500 : @color/red_500 }"
tools:text="CHECKED IN" />
Notice that we dynamically change the color and text based on the check in status of the attendee
Now we begin showing the fields with icons to their left. You can use Compound Drawable to achieve this effect, but we use vector drawables which are incompatible with compound drawables on older versions of Android, so we use a horizontal LinearLayout instead.
The first field is the order status denoting if the order is completed or in transient state
<LinearLayout android:orientation="horizontal">
<ImageView app:srcCompat="@drawable/ic_transfer" />
<TextView android:text="@{ checkinAttendee.order.status }" />
</LinearLayout>
Now, again for keeping the snippets relevant, I’ll skip the icon portion and only show the text binding from now on.
Next, we include the type of ticket attendee has. There are 3 types of ticket supported in Open Event API – free, paid, donation
<TextView
android:text="@{ checkinAttendee.ticket.type }" />
Next, we want to show the price of the ticket, but only when the ticket is of paid type.
I’ll include the previously omitted LinearLayout part in this snippet because it is the view we control to hide or show the field
<LinearLayout
android:visibility='@{ checkinAttendee.ticket.type.equalsIgnoreCase("paid") ? View.VISIBLE : View.GONE }'>
<ImageView app:srcCompat="@drawable/ic_coin" />
<TextView
android:text='@{ "$" + checkinAttendee.ticket.price }'
tools:text="3.78" />
</LinearLayout>
As you can see, we are showing this layout only if the ticket type equals paid
The next part is about showing the date on which the order took place
<TextView
android:text="@{ DateUtils.formatDateWithDefault(DateUtils.FORMAT_DAY_COMPLETE, checkinAttendee.order.completedAt) }" />
Here we are using internal DateUtils method to format the date into complete date time from the ISO 8601 standard date present in the order object
Now, we show the invoice number of the order
<TextView
android:text="@{ checkinAttendee.order.invoiceNumber }" />
Lastly, we want to show how the ticket was paid for via
<LinearLayout
android:visibility='@{ checkinAttendee.order.paidVia.equalsIgnoreCase("free") ? View.GONE : View.VISIBLE }'>
<ImageView app:srcCompat="@drawable/ic_ray" />
<TextView android:text="@{ checkinAttendee.order.paidVia }" />
</LinearLayout>
Notice that here too we are controlling the visibility of the layout container and only showing it if the ticket type is paid
This ends our vertical linear layout showing the fields about attendee detail. Now, we add a floating action button to toggle the check in status of attendee
<FrameLayout
android:layout_gravity="top|end">
<android.support.design.widget.FloatingActionButton
android:layout_gravity="center"
android:onClick="@{() -> presenter.toggleCheckIn() }"
app:backgroundTint="@{ checkinAttendee.checkedIn ? @color/red_500 : @color/light_green_500 }"
app:srcCompat="@{ checkinAttendee.checkedIn ? @drawable/ic_checkout : @drawable/ic_checkin }"
app:tint="@android:color/white" />
<ProgressBar
android:layout_gravity="center" />
</FrameLayout>
We have used a FrameLayout to wrap a FAB and progress bar together in top end of the bottom sheet. The progress bar shows the indeterminate progress of the toggling of attendee status. And you can see the click binder on FAB triggering the presenter method toggleCheckIn() and how the background color and icon change according to the check in status of the attendee.
This wraps up our layout design. Now we just have to create a BottomSheetDialogFragment, inflate this layout in it and bind the attendee variable and we are all set. The result with all fields visible looks like this:
To learn more about bottom sheet and android data binding, please refer to these links:
You must be logged in to post a comment.