‫Hello, my friends.
‫In this video we will start getting old posts and display them into the journal list.
‫So here inside the journal list I will override the Onstart method and I need to get them not on Oncreate
‫method.
‫I need to get them on Onstart method.
‫Later on, I will show you why I am doing this, but please follow me now.
‫Collection reference dot where equal to I'm getting the current user ID and from the instance that we've
‫created the singleton instance, the journal user dot instance is equal to the user ID.
‫So following here the same id getting the user id.
‫Get instance.
‫And here I need to continue.
‫Get.
‫User ID or user ID.
‫Get.
‫And here from this instance, I need to get the user ID.
‫Okay.
‫And I need to use only save arguments that get and add onsuccess listener.
‫So this onsuccess listener will allow us to check if everything is working fine or not and we get all
‫the data successfully or not for that.
‫You can see that it is a query snapshot and we need to use this query snapshot so if it or doesn't equal
‫it.
‫Is empty.
‫I'm checking if it is not empty.
‫Forget a for loop and go through all the elements, all the data, all the journals and inside the square
‫snapshot and display them into a journal list.
‫So I need to get all the data here and I will display or I will store them inside the journal list.
‫Here.
‫Okay, so I'm getting all the data from query snapshot and and stored them inside the journal list.
‫So here.
‫I will remove it and I will use for each loop so it dot for each.
‫And here I'm going to check for each item inside this query snapshot I need to transform the query snapshot
‫to objects that allow us to store inside this list.
‫And this list accepts only journals.
‫So how to transform the query snapshot to a journal object?
‫But first I will let this list would be a mutable list in order to allow the to allow us to add to this
‫list data and elements.
‫So here I need to transform or convert.
‫Query or snapshots.
‫Do journal objects.
‫How to do that.
‫We will start with var journal equal to.
‫I t dot to object.
‫And here we specify what are the type of the class that I need to convert this it to it.
‫It's of type journal and this is the class now adding.
‫Adding the snapshots and the journals to the.
‫List.
‫So journal list, dot add.
‫And here I will add the journal.
‫Here we have converted the snapshots to the journal objects, and here we add them to the list.
‫Okay, so.
‫Let's continue with the recycler view.
‫So we have added that the snapshots here and we have added them to this journal list, this immutable
‫list.
‫Now we need to display the items inside this list into the recycler view.
‫So here, recycler view.
‫I will start with.
‫Adapter.
‫This is the adapter, the journal recycler adapter.
‫Equal to journal recycler adapter.
‫And here I need to pass two parameters the context and the list.
‫So journal.
‫List activity dot this.
‫Or I can pass like this context and the journal list that we have created.
‫Set adapter recycler view or binding.
‫Dot recycler view Dot set adapter.
‫The Journal.
‫Adapter.
‫And adapter dot notify data set changed.
‫Okay.
‫This is a very.
‫Quick and very amazing way to set things correctly here in the Onstart method, because when the user
‫opens the app and Oncreate method is called, then the Onstart method is called when he exit the app
‫or he go to another activity.
‫If he comes back, the Onstart method will be called and not the Oncreate method.
‫So for that we put all the codes inside the Onstart method.
‫This is if we have documents, snapshots.
‫So we have journals.
‫If we don't have journals, it's very simple.
‫We only going to display the node posts.
‫List.
‫No.
‫Post text review.
‫Set visibility.
‫To.
‫View dot visible.
‫We need to display it.
‫So visibility.
‫It took into the parameter.
‫Visibility integer.
‫Equal to view dot visible.
‫Okay.
‫Also we can add on failure.
‫Listener.
‫So on this failure listener, we can.
‫Call the exception here and we can display a toast message.
‫Make text this.
‫Oops.
‫Something.
‫Went wrong.
‫Thost dot length short and dot show.
‫So this is the journal list.
‫We have succeeded in getting all posts on the start.