‫Hello my friends.
‫In this part I will continue decoupling the UI from the main activity and the questions list activity.
‫So we have seen before that how to make this listener at least interfaces and how to implement the MVC
‫model.
‫And I will continue in this video making.
‫And the decoupling of the UI.
‫So I have stopped here in the base view MVC.
‫I was making the base observable, which is here, and let's continue making.
‫The base View MVC class.
‫This is an abstract class.
‫As I told you, I will start by making a private view m root view.
‫So remember, guys, this is the base class which provides basic common functionality to MVC views implementation.
‫Okay.
‫Private view.
‫Although and I will get I will override get the view root and despite using return null it will return
‫m root view.
‫Okay.
‫Now I will set the root view of the MVC view.
‫This is set.
‫Set root view.
‫Okay.
‫It will be protected.
‫I will I will not override this.
‫I will make, first of all, protected and then I will continue making it protected void.
‫Set root view and I will set it as view.
‫Root of you and I passed it to.
‫M root of u equal to root of u.
‫Okay.
‫And this way I have making.
‫It now.
‫A convenience convenience method for obtaining reference to a link view contains in the hierarchy of
‫the root and link view.
‫I will suppress warnings for the unchecked the context and get context and the get string methods.
‫Now I will start by making the suppress of the warning suppress annotation suppress warning unchecked.
‫And I will create a protected.
‫And they will pass.
‫Oh, sorry.
‫It will return the T extends view, so its return type would be anything that extends the view so t.
‫Find view by ID.
‫It is the method that we have created and we have seen it many times.
‫S and id.
‫So return.
‫T and M wrote a view find view by id ID.
‫Okay.
‫In this way we are making everything as an abstract protected.
‫That that context protected context.
‫Get context.
‫Okay.
‫And I will implement and import the context class and return.
‫Get root view dot get.
‫Context.
‫Okay.
‫And one last thing I need to make is to get the string protected, to make two methods of the same name
‫and to be overrided as string return type as string.
‫Get the string.
‫And it is string.
‫String class and ID and ID and ID return.
‫Get context.
‫But that string.
‫Okay.
‫And I will pass the ID in this way.
‫We have configured the get string.
‫I will need to make another one in the same way.
‫String convenience method for obtaining a string resource with format arguments protected string get
‫string and the same way annotating the string resource as an int id.
‫But we have an object here and having this 3.3 points and format.
‫Arcs.
‫Okay.
‫Return.
‫Get context dot get string and we pass the id format args.
‫Okay, so guys, I know it is a little bit confusing.
‫A huge confusing, but I promise you to to work more and more and to understand everything correctly.
‫So don't worry if you don't understand the.
‫The sum of concepts.
‫I will I will go to the questions list if you MVC questions list.
‫MVC implementation.
‫And here I need to to remove this line because I have moved it to the.
‫The same package and it will work fine now.
‫I will scroll down.
‫To hear.
‫And I will say that.
‫Make, I can remove them.
‫Okay.
‫And I need to remove the get the view also and the questions list view MVC implementation is working
‫fine.
‫Okay.
‫For now, let's go back to the questions list activity, which is the main activity for our application.
‫And let's see how, where, what is changed.
‫We have seen that the recycler view and its adapter are being cut out and we have moved them into the
‫list activity in MVC.
‫So.
‫Let's move and write to some codes that implement implements the MVC and the bind, the MVC with the
‫questions list activity, and in order to display the questions into a correctly into our app.
‫So I will implement also here the questions list, MVC View MVC, and I will call the listener.
‫Okay.
‫And this requires us to implement the methods for on questions clicked.
‫I will make it later on.
‫And here we need to implement the private questions.
‫List of you MVC called em Vue.
‫M v c.
‫Okay.
‫Remember, we removed the questions.
‫We removed the recycler view and its adapter, and we implement the interfaces and the MVC model.
‫And the last steps is to add some, some some binding of these data and these logics inside the Oncreate.
‫I need to instantiate the MVC equal to new, equal to new questions List View MVC Implementation.
‫Layout inflator.
‫And from this I will pass the.
‫Context and put here to null.
‫Okay.
‫And set content.
‫I will cut this and put it here.
‫And I will put the set content to MVC.
‫The get root of you.
‫And this way I'm telling Android to go to MVC and get all UI details from MVC.
‫Okay.
‫Well, scrolling down to Onstart underneath this.
‫This Super MVC and view MVC dot register listener because we need to register the listeners on on start
‫and on stop.
‫We need to detach and stop the the Register listener So MVC also on register listener and passing the
‫context as this the one last thing I need to make in on response.
‫So on response this is.
‫The.
‫This is the same, but I need to put here m view MVC dot bind data bind the questions, place it with
‫bind questions schema.
‫And here on failure, I don't need to make anything.
‫And the last thing to make is questions, detail activity dot start dot questions questions list activity
‫dot this and pass question dot get ID.
‫Okay.
‫And this way I have.
‫Made the MVC model and we have detached the UI from our main activity.
‫So you see, guys, our code for the main activity is more and more cleaner.
‫Let's run and see the results.
‫Okay, we have run it and we have an error.
‫So the app crashes.
‫We go to the look at and we see that there is an error in the questions list here.
‫Okay.
‫We have created a fine view by ID method and we don't need to use the container for this.
‫So I will remove them and it will work fine.
‫Let me try because I have implemented and created a view find view by ID method.
‫And here we go.
‫This is our lovely application, but if we click on.
‫On it.
‫We go to the details, activity and details activity.
‫We didn't implement the MVC for it, so I will implement it.
‫And it's very easy in the same way.
‫First.
‫I will close this.
‫And in the same way I will implement for the the details activity.
‫I will not lecture everything now.
‫I will just copy and paste.
‫So I will cut and as the same way.
‫That we have been done before.
‫So questions, details, activity and.
‫And the start the same.
‫I will create a new.
‫Package.
‫Cold details.
‫Details, questions or question, and I will move the details activity to it.
‫Refractor.
‫And I will implement here the code.
‫The question details.
‫View ABC dot listener.
‫I will create this interface now.
‫This.
‫Sorry.
‫This is an interface called question.
‫Okay.
‫I will make the video more and more faster in order to save time.
‫And here we go.
‫We have our application.
‫So if you click on any question it, it loads the layout.
‫I have missed this.
‫I need to change it in the questions detail activity to M view MVC to get root view.
‫So let me run it again and see the app, the changes and I think it is working fine.
‫So let me check again list view and we have the response.
‫So in this tutorial we have implemented and learned how to make a clean application without implementing
‫the UI directly into the main activity.
‫We have divided the main activity U into UI and networking sections.
‫The next step is decoupling the networking logic from the application.
‫But first, let me make a quick review.
‫We have implemented and created the base observable interface, abstract class and a base view MVC,
‫and we have created the observable view MVC interface, also the Questions list, the View MVC and the
‫View MVC interfaces.
‫And these are the the logic, the abstract and the inheritance of MVC model.
‫And it's very important to know them and learn about them.
‫And we later on we have a complete MVC and design pattern.
‫Course.
‫So don't worry if you don't understand where the practice.