‫Hello, my friends.
‫In this video, we will continue with the fragments and we will add the codes for the new node fragment.
‫But at first I need to solve this error only save or non null asserted calls are allowed.
‫Just click on surround with null checks and here we've added the if node doesn't equal to null, it
‫will make this steps okay now.
‫Back to the new node fragment, I will start copying and pasting the codes from the home fragment because
‫they are very similar.
‫I will copy these.
‫For variables.
‫I will remove these.
‫These codes.
‫Here.
‫And the companion object.
‫And I will paste them here.
‫I will pass our dot layout dot.
‫Dot fragment.
‫New note.
‫And here fragment new node.
‫I need to change the layout the new node I need to add the.
‫Layout tag for data binding.
‫Here I will cut it and scrolling down to here and I will add the namespaces.
‫Cut.
‫Paste.
‫Cut.
‫And paste.
‫Okay.
‫This is the fragment new node.
‫If I check here, fragment new node binding object will be appeared.
‫Okay.
‫This is what we need.
‫Set has options menu to true and I will comment it later on.
‫We will see it when we talk about the menus.
‫Oncreate view in the same way.
‫I will scroll down, I will copy these two lines and paste them here.
‫Okay.
‫Binding.
‫I need to change the fragment new node binding dot inflate.
‫And here.
‫I need to pass the inflator the container and false at the three parameters.
‫Okay.
‫This is the inflate.
‫Now, if I scroll down here, return binding route.
‫It's good.
‫I need to add the on view created function.
‫I will override it.
‫Here.
‫And I will add this closing curly braces.
‫Notes of you activity as main activity dot note view model.
‫And here I need to pass em view or the view.
‫That and view equal to view.
‫I need to create a view here.
‫So private late initiate var m view.
‫It's of type view.
‫Okay.
‫I will initialize this view as the view for the own view created method argument.
‫Okay.
‫Now I will create a new method here.
‫New function called.
‫Save note.
‫It took into the parameter the view.
‫And I want from you to concentrate now because it's different from here.
‫Save note.
‫We start by the note title.
‫Equal to binding dot no title dot text dot to string.
‫Dot three.
‫Here I am getting the data from the edit, text, the title and the body.
‫So note body equal to binding dot.
‫It.
‫Edit Text node body dot text dot two String dot trim.
‫If.
‫If the note body or the note title is.
‫Not empty.
‫We are going to check it.
‫It is not empty.
‫I am going to create a new node object passing the following equal note and I will call the constructor.
‫I will start with zero zero.
‫Don't worry, because in the entity here we created it as primary key and auto increment.
‫Here.
‫I need to add Autoincrement.
‫Or autogenerate equal to true.
‫I've missed this.
‫I need to check that zero.
‫I can put any number here.
‫I don't need to make anything.
‫Rather than passing just for zero and the system and the database will insert it according to the corresponding
‫ID, so don't worry about it.
‫The second parameter is the title, and the third parameter is the node body.
‫This is the hierarchy of our database, the ID, the title and the body.
‫Okay.
‫Here.
‫Import note from master coding application.
‫I will go up and import it.
‫Import.
‫Import calm dot.
‫Master coding dot Note taking app dot.
‫A model dot.
‫Note.
‫But the dot model dot note.
‫But the error is still because conflicting inputs.
‫I have imported this.
‫Class by by error and wrong way.
‫I need to import this class from my packages.
‫Okay, now.
‫I will start with node view modal dot, add node and pass it to the to this newly created node and I
‫will display a toast message for the user.
‫Make text
‫application dot context or I can pass this.
‫Note saved successfully.
‫And the third parameter is toast dot length long dot show.
‫Function.
‫Okay.
‫Now view dot find nav controller dot navigate because we need to go back from the node to new node fragment
‫to home fragment.
‫I need to use r.id dot new node fragment.
‫To home fragment.
‫Okay.
‫Because we're going back after adding the.
‫The node successfully.
‫Okay, so after adding the node successfully, we go from the new node fragment to home fragment.
‫Otherwise we need to use the activity dot toast or I will display the toast message here.
‫Dot make text.
‫I will pass this the message please enter note title.
‫And here I will pass toast dot length long.
‫Dot show.
‫Okay.
‫And here we go.
‫I need to override.
‫The functions for the menu.
‫So I will copy this function.
‫I will paste it here on Create Menu Options.
‫Menu.
‫Clear.
‫I will remove this.
‫From here.
‫Inflator home menu.
‫I need to make it new note menu and.
‫Here.
‫I will pass super dot on create options menu.
‫And I will remove this from here because I don't have search.
‫Okay.
‫Now.
‫I need to add one last thing from the home fragment, which is the destroy on destroy.
‫And I need to override on options item selected.
‫I need to go.
‫And make When?
‫Item here.
‫When?
‫Item.
‫Item ID.
‫I am checking the item id is it equal to r.id dot menu save?
‫Then what we will make.
‫I will make this lambda and go and execute the save note.
‫Function and I will get the view as best.
‫And here we go.
‫Don't worry for this deprecated methods.
‫Okay.
‫I need to.
‫Uncomment.
‫This has to.
‫Has option menus in order to display these menus.
‫So.
‫I need to solve the error of the make text.
‫M Viewcontext.
‫And here am viewcontext will solve the error.
‫And here we go.
‫This is the new node.