‫Welcome back.
‫I prepared this layout to save time because it's very simple.
‫You can create by your own, or you can download the source code from the resources folder.
‫This layout contains to edit text, one for the name and one for the email and four buttons.
‫Save data, read data, update data, and delete data and one text view to display the results or the
‫responses from the firebase.
‫Let's move to the main activity and I'll initialize these widgets.
‫And by the way I'll use Findviewbyid just for saving time because in the next videos we'll use data
‫binding with Firestore.
‫Now we need to get the name and email, store them into an object of type, friend or user or whatever
‫you want, and then insert it into the firebase and perform the operations.
‫Save, delete, update and read on the Firebase Firestore cloud.
‫So for that I'll create a new model class and I'll name it as friend.
‫In this class I need to create a name and email variables.
‫I'll plus insert to create a constructor.
‫At first you need to create an empty constructor.
‫So always add an empty constructor when dealing with Firebase.
‫Then I need to create a new constructor having these two.
‫Also, I need to add the getters and setters for both name and email.
‫This is our model class.
‫Let's go to the main activity and initialize our firestore store.
‫So here under these variables and these initialization of the widgets I'll create the Firebase Firestore
‫variables.
‫We can see there is an error here because Firebase Firestore is not resolved.
‫And we can't find and resolve the symbol.
‫This is due to the absence and the lack of the dependency in the build of Gradle.
‫So here we added the Firebase Bom and analytics dependencies.
‫We need to add the dependency for Firestore.
‫For that you can search on Google latest Firestore dependency or go to the Firebase Google and to the
‫documents and scroll down to get the latest dependencies.
‫Select Java.
‫This is for the Bom for Firebase and this is for Firebase Firestore.
‫And I'll copy this note because it's very important when using the Bom.
‫This is the Bom.
‫You don't specify versions in Firebase library.
‫Dependencies sync.
‫Now if you don't use this platform and this Firebase Bom you should add here the latest dependency version
‫which is 32 .3.1 here after the Firestore like this.
‫Then we'll go to the main activity here and try to add Firebase Firestore.
‫And you can see we import it from Firebase dot Firestore.
‫Package DB equals to Firebase Firestore dot get instance I can initialize it here.
‫Or I can initialize it in the Oncreate method.
‫Then private document reference friends href equals to db dot collection.
‫And here I need to use the users or friends dot document or here I name it as users and the document
‫would be friends.
‫Again guys, you can initialize them here in the Oncreate method.
‫Also I need to add private collection reference collection reference equals db dot collection.
‫And here I need to specify the users.
‫Let's explain what we've done here.
‫The Firebase Firestore is the entry point for accessing a Firestore database.
‫You use this class to obtain references to specific documents and collections, as well as to configure
‫Firestore settings such as enabling offline data persistence or adjusting security rules.
‫The collection reference represents a specific collection within a Firebase Firestore database.
‫It's used to perform operations on the documents within that collection, such as querying, adding
‫and listening for changes.
‫Collection reference refers to the users collection within the Firestore database.
‫The document reference represents a specific document in a Firestore database.
‫It provides methods to read, write, update and delete data within that specific document.
‫So this France ref refers to the document with the ID France within the users collection.