1
00:00:00,180 --> 00:00:05,790
Now that we have the user class, we can go ahead and use user, so let's import user here, which is

2
00:00:05,790 --> 00:00:07,240
our models.

3
00:00:07,290 --> 00:00:08,580
So instead of models.

4
00:00:10,470 --> 00:00:13,200
And not the user that we get from Firestorm.

5
00:00:13,530 --> 00:00:16,680
It's important that we use the right one here.

6
00:00:18,840 --> 00:00:25,650
So now what I want to do is I want to register the user right in this function, but what we need,

7
00:00:25,650 --> 00:00:29,550
therefore, is our M store collection.

8
00:00:29,580 --> 00:00:34,440
So I'm going to create a new collection, which is going to be called users.

9
00:00:35,650 --> 00:00:39,060
OK, so it's going to be something like this or something like this.

10
00:00:39,330 --> 00:00:42,500
But the thing is, I'm using a magic string here.

11
00:00:42,510 --> 00:00:43,860
That's something that I shouldn't do.

12
00:00:44,320 --> 00:00:47,700
I think it's better if I go ahead and create a new.

13
00:00:48,950 --> 00:00:52,190
Class, which will be or new file, which will be Constance.

14
00:00:56,620 --> 00:00:59,080
This will just be a constant object.

15
00:01:03,070 --> 00:01:10,940
Which will for now just have one constant contact, all users string, which will be users.

16
00:01:12,460 --> 00:01:16,780
All right, so now we can use this constant that we prepared.

17
00:01:18,730 --> 00:01:22,480
So Constance thought user or users.

18
00:01:24,470 --> 00:01:32,390
So this is just a cold way to do the same thing as if we just created a new collection here, which

19
00:01:32,390 --> 00:01:33,200
is called Users.

20
00:01:34,840 --> 00:01:40,480
OK, so here, creating a collection or start collection, and we called this one, for example, users,

21
00:01:41,200 --> 00:01:46,480
and then we click next and now it becomes interesting because the document ID and all of the different

22
00:01:46,480 --> 00:01:49,150
fields, that's what we do next in the code.

23
00:01:50,730 --> 00:01:56,250
So we know go ahead and create a document, right, so that document.

24
00:01:57,710 --> 00:02:05,240
And here we need to get the current user ID, so we want to create a new document for every single user

25
00:02:05,240 --> 00:02:09,199
that we have because we want to store details about every single user.

26
00:02:09,199 --> 00:02:09,449
Right.

27
00:02:09,470 --> 00:02:15,620
So it would be good if we could get the user ID, which is this unique user I.D. So how do we get that?

28
00:02:15,650 --> 00:02:17,120
Well, we need to function for that.

29
00:02:17,130 --> 00:02:23,660
So let's create a new function, which is just going to give us the current user ID, get current user

30
00:02:23,690 --> 00:02:32,150
I.D., which will return a string, which then will simply return firebase of.

31
00:02:33,850 --> 00:02:41,320
Firebase Horth, get instant's current user.

32
00:02:44,020 --> 00:02:44,920
You ID.

33
00:02:47,070 --> 00:02:52,800
OK, so that will give us, as to current users, unique ID, which is.

34
00:02:54,740 --> 00:03:01,100
This year, you ID this one here, so it's going to give us this one and we want to use that as the

35
00:03:01,100 --> 00:03:04,280
document inside of our collection.

36
00:03:04,850 --> 00:03:07,190
So we'll create a new collection, which we call users.

37
00:03:07,200 --> 00:03:13,490
Then we have a new document which is going to be called this weird number or this weird add value that

38
00:03:13,490 --> 00:03:15,140
we just saw for every single user.

39
00:03:15,140 --> 00:03:20,420
So every user will have his own collection or the collection, but every user will have his own document.

40
00:03:20,560 --> 00:03:25,580
OK, so we have collections in collections, we have documents and then we have all of those fields

