Welcome back and this video, we are going to add a little icon here at the top, this hamburger icon,
and then we will open up the door and close it accordingly.
Of course, we want to have the right functionality for this.
So let's go back to our code.
And where this is going to happen is, of course, in the main activity.
So let's go ahead and go to our activities here.
The main activity currently, it's an empty activity.
It doesn't do much.
Right.
So we still need to make some changes here.
And I'd say we should start with creating the action bar.
So setting up the action bar.
So private function, set up action bar.
So I'm going to call this one.
And year we're going to do the default stuff that we need to do to use a support action bar.
So set up action bar here with our toolbar that we have.
So we created a tool bar called to Bar Main Activity.
So if you remember in our bar we had this tool bar which we created, which was the one with the main
activity.
All right.
So that is part one.
Then I would like to add an icon to this toolbar.
And in order to do so, what you can do is you can just add a navigation icon.
So here, set navigation icon and then which I can do I want to use well, our daughter drawable thought
I see action navigation menu.
Now, of course this icon doesn't exist yet, so let's create this resource.
So let's copy this and go to New Vector.
Then I can hear and you can simply search for menu.
And and give it the name that we prepared.
I see action navigation menu next and finish.
And then if you want this to bar, I can to also have a functionality, you, of course, need to add
an omelet listener.
So toolbar.
Main.
Activity that set navigation on Click Listener and what I want to execute here is to toggle the Droid,
so therefore we need to have a function which will do that.
So toggle control were all right.
So let's create one private fun toggle draw and then hear what we can check is have the draw layout.
By the way, if you look at it, it's this one here.
And the activity mean we have this draw layout, which we gave an idea which is a draw on this layout.
If that one is open so we can check here is drawer open.
And what we need to pass to is draw open is a draw gravity integer.
And here we can basically use the gravity compared Astarte.
So here gravity compared that start.
OK, so if the draw is open then I want to execute something.
All right.
So then I want to close the draw.
So draw layout.
Thought.
Clothes draw.
And here we also need to add to gravity compared start.
OK, and then otherwise open the drawer, so draw lay out that open drawer.
And here again, grow decomp Head Start.
So now he can talk all the draw once we click on the icon.
And of course, we need to call our set up action bar in our uncreate method so that any of that will
ever happen.
All right.
And then there's some other functionality that I would like to add, and that is when we pressed the
button, then the draw should also close.
All right.
So then I also want to toggle to draw, OK?
And if you want to override the on back press functionality, you can simply go ahead and say that you
want to do that.
So just implement it on that prest method with overwrite fun.
And then what I want to do here, if that happens, is I want to simply check if the draw layout is
open.
So basically what we have here, let's implement that.
But I instead want to do in the case, our double.
Back to exit.
And that is a function that we prepared in.
Our basic activity, so let's have a look inside of our basic.
Activity, right, or base activity?
So he has double back to exit, so if you want to use that in our main activity, we need to make sure
that it inherits from our base activity.
All right.
So that's what we do.
And now we can use to on or just double back to exit function.
Now, the next thing that I would like to have is a capability to click any of those icons or those
options pretty much, right.
So we have two options.
Sign out and my profile.
And for now, in our case, they won't do anything.
But in this example project, which we prepared there it is already.
So we need to add something to our main activity so that we can actually have an selected or item selected
listener.
OK, so in order to do that, we need to say navigation view dot on navigation item selected listener,
pretty long name, but if you import navigation view, it will probably help you out and it will be
a lot easier to enter this whole name.
OK, so once you do that, the main activity will ask you to implement some members.
And in this case, it just has one function on navigation item selected.
OK, so here we can now implement the functionality that should execute once we click one of those navigation
item options.
OK, so one of the navigation items, of course, is our logout function and the other one is to open
up the profile.
So here we can just go ahead and say when the menu item that is passed to us, which is in our case
called item.
So when item.
Thought item ID.
And then we have the different cases, so case number one, the item ideas are IDOT Neff, my profile.
So if you look at it and have my profile is in our activity main draw this item.
So we have prepared this menu in the last video where we had this group of items and one item was our
my profile and the other one was my sign out or the sniff sign out.
OK, so if it's in my profile for now, what we will do is we will basically just provide a little toast
here.
OK, so nothing fancy.
So toast may text and basically just say something like my profile.
Later on, of course, we want to replace this with something more meaningful.
So at that point, we will then replace it with the functionality that allows us, of course, to go
over to the profile page.
So we will need to create another activity which will do that.
And then we have the other icon.
So order I.D., dot net, sign out.
And what do we want to do if we press that button?
Well, first of all, we want to sign out of Firebase.
So Firebase off dot get instant's dot sign out.
So at this point, we can sign out and then while intent, so we should move over to another activity
intent, and we need to import intent for all to enter from this activity to the intro activity.
So we sent the user back to the intro activity class, our Java.
And, of course, double Colen here.
All right, and then we can add some flags to it, so let's add a flag to the intent had flags.
And it reflects that I want to add is intent, that flag activity.
Clear top for.
Intent, flag activity.
New task or now you might wonder what those flags do.
Well, you can any time read through this.
So there's a huge explanation.
So if set and the activity being launched is already running in the current task, then instead of launching
a new instance of that activity, all of the other activities on top of it will be closed and this intent
will be delivered to the now on top old activities and new intent.
OK, and then for the flag, new task.
What that does is it says when using this flag, if a task is already running for the activity, you
are now starting then a new activity will not be started.
Instead, the current task will simply be brought to the front of the screen with the state.
It was last.
And so basically we're not starting a new activity for interactivity if there was an interactivity in
our stack already.
So in our activities stack and we're just getting the intro activity to the front, so to speak.
So this is what we do with those flags there.
All right.
And then we can, of course, start the activity with this intent.
So start activity with intent and then finish the current activity so that the user can't get back to
the main activity once he signed out.
So that's basically the idea.
Right.
And of course, in any case, when the user clicked on anything we want to.
Close our draw, so draw layout, close draw with this same concept that we have before with this gravity
combat start.
So if I want to know more about gravity combat, start, push, object to x axis position at the start
of its container, not changing its size, so it just pushes it to the left side.
And this, of course, has to be done just here.
OK, one.
Bracket later.
And then if we look at our navigation item, listen there, it expects a boolean, so we need to return
something.
So let's just return.
True.
And then the error here disappears as well.
OK, and now we can go to our.
Uncreate here, we set up the action bar, but we're not setting up our nephew, not the nephew, but
the nephew, and then we set the navigation item selected listener to this, because this class is going
to be a navigation item, selected listener, as we have.
Added this part of code or this piece of code to the top of our main activity.
So basically, we're saying, OK, when something is clicked, do whatever is designed in here, so
it's very similar to a unclick listener, as we have seen before, but now it's an item selected listener
because we have multiple items that we can click on.
All right, and at that point, we can test our application on the device, so let's see whether the
eye can work so we can see we have the eye can now it's our menu.
I can that we added.
You click on it.
It's there.
Let's press the button.
Let's see.
Right.
It closes.
It has pressed the button again.
You could see we get this little toast at the bottom and then, yeah, everything seems to work.
Profile.
You can see my profile is displayed now.
Let's try to sign out.
And we are sent back to this island screen.
OK, so at this point, we have added this navigation system and it's quite some work, as you can see.
But on the other hand, it's a super useful feature that you will see quite often in applications.
And it's very, very helpful.
All right, so I'd say let's go ahead and add some more features in the next video.
See you there.