‫Welcome back.
‫We succeeded in adding the Firebase authentication system to our application.
‫Now the user is able to create an account and log in.
‫After a successful login the user will be directed to the journal list activity.
‫So in this video we'll start adding and using the Storage and Firestore services in Firebase.
‫So we're going to get all the journals or the posts from the Firebase Firestore and the storage into
‫our application.
‫And display them here in a recycler view in our Activity Journal list.
‫So I'll create a recycler view here.
‫It's very simple.
‫Its ID is recycler view with zero height zero.
‫And in further constraints for the parent click on it and click on this button.
‫I'll add margin ADP.
‫And here we go.
‫This is our layout for the journal list.
‫Now I need an add an adapter for this recycler view.
‫So I create a new Java class.
‫I'll name it as my adapter.
‫This adapter will extend the from recycler view dot adapter and I need to pass the VH which is the Viewholder
‫again.
‫Guys, if you have any doubt any question, please list it in the Q&A section or refer to the Recycler
‫View section.
‫And by the way, we built around 7 or 8 apps in the previous sections that uses the recycler view.
‫So please refer to the Recycler View section and the previous sections in order to learn more about
‫Recycler View.
‫But I'll make a quick recap and a quick overview and quick explanations about the methods and things
‫that we use in the recycler view.
‫The first step is to extend from Recycler View Adapter, and here don't pass anything until you create
‫the class Viewholder.
‫Here I'll start by creating the second step, which is the Viewholder public class.
‫My Viewholder extends from Recycler view dot Viewholder.
‫You can see it, and when you create like this class, I need to pass the parameter here.
‫So my adapter the class name dot my Viewholder.
‫I need to pass a Viewholder type parameter here in the generics for the adapter.
‫So I'm telling that we're going to use a viewholder of.
‫Type this my Viewholder class that will use custom views, and inside it we need to initialize the widgets.
‫Then in the constructor Alt+ enter to create constructor matching super.
‫I'll start initializing this title.
‫And the thoughts and date added.
‫And these variables that we create and these variables refers to the views thoughts equals to item view
‫findviewbyid or.id dot thoughts.
‫And here for the share button I'll set on Click Listener.
‫And I'll use Lambda hover here and replace with lambda.
‫This refers for the onclick method.
‫So here sharing the post.
‫Then this is our Viewholder class.
‫We need to initialize some variables private context and private.
‫List of journal modal class called journal list alt plus.
‫Enter to import the list and the context.
‫And by the way, we're going to use the context because we're going to use it with the glide library.
‫And I need to pass a context object.
‫And here in the my adapter class we don't have a context.
‫I need to use the constructor to have the context passed for this class, and I'll use this context
‫pass later on for the image display with the glide library.
‫And when using the RecyclerView adapter, we need to implement methods Alt+ enter to implement the methods.
‫The three methods on create Viewholder on bind, Viewholder and dot get item count.
‫And by the way, I talked about these methods in deep details in the previous lessons and the RecyclerView
‫section.
‫But don't worry, I'll give an overview about these methods on create Viewholder.
‫This method is responsible for creating a new Viewholder instance.
‫A Viewholder is an object that holds references to the views and that make up an individual item.
‫In the recycler view list, it's called when the recycler view needs to create a new Viewholder for
‫a new item that needs to be displayed on the screen on Viewholder method.
‫Inflates layout for an item view, and returns a new Viewholder that holds references to the views within
‫the layout.
‫Typically, you would inflate a layout XML file representing the item view and pass it to the view holder
‫constructor.
‫So here I start by the view view equals to layout inflator.
‫And here we need to get from context.
‫This is the we use the context object here with the layout inflator.
‫And later on we'll use it with the glide library dot inflate.
‫And here I need to pass our layout dot journal row view group or the parent and the false.
‫Then return a new view holder and pass the view.
‫So this is the layout inflator that it is responsible for displaying the custom XML layouts.
‫And this is the layout that we need to display for every item in the recycler view.
‫This is the view group and attached to route equals to false.
‫Recycler view will take the job to attach to the parent route.
‫Unbind the view holder.
‫This method is called when the recycler view wants to bind data to a view holder.
‫Specifically to populate the item views with the data for a particular position in the data set, it
‫receives two parameters the view holder to bind data at to, and the position of the data item in the
‫data set.
‫You can use this method to set the data from your data set to the views within the view holder, so
‫I'll use it to create a journal here.
‫Journal or current journal equals to journal list dot.
‫Get the position to get the current position of the current journal.
‫Then I need to set the title the thoughts name, image, URL, timestamp, and the image.
‫So for that I start with the title set text the current journal dot get title holder dot thoughts,
‫dot set text current journal dot get thoughts holder dot name dot set text.
‫And here we need to get other variables.
‫We need to display an image.
‫So image URL equals to journal or current journal dot get image URL.
‫Then we need to get the timestamp.
‫So time ago is a variable of type string.
‫I need to cast it to a string and get the date utils dot get relative time string journal current journal
‫dot get time added dot get seconds times 1000.
‫And here I need to change it to get relative time span string.
‫And here the starting time.
‫This will calculate the difference from the current date and the time that the post is added.
‫So you can see time ago about five minutes.
‫So this post is added five minutes before the current time.
‫So set the holder to date.
‫Added dot set text to time ago.
‫Then I need to use the glide library to display the image glide library dot width.
‫And here we need to pass the context object dot load.
‫I need to load the image URL that I get it from the journal, the current journal, and where I need
‫to add it or display it, we need to display it into holder dot image which is an object of type image
‫view.
‫Then I need to use fit center, which is a method that fits this image to the center of the holder.
‫Dot image view.
‫Let's go down to get item count.
‫And here we need to return the count of the list.
‫This method returns the total number of items in your data set.
‫It helps the recycler view to determine how many items it needs to display.
‫So in this video we succeeded in creating our custom adapter for the recycler view.