This tutorial will cover the first app we create in that course. The app is an offline-first CRUD app with Search and Pagination capability. In the app the user can add a scientist with his details to the database, fetch them, update them, delete them. The user can also search against already existing Scientists. The data when being read is paginated, making the app efficient. Pagination is taking place at the Firebase level.

The app has several screens/pages:

No.

Page/Screen

Type

Role

1.

Splash Screen

Activity

Use it to display your brand

2.

Dashboard Screen

Activity

Use it as the center or your app .

3.

CRUD Screen

Activity

Used for posting new data, updating and deleting data

4.

Listing Sceen

Activity

Used for hosting our Fragments

5.

LatestFragment

Fragment

Used for showing the last seven added items. This data is read primarily for our local cache.

6.

ListingsFragment

Fragment

Used for showing all items in our Firebase realtime database. However the data is paginated, with each page containing seven items or any number you want.

7.

SearchFragment

DialogFragment

Is our search dialog. First search is performed locally, then if no match is found we connect to Firebase and search there.

/data/model/entity/Scientist.java

This class will represent a single Scientit. It is our model class is therefore basically a java bean. It will define the properties of our scientist like name, description, galaxy, star , date of birth and death of death.

The key property will be autogenerated by Firebase realtime database.

We will make this class implement serializable interface. This will allow us to easily pass it across activities.

DB in this case is our Firebase realtime database reference. You can see we’ve specified the node where our data will be held using the child() method. Then we’ve added a value event listener and overidden two methods:

onDataChange() – SUCCESS

onFailure() – FAILURE

As we said we are returning a MutableLiveData object regardless of the success or failure. After all our RequestCall object which is the generic parameter of our RequestCall accomodates success, failure as well as progress. Thus observers will check for whether the current state is progress, failure or success and react accordingly.

Share Article:

Tags:

When I was a 2nd year Software Engineering student, I buillt a now defunct online tool called Camposha(from Campus Share) using my then favorite language C#(ASP.NET) to compete OLX in my country(Kenya). The idea was to target campus students in Kenya. I got a few hundred signups but competing OLX proved too daunting. I decided to focus on my studies, learning other languages like Java,Python,Kotlin etc while meanwhile publishing tutorials at my YouTube Channel ProgrammingWizards TV which led to this site(camposha.info). Say hello or post me a suggestion: oclemmi@gmail.com .
Follow me below;
Github
, and on my channel:
ProgrammingWizards TV