 Hello everyone. So in this video, I will talk to you about the using the Firebase cloud of firestore attached to a recycler view, which is kind of the dominant way of showing data in Android apps these days showing it attached to a recycler view. It gives you a lot of flexibility in how you present the contents of your data. So this video was recorded a while back. Everything is still relevant. The code looks the same. The lessons are the same. You may see some cosmetic differences in Android Studio and in the Firebase console. One big difference you will notice is I work within the Firebase example project, which is linked both in the lab that's attached to this video and in the video description on YouTube down below. It looks a little bit different. Let me bring up the emulator so you can see. So if you have checked out the Firebase example project, which you should have and you're playing with the code in there. So again, the code is going to be the same as you will see in the video, but the screen is going to look a little bit different. I have some old buttons, old styled buttons in the video you're about to see, but we're going to be working in this area here in the firestore plus recycler view. Okay, so that's it. Everything else is still relevant. And mainly this is an introductory video explores the code a little bit explores what the code does a little bit. But the bulk of the learning here is for you to spend time in the code and kind of playing with it and see how it compares with recycler views that you were asked to implement in the past. All right, that's it for now. And I'll switch it over to my younger self. All right, let me switch over to some code here. So I want to show you just briefly what's going on. Okay, so here we've got the Firebase example project. So in your lab for this this week, you will have a link to this Firebase example project. I encourage you to check it out after this just follow along for now. And then in your lab, you can check out this project and see the kind of code that we're working with. In the Firebase example project, I've opened up my firestore activity. Okay, so here's my emulator that's running over here. Here's the authentication example from last time. This still works if you want to try it, but I'm going to click on launch firestore activity. And so I get this example activity that comes up and it's pretty simple. All it does is you pick from a spinner, a first name and a last name. And when you click add person, it's going to save some information to the database and then display it right here. Okay, so let me let me just add Alan Turing. Okay, so what happened when I click this and let me add someone else Donald. Okay, and let me click add person. Okay, adding Donald Knuth. So what is happening here is when I click add person in my Java code, I create a person object, one of these things. And I tell the firestore to save it. And I also have a recycler view down here that is attached to my cloud firestore collection that stores people. And anytime it detects a change in the people collection, it automatically updates the recycler view. So that's pretty cool. So as I click add person, it actually is going up to the cloud firestore in the cloud, storing it in the database. And then coming back and pushing out that change here. Okay, so this recycler view is actually listening to the cloud. It's not doing anything directly in response to me clicking add person. It's listening to the cloud for changes. The other thing that I can do here is when you click on one of these cards, it will delete them. So I can delete these people and now they're all gone. All right, but let's look in this activity for just a moment. So if we look at the top, kind of here right here, I'm initializing my firebase firestore firebasefirestore.getinstance. And then down here, you can kind of see I'm hinting that I'm setting up a recycler view with the recycler adapter. We'll talk more about that in a second. But let me scroll down to the add user method. This is actually attached to add person. I probably need to rename this, but this method gets fired when you click add person. These two spinners are not attached to anything in particular, but you can see here person gets new person. First name from the first spinner, last name from the second spinner. User ID I create by taking their first name plus their last name and doing some transformation. And then getting the current date. And if we look at the person, the person is just a data object. No, it's just a plain old Java class that's holding person information. Nothing to it. Let's go back over here to this code. Here, MDB is my instance that lets me talk to the firestore. And I say for the people collection, I want to add to that collection new person. Where a person is a Java object. And that's it. That does it. I have a success listener here that logs whenever the user ID was successfully created and a failure listener if there was some error. But that's it. Firebase instance, the collection I want to talk to collection dot people. People is just a string. Let's see in a second. And that puts it up in the cloud. Let's go over to the cloud for a second. Here's my Firebase console. And click on database. All right. So here's the cloud firestore. I have a collection up here already called plants. We'll see that in the next video. There's no users here currently or no people currently here. Now watch me. Let me add grace hopper back. Okay, I need to refresh this page. Hmm. And now I have a people collection. Right. People collection is what I specified. That's where I want people to go to when I create them. So here she is. Right. She's in the people collection. There's a document. This is a unique up document identifier generated by the firestore. And then here are her fields. Created time, which is a date time stamp string first string last string user ID. Right. Let me add somebody else. Ada hopper. You may have noticed that the firestore was actually clever enough to show me that this person was added in real time. Watch over here again. Let me add another person. Okay. Watch over here. Actually updates in real time. That's pretty cool. Let me delete someone. Let me delete grace hopper over here by clicking on her. She goes away. Right. Here real time in the cloud firestore database. So that's pretty nifty. Let me go back to my code for just a second. So the the recycler view down here. This is a recycler view. Oh boy. Time to get them working. The recycler view is actually kind of set up a little bit differently than the recycler views that we studied in earlier labs. It is using a library called the firebase UI that makes it really easy to kind of connect and talk to the firestore. Right. So the thing about it that's neat is that this firebase recycler recycler options and then the person recycler adapter. They use library methods that are effectively listening to this for real time updates. So you don't have to do any real time listening. This does it for you. That's really awesome. All right. So the best way to learn about this and understand what it's doing is to kind of get in here and play around with this lab. So that's what I'm going to encourage you to do. Let me switch back over here. So let me bring myself back to you. All right. So what I want you to do is to go check out the lab called firebase cloud firestore. It links to the sample project that I showed. And yes, you will be using the firestore in your term project. Once you get into it and start using it a little bit, you'll see it's not too bad. You've got those event handling things like whenever you add something, did it succeed? Did it fail? What are you going to do? You've got that event handling stuff. But other than that, it's really not too bad. Certainly the most complicated thing about it is that recycler view. And hopefully I've given you a useful template to draw from there. All right. So next time we will talk about cloud storage, which is how you can store files like pictures in the cloud and display them in your application. Until then, have a good rest of your day.