‫The second step is to read all documents in the collection.
‫Let's create a new method here.
‫I'll name it as get all documents in collection and I'll use collection reference dot, get dot, add
‫Onsuccess listener and pass here on Success listener interface.
‫We override it.
‫This method on Success Collection reference represents the reference to a specific collection within
‫your Firestore database from which you want to retrieve documents, and in this case it's indicating
‫the user's collection.
‫And if you scroll up you can see the reference is.
‫User's Get method is called when we need to perform a read operation and retrieve documents from a specified
‫collection.
‫You can attach and add Onsuccess listener to the result of the get operation method.
‫This listener will be called when the data retrieval is successful.
‫The query documents snapshots contains the documents in the collection.
‫Inside the Onsuccess method of the Onsuccess listener, you receive a query snapshot.
‫The query snapshot contains the documents retrieved from the collection, as well as the metadata about
‫the query itself and as learned before in the previous sections of the Firebase, I need to query the
‫data in the snapshots.
‫We're going to use the for each loop to loop through and iterate through documents, so you can use
‫for loop to iterate through the query document.
‫Snapshot objects in the query document snapshots.
‫Each query document snapshot represents a document in a collection.
‫And you can use methods like getString, get Lang, and etcetera to access the data within each document.
‫Let's start getting and iterating through all documents in the collection.
‫So for that I'll use for query document snapshot, snapshot in the query document snapshot here.
‫Query document snapshot represent a document in a collection query document snapshot.
‫The second step is to transform snapshots into objects.
‫We get snapshot for every item in the query document snapshots, and we need to transform it into objects
‫of type friend.
‫So friend friend equals to snapshot dot to object method.
‫And here I'll specify the friend dot class.
‫And here I'm telling that for every document in the snapshot go and transform it into an object of type
‫friend.
‫I'll create outside this for loop an empty string just to display it into the text view.
‫Then for every friend I need to use this data string equals to appending the name and the email.
‫So name equals to friend dot get name plus email, friend dot get email plus a new line.
‫I'm appending in this data string every document.
‫Go and transform it into an object, and then get from this object the name and the email and display
‫it in one single line.
‫Then I need to set the text view to the retrieve data text view dot set text to data.
‫Let's run.
‫And every time I miss to call this in the button set click listener read button dot set on click listener
‫new view and click listener and call this method again.
‫Run.
‫Click on read data button and congratulations guys!
‫We get the name and the email for every object and for every document in the firestore.