41
00:03:25,880 --> 00:03:31,280
and the fields will be the one that we have in our user class, which is ID, name, email, image for

42
00:03:31,280 --> 00:03:32,330
mobile and so forth.

43
00:03:32,510 --> 00:03:36,410
So we don't want to create all of that stuff manually, but we want to do it in a code.

44
00:03:36,650 --> 00:03:37,990
That's exactly what we do now.

45
00:03:39,170 --> 00:03:46,430
So now let's go ahead and pass in the user, the current user, so get current user ID, then we want

46
00:03:46,430 --> 00:03:54,040
to set the user info to be set options Merche.

47
00:03:54,620 --> 00:03:59,020
So it's going to merge the user info, whatever user info is passed to us.

48
00:04:02,020 --> 00:04:09,360
And then we need to finally add in on success listener, so did it work, Ed, on success a listener

49
00:04:09,640 --> 00:04:12,870
and if it did work, well, then we want to execute some code.

50
00:04:13,150 --> 00:04:20,740
So we want to run the activity that is passed to this function, this registered user function, which

51
00:04:20,740 --> 00:04:22,060
is to sign up activity.

52
00:04:22,420 --> 00:04:26,530
And we dare want to call the user registered.

53
00:04:29,990 --> 00:04:37,490
Success, so user registered success.

54
00:04:39,630 --> 00:04:44,850
So it doesn't exist, so let's go over to the sign up activity and created.

55
00:04:46,540 --> 00:04:51,580
For now, it's just going to be a new function user registered.

56
00:04:54,790 --> 00:05:01,340
Success, which will show a toast, so let's see if we find a toast somewhere.

57
00:05:01,360 --> 00:05:06,700
I'm just going to use this toast here and actually I want to do the same thing as I did here.

58
00:05:08,530 --> 00:05:10,900
So where is it?

59
00:05:10,930 --> 00:05:18,250
It's up here, so let's write this little toast without the name and the email you have successfully

60
00:05:18,250 --> 00:05:19,150
registered.

61
00:05:22,180 --> 00:05:23,010
Something like that.

62
00:05:26,840 --> 00:05:28,070
And here.

63
00:05:29,650 --> 00:05:33,190
We should also highlight the progress bar, so hide.

64
00:05:35,190 --> 00:05:36,030
Progress.

65
00:05:40,120 --> 00:05:40,660
Thilak.

66
00:05:41,830 --> 00:05:44,380
So here, make tax, something is wrong with make text.

67
00:05:44,410 --> 00:05:46,740
It still needs the length here.

68
00:05:47,260 --> 00:05:51,940
So that's because I forgot to add a little quotation mark here.

69
00:05:52,360 --> 00:05:58,030
So hi, progress dialogue at that point and then lock the user out.

70
00:06:00,290 --> 00:06:08,000
By the way, if we now used to hide progress, dialogue, function here, we won't need it anymore in

71
00:06:08,000 --> 00:06:13,130
our registered user because we also did that somewhere in here.

72
00:06:16,060 --> 00:06:19,590
And that is right here, so we won't need it here anymore.

73
00:06:21,850 --> 00:06:30,720
And now at that point, we need to make sure that when we are registering a user that we call the fast

74
00:06:30,760 --> 00:06:33,210
or class function, which is called registry user.

75
00:06:33,670 --> 00:06:36,010
So the thing is, we're registering the user on two levels.

76
00:06:36,010 --> 00:06:36,310
Right.

77
00:06:36,340 --> 00:06:40,030
So one is we actually create the new authentication entry for him.

78
00:06:40,240 --> 00:06:46,300
And the other one is that we create a new entry in the collection of users, which is a new documentation

79
00:06:46,300 --> 00:06:46,900
or a document.

80
00:06:46,900 --> 00:06:47,200
Right.

81
00:06:49,480 --> 00:06:53,800
And this will is a little abstract still, but it will make a lot more sense once we actually run the

