Welcome back.
Whenever you register somewhere and you're logged in, then a token is sent to your device and we need
to work with that token because we want to use that token for the notification functionality.
So what we will do in this video, we are going to focus on the token functionality before we then go
back to the notification and finish that functionality.
So therefore, first of all, I'm going to go to my Constance and I'm going to create a new constant
because I'm going to use shared preferences to store that token on the device.
So here, let's go ahead and create a new entry, which I'm going to call.
Const Voll.
Pro Jay Manaj preferences.
And that will be pro-gay Manaj.
Preferences.
Or maybe something approaching Menasche press.
Actually, it doesn't really matter.
It's just important that you always use this constant value if you want to work with procurement preferences
or shared preferences.
OK, and the main activity, that's where we are logging in, right?
So let's go over there.
And this main activity here, we are going to create a new global variable, so here private.
And actually, let's make it to late in advance, late in advance and shared preferences, which will
be of tipsheet preferences.
Now, let's initialised to ship preferences in our uncreate method so we can just do that down here.
Or actually, let's do it before we.
Load the data or anything like that.
Even though it shouldn't make that much of a difference, but still, just to be sure.
Let's go ahead and.
Initialize it this start get shared preferences at the position constants DOT Project, Monash preferences.
OK, so this is the shared preferences object we need to add.
The motel that we want to use, so here, context mode, private.
OK, so the ship preferences should only be available inside of our application itself.
Then in our Firestar class, inside of our update, user profile function updates, user profile data
in there, we need to make some changes.
We're just at the point where we call activity that profile update success, so this will not be on
only a profile on high profile activity, but it will be an activity in general.
So this this activity that is passed to us, but then accordingly, we need to make changes to this
line here so we can check is it a main activity?
If that's the case, then call activity that Tolkan.
Update success, so that's going to be a function that we all need to create in a minute and then if
it is a high profile activity.
Then do as you did before, so just call a Twitter profile.
I played success.
OK, and here we still get this error, so we need to make the same distinction here.
So when the activity is a main activity call activity, hyd progress, dialogue, and when we are in
the high profile activity, do the same thing.
OK, now let's go ahead and create this function, Tolkan, update success in our main activity.
So let's go ahead and add that.
Fun Tolkan Update's success here, we, first of all, should hide progress, dialogue.
Then we will go ahead and create an editor for our ship preferences, so shared preferences, thought
editor, which will be our shared preference, is to be prepared.
And here we need to add it or use the added function.
And then can you use that Ed to put information into it?
So, Ed Todd, what boolean.
And it should be constants that F.C. Tolkan.
Updated.
So true.
Now, you might wonder about him talking, updated while we don't have that yet.
Well, let's have that in here as well.
So Const Voll.
Have some token updated.
Which I'm going to set to have the token updated and then we need another constant here while ACM.
Tolkan.
Which I'm just going to call EPCM Tolkan.
OK, so these are the variables that we're going to use as token update, it should be fine.
So at the position of FCC token update that we set the value to Drew.
And then we.
Said the Ed thought appli function, I would call it, but this change will be applied to our ship preferences.
So this is called if we have an updated Tolkan and we get a token once the user is registered, right.
Once he registers or once he logs in.
And then here we also want to show the progress dialog.
Which says, please wait, and then we used to fire storm class that.
Load user data with this.
Activity and the value.
True for the read or list.
So it should re open the screen or rerolled the screen, so to speak.
OK, now we will also need a function that takes care of updating the token inside of our.
Database, so to speak.
All right, so here, fun, and this one can be private, so private fun update F.C. Tolkan.
Here we pass in the token, which will be of type string and then.
Here we used to user Hashmat.
Which will be a Hashmat of string and any.
And then we used this user hash map at the position, Constance.
Thought FGM underscore Tolkan.
So if you look at the user.
Here is the model user, you can see that we had this value called Afkham Tolkan and you might have
wondered what the heck this was for.
So we never used it, but now we do.
So now we want to store the FCM tokens or the token of the user that is locked in so that he can log
in very easily and that we can send notifications to him and so forth.
OK, so we set that value to be the token that is passed to us when we call the update of some token
function.
And then we also want to.
Showed a progress dialogue.
Accordingly and.
Update Soulfire store clerks that update user profile data with this activity and the user hash map
that would just be paired.
So this function will take care of updating the Afkham token, and now we can.
Get the ACM token.
From the ship preferences, and that will be in our uncreate here, so that is where we get the ship
preferences and once we have the ship preferences, we can now, of course, use the.
While token updated equals and shared preferences that get Bolian at the position constants that.
SDM Tolkan updated.
And the default value will be false.
So this variable is used to get the value, whether either the token is updated in the database or not.
OK, and then we check if.
The token is updated.
Then we will show the progress dialogue.
With our police wait statement, so we used the string once again here.
And then.
We use Firestar class.
Third load user data with this activity.
And report details said to true.
And otherwise, so Tolkien updated this set of falls, then we will use Firebase.
Instant's.
I'd thought get instance.
That instance ID.
Thought add on success listener.
With and here we need to import Firebase.
Instance.
Or yeah, right, it correctly and import it so here, for instance, ID.
With the head on success listener, and this should be the main activity, and then.
What do you want to do here?
Well, we want to update our F.C. Tolkan.
With instance Heidi Dodd or the result that Tolkan.
OK, so.
By using this and, by the way, the result.
For instance, result is what we get.
From.
Our function here, OK, so we get the instant result from this call here.
So basically what's happening here is if we have an update token, we just say, OK, look, the user
data and if we don't have an update token, then we want to get an update, a token.
So we get it from the instance.
And then we call the update of some token we pass in the user hash map.
We update is a profile with the updated token.
And then there's one thing left to do, and that is when we click on Nevsun out.
So when we sign out of the application, what we also want to do is we want to make sure that.
Our.
She had preferences are reset so that the token is not stored anymore.
OK, so headed that clear also here, clear thought apply.
What that will do is it will reset the whole ship preferences and set that back to empty.
So let's test the application and see if the data is actually updated in the database or at least have
some token is stored in the database.
So here we look at the users.
If the user gets an FCC, I'm talking or not, so not part, but done such larcombe.
OK, so that we are.
Profile updated successfully.
Good to hear.
And as it seems, we are not closing the dialogue yet, so at some point we're still not closing our
dialogue there.
But if we look at the database, we can see that I have a token here now, so I'm letting the token
worked, but we still need to close the progress dialogue.
And as it seems, I was missing a high progress dialogue inside of our update, navigation user details
function.
So, yeah, you need to add that line as well as inside of the main activity.
So I check the flow.
By the way, if you want to know how to figure that out, I check the flow of our application.
So each time that we show the progress dialogue, we need to make sure that whatever calls we do afterwards.
So for example, imports list, this function needs to close the dialogue as well.
So here.
At on success, listener needs to add one point close to dialogue, so as this doesn't do it directly
in here, it needs to do it in one of those calls.
So, for example, in the unfilial listener, it needs to hide the progress dialogue, but also in the
populated portals.
Why?
I need to make sure that the HUD progress dialogue here is also called.
OK, so that's it for this video.
And in the next video, we're going to do some more notification stuff.
So finally, getting the notification running.
Yeah, you're the next one.