‫Hello, my friends, and welcome to the last part of the Mvvm architecture, which is The View.
‫We will start building our view that contains three fragments which we created before one main activity
‫and one adapter class for the recycler view.
‫I will start with the adapter class for the recycler view.
‫In this video.
‫I will create a new package.
‫I will name it as adapter.
‫And inside this adapter package, I will create a new Kotlin class.
‫I will name it as node adapter.
‫And this class I will extend it from recycler view dot adapter and into the parameter view holder.
‫And we've talked about view holders and recycler view a lot in the previous videos, so please go back
‫to the recycler view section in order to understand more and get more information about view holders
‫and recycler views.
‫Note Adapter dot, note view holder and this class I will created in the next couple of minutes.
‫Okay.
‫Or I will create it now directly in order to remove this error.
‫Note view holder and I will pass an item binding here.
‫It of note layout here.
‫What is the name of the layout?
‫Note Layout.
‫Oops.
‫I have missed to add the layout here.
‫Layout tags in order to generate a binding.
‫Object for this layout and use the data binding with it.
‫So here I pass layout and I can move these namespaces.
‫To.
‫The layout tag.
‫Okay, so here we go.
‫I will cut these two properties and paste them here.
‫Okay, so this is our note layout.
‫I will try to type note layout and you can see note layout binding.
‫Again it took into the object or generate the objects for every layout.
‫It starts with capital N capital L, and it adds the binding word for every layout in order to generate
‫a class of it.
‫Okay.
‫This will extends from recycler view.
‫Dot viewholder and took into parameter the item binding dot root.
‫Okay, so here we've created our class node viewholder.
‫Under this I will create a private val defer callback.
‫Equal to object.
‫And here I will add the fill util.
‫Don't worry, I will lecture everything now.
‫Item callback and it took into parameter the node instance.
‫Okay, let's type parameter oplus.
‫Enter.
‫To import the note item callback.
‫And here I need to add the function.
‫But what is this?
‫The purpose of using the futile that it is a utility class that can can calculate the difference between
‫two lists and output.
‫A list of update operations that converts the first list into the second one.
‫But hey, I don't understand.
‫Don't worry.
‫That sounds.
‫Complex.
‫But the main purpose in you of using the diff util class here in our application is to calculate updates
‫for a recycler view adapter and display things when we need to insert delete update the recycler view
‫items.
‫It will make these operations more and more fast and handle them smoothly.
‫So I will override our items.
‫The same function.
‫I'm checking them return old item.id equal equal to new item.id.
‫And this is the end operation operator.
‫Here the old item dot note body.
‫Equal equal to new item dot note buddy.
‫I'm checking if it is the same and if there is any existing node with the same.
‫Note title and note body.
‫Note Title equal equal to new item dot.
‫Note title.
‫Okay.
‫I'm checking if the items are the same.
‫Another function I need to override are contents the same return old item equal new item if there exists
‫inside the database an item.
‫Or inside the recycler view.
‫An item that is similar to the new one, then we will return the new one equal to the old one.
‫Okay.
‫This is the importance of using the diff.
‫And handles smoothly The insertion deletion, updating and the items in the recycler view defer equal
‫to async defer list.
‫Defer.
‫This, pass this and defer call back.
‫Why we use this differ.
‫Since we've learned before that in order to use the recyclerview, we can use the unbind viewholder
‫and the make refresh all the visible area on the recycler view redraw them, but it cannot fire the
‫recycler view animation and has many many problems inside the unbind Viewholder.
‫If you use partial refresh so I can use adapter dot notify item dot item changed.
‫Also, I am refreshing partial things on item change and item insert range changed range inserted and
‫range removed.
‫Okay, but this will give you a specific item position to refresh.
‫But here comes the problem.
‫What if you have a whole list you need to refresh?
‫Do you have to calculate all the positions you need to refresh?
‫No.
‫So we've used this diff util.
‫Utility and we're going to use the async list differ.
‫Function.
‫It will create a dphil util item, callback and async list defer to handle all the data synchronization.
‫Okay.
‫So it's very simple.
‫We are making our recycler view looks more and more professional and handle all the events in the recycler
‫view.
‫Now I will add on create viewholder.
‫Return note.
‫Viewholder.
‫And inside this Viewholder.
‫Note Layout Adapter.
‫Binding or note layout binding dot inflate.
‫I'm passing the layout inflator from parent and the context.
‫Parental context and the.
‫Parent.
‫And the third is false.
‫Okay.
‫Here I'm using note layout binding, which is the.
‫Object of this layout.
‫In the next video, we will continue with our node adapter and we will.