‫Welcome back.
‫Move to main activity and start creating the variables for data binding and the view model.
‫I start with light initiate var binding.
‫It's of type activity, main binding and private light.
‫Initiate var contact view model that's of type contact ViewModel.
‫Inside the Oncreate method I'm going to use instead of Setcontentview, I'm going to use binding equals
‫to data binding util dot Setcontentview method.
‫Pass this and r dot layout dot activity main I'll initialize the room data base.
‫Start with val dao equals to contact database dot get instance.
‫And here I am passing the context which is the application context and dot user or contact Dao.
‫The second variable is the repository.
‫A repository equals to contact repository.
‫And I'm passing this Dao to it.
‫The next step is to create the view model.
‫So here the contact view model equals to view model provider.
‫And I'm going to pass two parameters.
‫The first one is this which is the owner the lifecycle owner.
‫And the second one is the factory.
‫You can create your own view model factory.
‫But for now I'm not going to use the factory in this project.
‫So I'm going to pass only this which is the owner the lifecycle owner dot get.
‫And I'm going to get the contact view model, which is a class in Java.
‫Then I'm going to use binding dot user or contact view model equals to contact view model I'm assigning
‫this variable inside the data binding called contact view model to the contact view model that I created.
‫Now binding dot lifecycle owner equals to this because I used LiveData with the data binding.
‫So lifecycle owner.
‫This property is related to live data and data binding integration.
‫It's used to define the lifecycle scoop that the live data objects should observe.
‫Live data is an observable data holder class, and tying it to a lifecycle owner, like an activity
‫or fragment, ensures that it only updates when the associated lifecycle is in an active state.
‫This helps prevent potential memory leaks, and this is the context of Android.
‫When you see this inside an activity or fragment, it refers to the instance of that activity or fragment.
‫And under this I'm going to call a method that I'm going to create.
‫Now it's called initiate recycler view Alt+ enter to create this function.
‫And here I'm going to start with binding dot recycler view dot layout manager equals to Linear Layout
‫Manager and pass this as the context.
‫Also I'm going to uh call a function display users list.
‫And I talked about this layout manager in the previous videos.
‫And using the recycler view with data binding display users list create this function.
‫And here I'm going to use contact view model dot context dot observe.
‫Since I'm going and I use the observable interface, I'm going to observe any change in the view model.
‫And here I'm going to use binding dot recycler view dot adapter equals to an instance of the class of
‫a recycler view adapter that we're going to create in the next video.