‫In this video, we are going to create the app with the MVP pattern.
‫So hello, guys, and welcome again.
‫First of all, let us organize the packages and we will separate them into util utilities and and UI
‫packages.
‫I will create a new package called UI and a new package called util.
‫I will paste my model as I refactor and move my model to util and I will make a new package called UI
‫and I will move my main activity to it.
‫Okay.
‫Sometimes Android studio will take time to to display it inside the package.
‫Okay.
‫So don't worry.
‫Okay, it's done.
‫Now, in order to implement, to create the pattern of MVP, we need the presenter, of course.
‫So I will create a new class inside the UI.
‫It's called Presenter.
‫And inside the presenter here.
‫It will acts as presenter.
‫I like to comment that some some steps in order if you if you want to the code and if you want to revise
‫the code, you can know what are the steps and why we use this, this, this class, this method.
‫So I love comment.
‫If you don't like commenting, please please tell me in the comments below.
‫So I love making the comments in order to to make sure that the ideas and everything is delivered to
‫you and you are able to understand everything.
‫Now let's link the app app.
‫Presenter I have named it as app presenter.
‫I will link the presenter with the view, which is the main activity.
‫Okay.
‫And there is an interface between the app view.
‫The interface, which is called App View, and there is a midway between the presenter and the activity.
‫It's done.
‫This midway is linked by this interface.
‫I will name it as app view, and this is the linkage between the presenter and the view.
‫As I told you, I will create a new app, a new method called Get Name app now.
‫App.
‫I'm making an instance from the the interface that we have created, so I'm linking the app.
‫Presenter with the app View.
‫Okay.
‫With this interface.
‫Remember, guys, there is a this is an interface midway between the presenter and The View.
‫So link instance, the app view.
‫The second one.
‫Is the linkage between the presenter and the model.
‫So as I told you, the presenter goes to the model and gets the data back and handle it exactly as the
‫same as the example.
‫Where you ask the waiter in the restaurant to get the water and the the presenter, which is the.
‫Waiter goes to the refrigerator and reaches the database and get the bottle, which is the model.
‫The data you need in this case.
‫So this is the linkage.
‫So we have linked the presenter with the model.
‫By get app from model A method.
‫And we have we have linked the app presenter with the interface with the view via interface called App
‫View.
‫Okay.
‫And we need now linkage between the presenter and the main activity.
‫As I told you, calling the interface.
‫Now we are going to call the interface by a new method called get app details app view dot on get app
‫name.
‫And here we put the results from.
‫The model.
‫So passing here the results from database.
‫Okay.
‫I am this this class is the presenter getting the data from model and passing it to the interface that
‫it is related to the view.
‫Okay.
‫The main activity, it's very simple and we have used the get app from Model and I need to get the app
‫name.
‫So now I need to get the app name.
‫Okay.
‫I have missed that.
‫That get app name on get app name.
‫It needs to pass parameter strings.
‫It takes parameter strings so it is solving the error.
‫Okay.
‫It's very simple.
‫And here I will like make a summary for what we are, what we have done, The View in this case, it's
‫the text view and the button, which is the main activity.
‫And where is the view?
‫Where is the the binding?
‫The binding is done with the mvvm.
‫So the view, which is the activity.
‫With a view.
‫Text The view and.
‫But.
‫The second is the model.
‫We see that it is the same as the MVC, which is my model class.
‫But here in MVC, a controller is main activity and the presenter here in the MVP, which is the presenter
‫class and it's helping interface, which is called App View.
‫Okay.
‫So it's very simple.
‫And the main activity we need to implement the app view interface, which telling that, Hey, I need
‫to connect with you, I need to connect with the interface.
‫So the interface between the app.
‫Presenter and the view is done by App View, which is an interface midway between them.
‫Okay, we are implementing it and this is the method that we are obligatory need to implement it on
‫get app name.
‫And.
‫The.
‫Instantiating the presenter.
‫App Presenter equal.
‫App.
‫Presenter This.
‫Okay.
‫It's very simple here because we are passing it.
‫Okay, Now let's solve the error here.
‫I will remove.
‫Copying it, making it well clear, and when the user clicked the button.
‫It will call the app presenter and will call the get app name, which in turn calls the modal view and
‫pass it to the interface and this interface will give it to you directly.
‫So calling the presenter to get data from database, it's very simple.
‫Now I need to set the text.
‫But but first of all, I need to tell you very important notes.
‫A calling.
‫The presenter to get data from database is done by onClick, so no linkage between activity and model
‫anymore.
‫So the activity didn't know where where to get model, where to get data.
‫It's the it's the function of the presenter.
‫Okay.
‫So the when you ask the waiter to get water, you are not not familiar from where he will get the water.
‫Where is the location of the refrigerator?
‫Where are the water are located?
‫Maybe it's not in the refrigerator.
‫Maybe it's stored in in in a in packages or whatever you want.
‫So you are not able to know where is the data.
‫You are not your own business to get the data.
‫Now.
‫Run the application and you get this and our application is working fine.
‫We have learned in this video the MVP pattern.
‫We have implemented the Model Mymodel previously and the view activity and the presenter.
‫We have created the presenter and its own helping interface.
‫Thank you guys.
‫I hope you benefit from our videos.
‫If you want us to make new tutorials and keep our Udemy channel, Udemy Course and YouTube channel alive.
‫Subscribe.
‫Rate us five stars and don't miss to download our official application Master coding.