82
00:06:53,800 --> 00:07:00,010
code and we see what it does with our entry in the fire store database.

83
00:07:00,700 --> 00:07:03,520
OK, so at this point, there's one little thing left to do.

84
00:07:04,770 --> 00:07:07,450
And that is to get rid of this toast here.

85
00:07:07,500 --> 00:07:12,760
We won't need it anymore in here and we also don't need to sign out here anymore.

86
00:07:13,110 --> 00:07:16,070
But what we want to do is we want to create a new user.

87
00:07:16,110 --> 00:07:16,510
Right.

88
00:07:16,520 --> 00:07:25,950
So here we just go ahead and say what user is going to be a new user, which is going to be a firebase

89
00:07:25,950 --> 00:07:26,700
user?

90
00:07:26,940 --> 00:07:31,180
Thought you I.D. is what are we going to pass there?

91
00:07:31,230 --> 00:07:34,350
We passed a name and we passed a registered email.

92
00:07:35,580 --> 00:07:37,870
OK, so let's go ahead and import user.

93
00:07:37,890 --> 00:07:41,000
This time it's also our models here.

94
00:07:41,760 --> 00:07:48,600
So we'll create this new user object and now we can pass that user object to our first class function,

95
00:07:48,600 --> 00:07:50,070
which is this registered user.

96
00:07:50,310 --> 00:07:54,810
So we need to pass on an activity which is going to be this, and then we pass in the user, which is

97
00:07:54,810 --> 00:07:57,460
the user that we just created in our sign up activity.

98
00:07:57,840 --> 00:08:06,270
So now we can go ahead and say fires to class, dot register user.

99
00:08:06,840 --> 00:08:13,560
And here we pass on this and we pass in our register or our user that we prepare.

100
00:08:14,430 --> 00:08:19,050
And then, of course, I need the brackets here because I'm not using a first class object.

101
00:08:19,050 --> 00:08:20,550
I'm using the actual class here.

102
00:08:21,000 --> 00:08:24,900
So I need the brackets in order to call its function.

103
00:08:25,830 --> 00:08:26,250
All right.

104
00:08:26,260 --> 00:08:31,110
So at this point, let's test our application and see if it's going to do what we need from it.

105
00:08:32,970 --> 00:08:38,070
And by the way, while it's loading, let's go to authentication and get rid of those two users, because

106
00:08:38,070 --> 00:08:41,039
those two day would cause problems later on.

107
00:08:42,360 --> 00:08:48,660
Because otherwise, well, we will try to access their information as users, but they don't exist,

108
00:08:48,660 --> 00:08:51,090
right, because we changed everything.

109
00:08:51,420 --> 00:08:56,520
So they just didn't exist in the database to exist in the authentication, but they don't exist in the

110
00:08:56,520 --> 00:08:57,060
database.

111
00:08:57,060 --> 00:09:01,080
So if we want to access anything from the database, that would cause problems.

112
00:09:02,230 --> 00:09:07,240
All right, and at that point, we can test it, there's only one little thing that I noticed when I

113
00:09:07,240 --> 00:09:12,210
ran into an issue testing it, and it's not really the code itself.

114
00:09:12,220 --> 00:09:14,080
The code is fine as it is now.

115
00:09:14,260 --> 00:09:20,470
There's just one duplicate that I have here, which is activity finish, which I run here once again

116
00:09:20,470 --> 00:09:26,500
in the Firestone class, even though it's necessary because an user registered success, we already

117
00:09:26,500 --> 00:09:27,190
run finish.

118
00:09:27,220 --> 00:09:30,820
Okay, so it's not really necessary also when testing it.

119
00:09:30,820 --> 00:09:31,930
And by the way, now it works.

120
00:09:31,930 --> 00:09:39,190
So the code is fine and I had to test it on another machine in order to make sure that the code is fine.

