‫Hello, my friends, and welcome back.
‫In the previous videos we created the instance retrofit instance, the data classes and the API service
‫interface.
‫Now let's combine these three parts together in order to get a retrofit response in a professional way.
‫For that, I will create a Val retrofit service.
‫I will initialize it as retrofit.
‫Retro fit instance dot get retrofit instance.
‫I will go to new line in order to make it clear.
‫And here I need to make use of create method.
‫Here I need to pass a service class.
‫You can see service of type class.
‫What is the service?
‫In our application, we told you that we have three parts the data classes, the interface and the service.
‫So album service interface is acting as the service interface, so I need to pass it here.
‫Album service class, Java.
‫So here I'm combining the album service with the with the retrofit instance.
‫Now let me create a live data object.
‫Since we need to pass and get a response from the.
‫Internet from the server.
‫I need to get the the requested data and the delivered data into live data.
‫And this live data will update the UI directly.
‫We learned about the live data before, so I will create a response.
‫Live data.
‫It's of type live data.
‫And what is the type?
‫Type T The generic of this would be of type response and passing here the albums.
‫I need to get a response.
‫Of type albums.
‫Albums.
‫You remember the albums?
‫It's an array list of our Json file equal to live data.
‫And here I need to pass the live data here.
‫This would be requesting and and representing the live data scope of response of albums.
‫Okay.
‫So I will create Val response and I will store it by retrofit service dot get albums.
‫You can see I am calling this method in order to store it inside a response variable.
‫And I need to call the function Emmett in order to emit the response.
‫So here I'm emitting this response.
‫Now.
‫I am going to make use.
‫Of the response live data dot observe.
‫And since we are going to use the live data, I'm going to observe for any change of this data.
‫So the first function, the first parameter of this function is this, which is the life cycle owner.
‫The second observe.
‫The second function parameter is the observer.
‫This is an observer and you can see if I check it it here it it would be of type response albums.
‫Okay.
‫Van Album Albums list.
‫Equal to it.
‫Dot body.
‫I need this.
‫Response albums so dot body.
‫Dot list.
‫Iterator.
‫Now I need to check if the albums list is not equal to null.
‫Then I need to loop through all the elements of this albums list, which is a mutable list.
‫Dot has next.
‫What I need to do.
‫I need to create every time a valuable albums item or album item equal to albums list dot next and I
‫need to log this in the logs tag.
‫And here I need to get albums.
‫Item Dot.
‫You can see that we have succeeded in getting the album item, which is the album item here.
‫Tag.
‫Type and I can get the ID, I can get the user ID or the title.
‫Okay, Now let's run our application and see if the response and the titles of all the albums are getting
‫into the logcat.
‫So let me open the Jason.
‫Placeholder.
‫Type ID code that come.
‫And here I need to search for tag.
‫Now waiting for the application.
‫Since it's logging, I need to check info.
‫Okay, so I represents info.
‫I need to check it now.
‫Waiting for the application and let's see if it will parse the titles of these 100.
‫Albums.
‫And here we go.
‫Let me go up and you can see that the first title here.
‫Corresponds to this value.
‫The second title is this.
‫The third title is This and so one.
‫So congratulations, guys.
‫We have succeeded in creating this application that gets the response from the server and transform
‫it into logs.
‫In the next video, we are going to display these logs into text views in our application.