It is important to show the user the ticket details before he makes the payment so that he is aware how much does each ticket costs. Let’s see how this is being done in the Open Event Android App.
This function will query the database with a list of ids and return the tickets with the matching ids.
To use the above function we first need the ids of the tickets that needs to be shown so we loop through the ticketIdAndQty variable and everytime the quantity is greater than 0 we add the id of the ticket to the array list.
The next step is to call getTicketsWithIds function in a background thread because it is a database operation and we don’t make calls to the database in the main thread. If the call to the database is successful we store the list of tickets in a variable otherwise an error message is shown to the user.
To display the values to the user we just have to use the ticket variable and use its various fields but subtotal is not present in the variable so we have to calculate it. We just multiply the price of the ticket with its quantity. So we pass the adapter position in the qty array to get the quantity of the current ticket and multiply it with the price.
Ticket details are only shown if the user clicks on the textview which says view so we adjust the visibility of the ticket details in this simple if else statements and also update the textview value accordingly.
- Room official documentation :https://developer.android.com/topic/libraries/architecture/room
- Vogella RxJava 2 – Tutorial : http://www.vogella.com/tutorials/RxJava/article.html
- Androidhive RxJava Tutorial : https://www.androidhive.info/RxJava/