So now I want to create a listener.
OK.
And add value event listener for the computer the unique ID so that Vendi actually data.
For example computer name or computer speed or computer screen.
When are those data actually change.
We can be notified.
Right.
So now I can say database reference.
So you already know that this database reference is actually referring to a category in the database
called computers.
Right.
And here I can say database start to hide.
So here I am referring to the height of this reference and the child is going to be unique.
Computer I.T. right.
And here I can say that add value event listener.
So as you can see here I am calling this method on the height of this database reference and that the
name of that height is unique computer ID.
So here let me actually create a new line right.
That adds value the event listener.
And inside the prentices I can see new.
And here I just need to hold the shift key on my keyboard and then place and delay the real key on my
keyboard.
And now as you can see here this is the first option that appears here.
So I just need to select it and in person it'll be on your keyboard at the end of this Prentice's as
you can see here.
After the end Prentice's here we need to actually put a semicolon here and now we have these two methods
the data changed and on canceled Meffert.
So let's go inside the update or change it here.
And now I'm going to pasting some lines of code here and then I'm going to explain to you what's going
on here.
So as you can see here these are the lines of code that I pasted here in line number two hundred and
76 as you can see here.
We have actually a value bet right and the name of this variable is computer and the data type of this
variable is of type computer class as you can see here.
And then I put an assignment operator here and here I am referring to the name of this argument data
snapshot right data snapshot that gets value.
So here let me tell you that we are actually creating an add value event listener for this unique computer
ID so this unique computer idea is actually a category right.
So when we create our listener and this category we are going to be notified when the children of this
category actually change.
Right.
So now I can see data or snapshot that gets value.
So here I can actually get the value get the object that is inside of this category unique computer
ID.
So because we all of the past we already actually sent a computer object to the server.
Now we want to get those data we want to actually get that object right.
So if we actually scroll to the top here and let's go inside the produce in your computer here as you
can see this is this McFedries produce in your computer and put it in the database.
If you look at this line of code here in line number 162 we are creating a new computer object.
Right.
And here we are actually sending these objects to the server.
Right.
This is actually the computer object that you're sending to the server.
But here inside this method let's go inside this computer change listener.
We want to actually get that object that we already sent to the server.
Right.
So first of all we need to actually create a listener for this unique computer ID and then we can be
notified about the changes of those that are inside that category.
Right.
This unique computer I.D. and here when we say Computer computer as you can see here assignment operator
data snapshot here as you can see this data snapshot argument actually has that object right.
We can actually get that object from this data snapshot here so data snapshot that gets value.
Computer class this time.
Right.
So because the data type is actually a computer class.
And now we already have this computer object.
But if any errors occur and this computer object is actually null then we are going to return from this
if it will not going to actually execute the Smurfette here anymore.
It's going to actually just break out of this if it is not going to execute the lines of code after
this if statement if the computer object is actually not so after this if statement I'm going to execute
I'm going actually pasted some lines of code here and then I'm going to explain to you what's going
on here.
So as you can see here these are lines of code that I've pasted here.
So as you can see I am referring to these three ex-teammate here.
So this the data here is actually fairly unique to this text view that is inside of these horizontal
scroll view here that we put right.
So this takes the data is actually referring to that takes a view that is inside of that horizontal
scroll view.
So if you actually scroll to the top here let me scroll to the top here as you can see we actually declared
this object here inside this class takes the data in line number 31 and it inside is uncreate Smurfette.
We actually initialized this the x 8 or so to the data and then here we cast that this object 2 and
2 are to take your object find the ID are that ID that makes the computer the top.
So this takes you is going to actually hold the data that you are going to get from the server.
Right.
So let me scroll down here.
So here I am saying that the data that said text.
And as you can see here inside the parenthesis we have these values right.
So first of all I am actually saying that instead of double quotes I am saying the computer name Kallen
I am concatenating disvalue with disvalue.
So plus computer that just computer name.
So here I am referring to this computer object.
And inside this computer class as you can see here we have these ghetto's.
Right.
So you already created these getters inside this class.
Right.
For example Gates Computer Seip you return computer Sibiu or get computer name written a computer name
just computer power little computer power and so on.
So let's go back to our main activity the double fight here.
So here I am saying that computer name call in space plus a computer that gets named.
And then here we have another plus.
So here we are concatenating these values together and here instead of double quotes we have a dash
plus computer power Colan plus computers that get power plus an inside double quotes.
We have actually Attash and yet again plus computer speed Colan plus computer that gets computers speed
plus inside it because we have dash plus computer ram Colan plus computer that gets computer RAM plus.
And instead of double quotes we have another dash and here plus computer screen Colan plus computer
that get that gets computer screen plus dash plus computer keyboard Kallen plus a computer that gets
computer keyboard plus dash plus computers colon plus computer that gets computers Sibiu.
So just put these values here.
And later when we actually do run our application it will make sense right.
So don't vote it here.
If if it if this doesn't make sense because it's it's really simple you already know about this concatenation
in Java.
So you should be familiar with this concept already.
So now let's actually go inside our uncreate Smurfette.
Now as you can see here we are actually going to scroll up here as you can see now now let me show you
the uncreate method here.
So this is our uncreate method right now I am going to go inside the curly braces of this uncreate Meffert.
So let's just scroll down here.
And here we are actually creating a listener for this PTEN send or date or update date button.
As you can see here.
So now we are going to go inside this article each method right inside the unclick method of this listener
and send or update data.
And now after these try catch blocks here.
Now I'm going to pasting some more lines of code here and then I'm going to explain to you what's going
on here.
So as you can see here these are the lines of code that I pasted here.
So here we have actually an if statement right.
And here we are taking that ief text.
So again we are using this text utility class in order to check whether this unique computer ID valuable
which is of type strange is empty or not.
Right.
If takes you to a list that is empty unique computer ID.
This means that if the value of the computer of the really unique computer ID valuable is actually empty
then this expression here evaluates to true and it's going to go inside the curly braces of this if
statement and it's going to execute these lines of code here.
Right but if the value of this unique computer ID is not empty then it's not going to actually execute
this statement.
So it is very important.
So now let's go inside the curly braces of this statement and let's see what's going on here.
So here you are saying that if the value of this unit computer ID value is empty then produce a new
computer and put it in the database.
So this Minford we are we are actually running to the Smurfit right.
So now let's actually go let's scroll down here and let's go inside this method.
As you can see this is RMF it produce in your computer and put it in the database.
The Smurfette accepts some arguments as you can see here.
Computer Name computer power computer speed computer ramp computer screen computer keyboard and computer
CPQ.
And here we have this statement and here we are saying that if the value of this unique computer ID
is actually empty then it's going to execute this line of code here a unique computer ID assignment
operator database of friends that pushed that cheat.
So it's going to actually create.
So if that computer is actually empty it's going to create a unique ID here in the database and it's
going to get that key that I.D. and is going to assign that I.D. to this computer I.D. here.
And then as you can see here we are actually creating on your computer object here by these by using
these arguments as you can see here.
And then here you are actually sent this object to this category.
So database of friends that child Junichi computer ID that sits while your computer object.
Right.
So we are saying that this is actually a category.
Why.
Because we are sending this object with these values.
Right.
For example this computer name here is going to be de-value right.
But inside this computer class you can see that we have these instance variables with these names for
example computer name.
Here is actually the key and the value that we passed to this computer name is going to be the value.
So inside this constructed we can see that you're saying that this that computer name we are saying
to this for example this instance variable assignment operator computer name which is of type string.
So inside this main activity that of it when I say database reference the child your computer ID you
are referring to this idea right.
But then I say set value computed object is going to actually pretty soon into computer ID as actually
our category and its scanner.
I actually put the value at the keys and the values of this object inside that category.
So then I when we don't add you to our project you will see how this works.
And finally we are calling the Smurfette change the text of send or update button.
According to the situation so that is going to actually change that the text of the pattern when you
for example want to send the data to the database or when we want to update the data.
So let's go back to our uncle each method here.
So produce in your computer and put it in the database.
So the Smif it actually needs some arguments right.
We need to pass some values to dismiss it.
So for the first argument we need to specify the computer name as you can see here.
Put look at this Smurfette produced in your computer and put it in a database.
The first argument is actually the computer name.
And this is of tape strength.
So we need to pass a string value.
So we already got this string value from our edited text.
As you can see here let me scroll to the top here.
Inside is Uncle Comerford in line number 96.
We created this variable which is of type string.
And we got the text of this EDT computer name as you can see here let me show you the emulator.
We got the text this EDT computer name and we converted this value to a string value.
And here we are assigning that convert value which is now a string value to this computer name.
Right.
So the champ has this computer name to dismiss it as you can see here produce in your computer and put
it in a database computer name for the second argument.
This looks at this method you produce in your computer here for the second argument we need actually
an integer value which is like computer power.
So now the value that we get from this editor is actually a string value.
Right.
So here that's why we created this try catch block here.
As you can see these structures like in say the trickiest block we are converting that string value
computer power to an integer value and we are assigning that integer value to these computer power integer
value.
And if any errors occur here in this line of code here it's going to actually catch that error here.
Right.
So now let me scroll down here.
And as you can see here for the second argument we are passing this value a computer power integer value.
And as you can see here for the first value we need to pass the computer's speed.
So again we passed the computer's speed integer value right.
For the first argument to be passed computerdom integer value.
So if you scroll to the top here as you can see here we have this try catch blocks for the computer
speed integer value and we have these structures applied for the computer integer value.
We created these variables here.
Right.
But because we need integer values here we actually got these string values here and we actually converted
them to an integer value so that we can use it so that we can use them on the Smurfette produce in your
computer and put it in a database for the for this argument computer screen.
So as you can see if you scroll to the top here we actually created this value.
But here can computer screen it it's a computer screen that takes that restraint as you can see a computer
screen here.
And we have computer keyboard and computer Seip you.
So if you pass these values to the Smurfette computer the screen computer keyboard and computer c.p.
And after we actually created a new computer here we are going to actually set the text of these as
it takes to an entire value.
OK.
We're going to actually just it is a computer that said text empty string value.
ADT computer power that said text anti-stalking value.
We don't want to.
Actually we don't want those values to be here.
Haven't we sent those data to the server.
OK.
We just want to empty it and hit the text.
So it is the computer spit that said text empty string value.
It is the computer ram that said text empty value and it's a computer screen that takes the interesting
value.
It's a computer keyboard that set this empty string value.
And finally it is the computer s.p that takes the empty string value.
So now after the end in curly brace of this if statement here I'm going to actually paste in an else
statement here.
So now let me paste it and then I'm going to explain to you what's going on here.
So as you can see here these are the lines of code that I pasted here.
We have this ELSE block here this statement.
So now let's go inside the curly braces of this L statement and let's see what's going on here.
But before that if you look at this statement.
Here we are saying that if takes you that is empty Junichi computer I-T.
This means that if this valuable unique computer ID which is of type strange is actually empty right
then it's going to actually go inside the curly braces of this statement and it's going to execute these
lines of code here.
But if this unique computer ID is not empty then it's going to actually look at this Else statement
here and it's going to execute this Else statement.
Right.
So let's look at these lines of code here.
Inside this statement here if the computer is not empty we want to update the actually the data that
we already created.
You want to update the computer object that we created and sent it to the server.
So now we want to update it modify the produced computer.
So now let me actually show you this method.
Now let me scroll down here.
So now you can see this method here.
Private Voyt modified the prettiest computer and now as you can see here we have these arguments for
this method.
And here you can see that inside the Smurfette We are checking that with all of these arguments are
empty or not.
If these arguments are actually empty then it's not going to actually execute these lines of code here.
For example if this computer name is empty then it's not going to execute this statement right.
But if these computer names for example when the user passes a value to this method and when the user
wants to update the computer name right.
If that value is empty it's not going to execute this statement.
But if that value is not empty and it is actually a real string value then it's going to actually update
that string value according to that cheat.
So let's look at this Meffert here.
So let's go here inside these are unclear methods or else modified to produce computer computer name
computer power computer speed computer and computer screen computer keyboard and computer speed.
So not is that we didn't actually pass integer values to the Smurfit because this Smurfette this scroll
down here we call this method here.
All the arguments of this method are of types think.
Right.
Because there is that I actually chose to use string arguments here is that because text utils cannot
be used on integer values.
Right.
It can only be used on this string by the user.
Right.
And that's the reason I actually chose these arguments to be of type string.
And then we could use these takes you to use here for example for this computer power here as you can
see we used this computer power string value.
But inside this statement you can see that I actually use the try catch block here and it is trouble.
As you can see here.
I converted this computer power argument which is of type string to an integer value and we actually
assigned to that initial value to these computer power integer value.
And here we are actually sending this data to the surburban we are when we want to actually update the
data in the server.
We are actually passing this computer power into value right.
So now let's scroll top to the top here.
As you can see here look at this statement.
So here we want to update the data modify the previous computer computer name computer power.
And if any of these arguments as you can see here is actually empty.
So if you look at this little scroll top to the top as you can see inside these Mefford For example
look at this line of code here.
In computer name assignment operator.
So here we want to get the string value from this computer name right and look at this value here.
We are actually saying that is 3D.
So it's going to convert this value to I think value and it's going to assign this value to this computer
name.
So are getting these values here as a string values as you can see here.
And here we are passing these values to the Smurfette locate this method modified the previous computer.
So this method only needs to the arguments of types 3.
So we directly pass these values to this Mefford computer name computer power computer speed computer
and computer screen computer keyboard and computer CPQ.
And if any of these values for example if the user passes Nuffield here if they use enters nothing here
then it's not going to actually update the computer name right.
So you can actually see that here and now.
Let's after the ending Apprentice's of this listener here.
Right.
So as you can see here we created a lesson there for this button and send all of the data.
So now as you can see here let me show you the highlighted here.
So after the 18 practices of this method again I am actually inside of these uncreate method.
Let's actually go inside these create method and now first let me tell you that for the first time that
our application runs I want the text of this button to change.
I don't want this send but takes to be here.
So let's actually scroll to the top here.
So now for example after here after this line of code here with and get data from server I can say change
the taste of scent or update button.
According to the situation.
So it's going to change the text of the spot and according to this situation and it's going to actually
for example let me ask you to hold the comments on my keyboard.
And if you are using a Windows machine you can hold the control here on your keyboard and then click
on this method here.
So as you can see here now you can see the declaration of the Smurfette and in say this mirror.
Here we are saying that if the value of this unique computer ID is actually empty if this valuable is
actually empty then it's going to execute this line of code here and it's going to set the text produced
in your computer and send it to the server.
So for the first time that you and I tried it on our application is going to actually execute this line
of what year.
But when we actually send the data to the server this computer ID is not going to be empty because in
that case this variable has a unique computer ID.
Right.
Look at this Meffert here produce in your computer and put it in the database.
Here we are checking that.
That is rowdier bill is empty or not.
If it is empty it's going to create a unique computer idea here.
Push.
And it's going to get that key that I.D. and it's going to assign it to the computer I.D..
And when this happens this unique computer idea is not empty anymore.
So that's why you can see that it's going to actually set the face of this button modify that produced
computer data.
So now let me scroll to the top here.
As you can see we call the Smurfette change the text of send or up or update button according to the
situation.
Right.
And we also called the Smurfette in say the produce on your computer Meffert let me scroll down here.
Look at this Meffert produce in your computer and put it in the database as you can see.
We also called this method at the end of this method as you can see here before the ending curly brace
of this method you can see this colleague changed the text of send or update button according to situation
situation because when we create a new object and we pass it to the database and we send it to the database
I want to change the text of the button to update to modify the produced computer.
Right.
Because in that case the computer unit's computer ID is not empty.
So when we run an app or application it will make sense.
So now again let's actually go inside this uncreate method.
So before the end in curly brace of this uncreate Meffert.
Now I'm going to actually just write some lines of code here.
So now I want to create a listener for the PTEN get data from server.
So now let me show you the emulator as you can see here we have this button right.
Get data from server.
So when I click on the spot and we want to actually get the data that we already sent to the server
and we want to put that data inside it takes you inside the horizontal scroll view so that we can actually
scroll and see the other data.
So here inside this uncreate Smurfette I can say PTEN get data from server that set unclick listener
Nijo view that unclick listener as you can see here.
So Enceladus Anklage method here I can just refer to the name of these dismember that they created here.
Let me show you the Smurfette here as you can see computer 8 or change a listener.
So this method is going to actually look at the data that we have on the server and it's going to actually
just notify us when those data change.
OK.
And then we can also get the data from the server.
So now let's actually scroll to the top here and it's going say this uncreate method.
So it is Uncle Mefford.
I can just say computer data change listener as you can see here.
I just referred to the name of that Meffert.
But what happens if the unique computer ID is actually empty.
And in that case in that moment the user clicks on the spot and get data from server.
So because in that moment we don't have any data in the server to get.
We should actually check for that condition if there are unique computer ID.
As you can see here I created an if statement and here I am saying that if unique computer ID is actually
gnarl right then in that case I don't want this line here to be executed because there is no data in
the server to get.
So if the computer ID is null and this means that the user has not actually created a computer object
and send it to the server in that case I don't want this night here to be executed.
So here I can say return.
Right so it's going to actually turn from the Smif it and it's not going to execute the lines of code.
After this written statement here.
Right.
So now.