‫Welcome back.
‫We succeeded in creating and adding the retrofit to our application.
‫Now let's move to the next step, which is displaying the data into the app UI.
‫This app will follow the Mvvm architecture model view ViewModel.
‫We finished the remote data source section.
‫Now let's move to the repository and the repository is included inside the model section or layer.
‫So inside this model package I'll create a new Java class and I'll name it as movie repository in the
‫Mvvm model View ViewModel Architectural Pattern In Android a repository is a design pattern that acts
‫as a bridge between the view model, which is the presentation layer and the data sources such as a
‫network API for or a local database.
‫Its primary purpose is to abstract the data source details and provide a clean API for the ViewModel
‫to fetch and manage data.
‫A repository abstracts the data sources, which could include remote data from a web service like our
‫application or a local data from a database that we have done in the previous apps using the room database
‫or any other data retrieval mechanism.
‫It shields the ViewModel from the complexities of interacting directly with these sources.
‫The repository helps enforce the single source of truth principle, which means that there should be
‫a single place in your app responsible for managing and storing the data.
‫This reduces the risk of inconsistencies or errors that can arise from having multiple sources of data.
‫I need to fetch the data and store it inside an array list of movies.
‫So I'll start with private array.
‫List of movie model class.
‫I'll press enter to import it and I'll name it as movies Equal new array list.
‫And I need to create a mutable live data because I'm going to use live data in the ViewModel to fetch
‫the data and displayed in the UI.
‫And this mutable live data is of type list of movie class.
‫I'll name it as mutable live data equal to new mutable live data.
‫Please refer to the live data lesson in the previous sections to learn more about live data.
‫Live data is used to hold and observe data changes in a lifecycle aware manner within an app.
‫In Android, Mutable live data is an extension of live data class and it adds the ability to modify
‫or set its contained data.
‫So for that it's called mutable live data.
‫Not having the ability to modify mutable live data has the ability to add or modify its contained data.
‫Mutable live data ensures that the data changes are observed only when the component is in an active
‫state started or resumed, helping to prevent memory leaks and UI updates when they are not needed.
‫And unlike the regular live data which is read only once data is set, mutable live data allows you
‫to modify its stored data through the set value method and post value.
‫Then I need to create a private application instance or a context application in order to use it to
‫get the context, because I need to pass it to the popular movies here in the service API.
‫And because I need to access the resources that I'm going to add here later on.
‫Don't worry, I'll show you guys.
‫Alt plus enter to import the application.
‫Now I need to create a constructor only having the application again.
‫Guys, I am passing and creating this application order to access the resources folder later on because
‫I'm going to place the string API here inside the resources tag in the string dot XML file.
‫Again, I'll create a public method called Get Mutable Live data and it's returning type should be a
‫mutable live data.
‫And this is a getter method for this mutable live data.
‫You can create it using getters and setters or like this list of move.
‫Okay, so this method will return this and it's a getter method for this.
‫I want from you to focus with me because it's a very important method.
‫I'll start with movie API service.
‫Movie API service equal to retrofit instance dot get service in the context of retrofit and Android
‫app development, you often create a retrofit instance and use it to create service instances.
‫These service instances are interfaces that define the API endpoints and their associated Http methods
‫get and post.
‫And in our case we created and we defined only one get method.
‫You then use the service interface instances to make API requests.
‫Then I'll start by using the call class again and I need to pass the result.
‫And we talked about the call in the previous videos call, I name it as call equal to movie API service
‫dot get popular movies alt plus enter to import the class of call.
‫And here I need to get the popular movies.
‫I need to pass the string the API key.
‫So for that I'll create a string here and I'll name it API underscore key and its value.
‫My API key that I stored inside the notepad.
‫I passed the application object here in the constructor in order to use and make access to the string
‫dot XML file in the resources folder.
‫So I need to get this and I recommend to store all the strings here inside the Strings.xml.
‫You can skip and omit this application and you can define here the API you can use like this.
‫Here.
‫I'll start application dot, get application context dot get string.
‫And here I need to get r dot string dot api alt plus enter to import class r and you can see I'm accessing
‫string resource file.
‫Since I used the application and get the application again.
‫Guys, you can remove this application and pass the API key directly here.
‫But I don't prefer like this.