In the Open Event Android App until now we were just showing a list of events from the server randomly. This does not makes sense because users are interested in events near them. So it was decided to show events according to a given location in the app. Let’s see how we achieved this.
The API endpoint which we are using looks something like this
This endpoint will return all the events that are happening in India. You can try to copy the above URL in your browser and see the output yourself.
This function is used to return a list of events which are happening in the location specified by the user. It also saves these events in the local database of the app.
The following piece of code gets called when the user clicks on the submit button in the soft keyboard. If the query is not empty then we store the value of the location in a variable and use it to load events according to location.
We are using a function named loadLocationEvents() above. Let’s have a look what this function is doing. We are using the location name that the user provides in a constant called query then we are sending a GET request to the server to get all events that are happening in that location name. All these networking request are happening in a background thread. As soon as we start the network operation we set the value of progress to true, this will show the progress bar to the user and as soon as the network request has been completed we remove the progress bar.
That’s it. We can now enter a name of the location and we will get a list of all the events that happening there
- ReactiveX official documentation : http://reactivex.io/
- Vogella RxJava 2 – Tutorial : http://www.vogella.com/tutorials/RxJava/article.html
- Androidhive RxJava Tutorial : https://www.androidhive.info/RxJava/