‫Well, hello, my friends, and welcome to the last.
‫Part of this application, which is the view of the main activity.
‫Let me go to the activity underscore main.
‫Layout.
‫Add the layout tags in order to use the binding.
‫Data binding library.
‫Here I will paste it and I will cut these namespaces from here to here.
‫Okay, now back to the main activity.
‫I will create late initiate var binding.
‫It's of type activity main binding.
‫And this is the node ViewModel that we've created before.
‫Now I will remove the setcontentview binding.
‫Equal to activity.
‫Main binding dot inflate dot.
‫I will pass the layout.
‫Inflator set.
‫Content view to binding the root and set support action bar to binding.
‫Dot tool bar.
‫I didn't add the toolbar so I can skip it.
‫Set up view mode.
‫I will create this function.
‫Here.
‫Set up the view model.
‫Val Node Repository.
‫As I told you, we start linking things together, so I need to connect the repository with the view
‫model and the view model with the view.
‫So node repository equal to node repository.
‫And I will pass the node database.
‫And I will pass this context.
‫Okay.
‫You can see how I'm creating the repository and passing the node database.
‫Now.
‫I will create Val ViewModel provider.
‫Factory.
‫Equal because I don't need to create a view model instance directly.
‫I need to connect it through the factory so I can't use the node view directly.
‫I need to connect it with the node view.
‫A model factory.
‫Model.
‫Provider factory.
‫Okay.
‫So it's equal to not ViewModel factory and I will pass the application and.
‫And the note repository.
‫Okay.
‫You can see how I am linking the ViewModel factory with the repository and with the database.
‫Okay.
‫Note Repository.
‫Separate expressions.
‫Here.
‫If I delete this, maybe.
‫Good.
‫Okay, now I will create the last thing, which is the view model.
‫Note view model equal to view model provider.
‫I am connecting the view model with the view model provider factory.
‫Here.
‫By making this.
‫ViewModel provider factory.
‫And here we go.
‫This is the the linkage between the ViewModel and the ViewModel factory dot get.
‫Note ViewModel and its type class.
‫Dot, Jeff.
‫Here we go.
‫This is our main activity.
‫It's very simple.
‫It retains the view binding and data binding here and setting up the view model.
‫I am creating a view model factory.
‫I am connecting it with the repository which in turns connect with the database.
‫And since I don't need to connect and I can't connect with the ViewModel directly, I need to connect
‫this view model with the view model provider.
‫Here we go.
‫This is our application.
‫Now let's.