121
00:09:39,460 --> 00:09:41,340
But it still didn't work for me.

122
00:09:41,350 --> 00:09:46,490
So registering the user did work for me, but creating the collection for some reason didn't work.

123
00:09:46,510 --> 00:09:53,800
So what I needed to do is I needed to restart my computer and then run it again and then it worked.

124
00:09:53,830 --> 00:10:00,790
So if you have the problem that it doesn't work for you, then just try to do these kind of things,

125
00:10:00,790 --> 00:10:08,080
such as restarting your computer or closing Android studio and opening it up again, or even deleting

126
00:10:08,080 --> 00:10:13,950
the different folders that are inside of this project folder.

127
00:10:15,120 --> 00:10:21,480
So the build cradle an idea and also the build folder in here, you could delete them and then run the

128
00:10:21,480 --> 00:10:22,260
application again.

129
00:10:22,530 --> 00:10:29,670
I'm telling you this, because this issue, which is super funny, it didn't happen on other machines,

130
00:10:29,670 --> 00:10:30,670
but for me it did.

131
00:10:31,050 --> 00:10:35,400
That's why I wanted to talk about it real quick so that, you know, if something like that happens,

132
00:10:35,400 --> 00:10:40,860
that sometimes it's not the code, sometimes it's some unknown force.

133
00:10:41,460 --> 00:10:45,000
That's how I'm going to call it, because I have no idea where it comes from sometimes.

134
00:10:45,300 --> 00:10:45,690
All right.

135
00:10:45,690 --> 00:10:48,350
So let's sign sign up now.

136
00:10:51,040 --> 00:10:56,530
Therefore, I go here, I create a new user, and by the way, I deleted all the other ones, as you

137
00:10:56,530 --> 00:10:59,590
have seen, and now let's add this user here.

138
00:11:00,710 --> 00:11:05,660
And sign up, please wait, and you've successfully registered.

139
00:11:06,590 --> 00:11:08,870
So now let's go back to the authentication.

140
00:11:10,100 --> 00:11:14,510
And just refresh the page just to see if we have new users.

141
00:11:16,470 --> 00:11:20,790
And we can see we have them, of course, I could have pressed reload button that probably would have

142
00:11:20,790 --> 00:11:22,350
been faster and done in the database.

143
00:11:22,380 --> 00:11:25,190
Let's see if we have something in Project Manaj.

144
00:11:26,100 --> 00:11:27,840
We have this collection called Users.

145
00:11:27,840 --> 00:11:32,190
Then we have the user with this unique ID and we have all of this information.

146
00:11:32,190 --> 00:11:35,340
So we have this email system token nothing yet.

147
00:11:35,350 --> 00:11:36,480
ID Yes.

148
00:11:36,480 --> 00:11:37,270
Image nothing.

149
00:11:37,270 --> 00:11:38,950
Amabel zero a name doneness.

150
00:11:39,240 --> 00:11:39,660
All right.

151
00:11:39,670 --> 00:11:40,560
So it worked.

152
00:11:40,560 --> 00:11:48,840
We have passed an object into our database has fields I guess so we have this object.

153
00:11:48,870 --> 00:11:50,520
Is this the object, the user object.

154
00:11:50,880 --> 00:11:53,630
And these are all of the features of the user object.

155
00:11:53,640 --> 00:11:59,400
So all of the variables that the user class has and all of the details that we have with it.

156
00:12:00,210 --> 00:12:00,750
All right.

157
00:12:00,750 --> 00:12:06,480
So now you know how to create a collection, how to add a value in there and store data inside of the

158
00:12:06,480 --> 00:12:07,110
database.

159
00:12:07,110 --> 00:12:12,090
And we will, of course, have to check how to retrieve the data and we will work with all of those

160
00:12:12,090 --> 00:12:13,470
things in the next video.

161
00:12:13,480 --> 00:12:14,850
So see you there.

