1
00:00:00,580 --> 00:00:01,280
Welcome back.

2
00:00:01,540 --> 00:00:06,710
Now that our authentication functionality seems to work, let's look at database.

3
00:00:06,720 --> 00:00:09,910
So there we have two options, right?

4
00:00:09,940 --> 00:00:16,930
So one, in the database, you can either use fire store or you can use the.

5
00:00:17,810 --> 00:00:24,800
Real time database and I talked about it very briefly before, but what we are just going to use the

6
00:00:24,800 --> 00:00:29,890
cloud firestorm because it's more powerful queries, automatic scaling.

7
00:00:29,900 --> 00:00:32,720
So it's just a better choice for us.

8
00:00:32,729 --> 00:00:32,980
Right.

9
00:00:33,680 --> 00:00:35,240
So let's go ahead and create that.

10
00:00:35,630 --> 00:00:41,270
We are going to use the test mode because we want to be able to test everything.

11
00:00:41,270 --> 00:00:41,600
Right.

12
00:00:41,630 --> 00:00:46,430
Anyone with a database reference will be able to read right to your database for 30 days.

13
00:00:46,760 --> 00:00:49,790
So this is a high risk approach.

14
00:00:49,790 --> 00:00:53,000
Of course, anything good or many things could go wrong.

15
00:00:53,240 --> 00:00:58,820
But in our case, because we want to test it, it's going to make our life a lot easier, especially

16
00:00:58,820 --> 00:00:59,350
at the beginning.

17
00:00:59,360 --> 00:01:02,570
So once you're in production, you should definitely change your rules there.

18
00:01:03,350 --> 00:01:09,440
Then you have to select your cloud forest location so where the data should be located.

19
00:01:09,770 --> 00:01:12,450
So you have, of course, multiple different options here.

20
00:01:12,710 --> 00:01:18,500
I'm just going to use Europe West because I am in Europe and then I'm going to press down.

21
00:01:18,650 --> 00:01:25,370
If you have an application where your user base will be mainly in another country or in one specific

22
00:01:25,370 --> 00:01:32,360
country, then you definitely have to consider that your put your location cloud first location specifically

23
00:01:32,360 --> 00:01:33,200
at that location.

24
00:01:33,840 --> 00:01:34,360
OK.

25
00:01:36,270 --> 00:01:41,900
All right, once that is done, you will find yourself seeing the screen where you have data rules,

26
00:01:41,900 --> 00:01:47,290
indexes and usage and by the way, in rules, that's the thing that has been changed for us to hear.

27
00:01:47,300 --> 00:01:47,840
Read right.

28
00:01:47,840 --> 00:01:50,240
Is activated so that we can.

29
00:01:51,590 --> 00:01:56,680
Ride around and play around with it, you can see, hear, read, write, and then request time, time

30
00:01:56,750 --> 00:02:02,300
stamp date 20, 20, the 22nd of March, then it will change.

31
00:02:02,500 --> 00:02:06,950
OK, so for now, it's a ride are both allowed, but later on we'll change it.

32
00:02:07,070 --> 00:02:09,080
And you can change those rules any time.

33
00:02:09,350 --> 00:02:12,560
If you want to know more about the rules, check out the documents here.

34
00:02:12,770 --> 00:02:14,890
OK, but for now, it's going to be fine for us.

35
00:02:15,170 --> 00:02:20,270
We can just go ahead to the data tab and yea, we can now create our own collections.

36
00:02:20,720 --> 00:02:24,830
For example, we can go ahead and create a collection called User's.

37
00:02:25,850 --> 00:02:33,170
So let's go ahead and create this collection called Users, and now you can go ahead and create and

38
00:02:33,170 --> 00:02:36,950
document ID, for example, you can go ahead and create an auto ID.

39
00:02:36,980 --> 00:02:39,380
You can add all of the different fields that you want to have.

40
00:02:39,380 --> 00:02:43,430
For example, for user, what we have is the name, the email address.

41
00:02:43,640 --> 00:02:47,990
And then we could have something like an image or whatever you can come up with.

42
00:02:47,990 --> 00:02:48,250
Right.

43
00:02:48,470 --> 00:02:50,990
But the thing is, you don't even need to do that here.

44
00:02:50,990 --> 00:02:55,760
So we can, of course, create a collection and create everything just here in this beautiful UI.

45
00:02:56,060 --> 00:02:58,150
But we are going to do that in code.

46
00:02:58,160 --> 00:03:04,520
So you will see how to create collections and those objects, so to speak, in code, because we will

47
00:03:04,520 --> 00:03:09,380
create a class, a user's class, which will then contain all of the information that we want to store

48
00:03:09,650 --> 00:03:10,550
about a user.

49
00:03:10,730 --> 00:03:11,140
All right.

50
00:03:11,150 --> 00:03:16,070
At that point, we can go back to our project and we will need to add a new.

51
00:03:17,910 --> 00:03:26,550
Implementation here or a new dependency to our project, so let's add that it's the first to implementation

52
00:03:26,690 --> 00:03:27,170
here.

53
00:03:27,200 --> 00:03:29,870
Let me add that you can see Firebase.

54
00:03:30,870 --> 00:03:39,630
Firestorm 21 four zero, so it's similar to what we had before when we had firebase off and you can

55
00:03:39,630 --> 00:03:41,800
see the versions, they differ a little bit.

56
00:03:42,180 --> 00:03:43,490
So now we're using Firestone.

57
00:03:43,500 --> 00:03:47,400
Later on, we will use storage and we will need to add another dependancy.

58
00:03:47,400 --> 00:03:49,410
But for now, this is going to do.

59
00:03:50,580 --> 00:03:57,930
So don't forget to think it, of course, and once the singing is done, you can start thinking, all

60
00:03:57,930 --> 00:04:00,510
right, you can start using Storm.

61
00:04:01,540 --> 00:04:06,760
All right, and the next thing is that we are going to create a new class, so the thing is I thought

62
00:04:06,760 --> 00:04:14,590
about different ways to approach this application and doing it in while doing the code that you need

63
00:04:14,590 --> 00:04:18,779
in the classes where you need them to create a lot of duplication.

64
00:04:18,790 --> 00:04:25,870
And I thought it would be a lot nicer to have a very clean structure that you can easily re use and

65
00:04:25,870 --> 00:04:28,160
then also easily adjust and maintain.

66
00:04:28,390 --> 00:04:31,960
So let's say at one point Firebase doesn't work anymore.

67
00:04:32,290 --> 00:04:37,450
So you don't want to go to every single class and make changes to every single part of the application.

68
00:04:37,660 --> 00:04:41,190
But you want to have one class which handles the whole database stuff.

69
00:04:41,500 --> 00:04:46,870
So in case Firebase doesn't work anymore, you need to change to another solution in the future.

70
00:04:47,110 --> 00:04:50,130
For whatever reason, Firebase doesn't exist anymore.

71
00:04:50,440 --> 00:04:55,570
They go bankrupt even though it's highly unlikely that Google will ever go bankrupt.

72
00:04:55,760 --> 00:05:02,320
But I mean, like generally, if you use a solution which could potentially go obsolete at one point,

73
00:05:02,650 --> 00:05:07,360
then it's always good to have the code already be prepared for this.

74
00:05:07,450 --> 00:05:08,380
And that's what we're going to do.

75
00:05:08,390 --> 00:05:14,940
So we are going to create an extra class which will take care of the whole database stuff and horror

76
00:05:14,950 --> 00:05:16,390
of the whole fire store stuff.

77
00:05:16,600 --> 00:05:21,070
And that will make our life a lot easier if we ever have to change anything.

78
00:05:21,400 --> 00:05:25,150
OK, so let's go ahead and create a new directory here.

79
00:05:25,150 --> 00:05:31,150
So a new package and this one will be Firebase and inside of Firebase.

80
00:05:31,150 --> 00:05:34,900
I want to have this new class, which I'm gonna call Firestar class.

81
00:05:35,680 --> 00:05:37,600
Very awesome name.

82
00:05:37,600 --> 00:05:39,070
So file class.

83
00:05:40,190 --> 00:05:49,850
Fire store, or maybe it's just a store class, all right then and here, I want to put all of the different

84
00:05:49,940 --> 00:05:54,540
fire base fire store dependent or irrelevant code.

85
00:05:54,920 --> 00:05:59,650
So, first of all, I will need to have an instance of the fire based fire storm.

86
00:05:59,900 --> 00:06:00,400
All right.

87
00:06:00,410 --> 00:06:10,220
So private fall and fire storm, I'm going to call it, and will be fire base, fire store, dot, get

88
00:06:10,220 --> 00:06:10,980
instance.

89
00:06:11,000 --> 00:06:13,550
So let's get the instance directly.

90
00:06:14,060 --> 00:06:17,810
Fire based firestorm needs to be written correctly.

91
00:06:17,810 --> 00:06:21,910
Then it will also allow me to use it in my case.

92
00:06:21,920 --> 00:06:27,980
So you can see we have this new import here, fire base, fire store, and then we get the instance.

93
00:06:29,480 --> 00:06:33,540
So let me see what still complaining because it added this tour.

94
00:06:33,740 --> 00:06:38,960
OK, so now we have our fire base fire, for instance.

95
00:06:41,060 --> 00:06:50,270
And now we can go ahead and create a new user so we can register a user in our database, so the idea

96
00:06:50,270 --> 00:06:56,680
is that we don't only registered user directly in the authentication module, but also in our database.

97
00:06:57,650 --> 00:07:04,490
So not only here in authentication, where we have the user, we have this identifier that we have when

98
00:07:04,490 --> 00:07:06,560
we was created and the user ID.

99
00:07:06,800 --> 00:07:09,620
But we also want to store a little more information about the user.

100
00:07:09,770 --> 00:07:15,920
So each time user registers, we also want to have them in the database so that we can then add information

101
00:07:15,920 --> 00:07:18,290
about as, let's say, telephone number.

102
00:07:18,290 --> 00:07:24,230
If you want that or if you want to add an image of him or he wants to add an image of him, then we

103
00:07:24,230 --> 00:07:25,610
want to be able to do that, OK?

104
00:07:25,850 --> 00:07:29,720
And that's why we need to have an entry for every user in our database.

105
00:07:31,490 --> 00:07:39,310
So let's create a little function, which will do just that, so fun register user, which will need

106
00:07:39,320 --> 00:07:49,100
an activity and I'm going to pass on the sign up activity and then user info, which will be of type

107
00:07:49,610 --> 00:07:50,150
user.

108
00:07:50,390 --> 00:07:56,240
So we will need to create a class which allows us to do a lot of stuff.

109
00:07:56,240 --> 00:07:56,510
Right.

110
00:07:56,540 --> 00:07:57,540
So let's go ahead.

111
00:07:57,560 --> 00:07:58,880
Do we have the users already?

112
00:07:58,920 --> 00:07:59,870
No, we don't have it.

113
00:08:00,140 --> 00:08:02,360
So we need to create a new model called user.

114
00:08:04,410 --> 00:08:11,220
So let's go ahead and create it real quick, New Scotland class, and this one will be user.

115
00:08:13,620 --> 00:08:20,520
Now, this is going to be a data class, right, data class user, and we want to have a bunch of information

116
00:08:20,520 --> 00:08:21,530
about the user here.

117
00:08:21,840 --> 00:08:26,280
So when we use the data class, we just need those kind of brackets or not the curly ones just around

118
00:08:26,280 --> 00:08:26,750
the ones.

119
00:08:27,060 --> 00:08:30,090
So I want to store the ID of the user.

120
00:08:30,630 --> 00:08:32,640
So let's do that then.

121
00:08:32,880 --> 00:08:34,679
I want to store the name of the user.

122
00:08:36,510 --> 00:08:38,070
Then what else would be interesting?

123
00:08:38,760 --> 00:08:40,159
Well, the email would be nice.

124
00:08:40,409 --> 00:08:42,299
So let's add the email as well.

125
00:08:42,450 --> 00:08:43,980
Email of the user.

126
00:08:46,140 --> 00:08:46,890
Then what else?

127
00:08:47,340 --> 00:08:53,700
Well, image, how about an image, so I'm going to store the image as a string as well because I'm

128
00:08:53,880 --> 00:08:58,080
just going to store the image location on the database.

129
00:08:58,080 --> 00:09:02,940
So it's not really the database, but it's actually the.

130
00:09:05,200 --> 00:09:08,620
Storage functionality of firebase, so you can see we have an extra.

131
00:09:10,700 --> 00:09:16,130
The point here, which is called storage, so you can store images or even videos on the storage.

132
00:09:16,880 --> 00:09:17,360
All right.

133
00:09:18,440 --> 00:09:25,160
So we will have the image then, maybe also the mobile number of the user, so mobile, which will be

134
00:09:25,160 --> 00:09:25,900
a long.

135
00:09:26,830 --> 00:09:32,060
I'm just going to set to zero for now and then to Afkham token.

136
00:09:32,270 --> 00:09:38,660
So we will also need to have a token of the user so that we know that it's the specific user that is

137
00:09:38,660 --> 00:09:39,990
Lockton next.

138
00:09:40,010 --> 00:09:45,440
I would like to make this class pasodoble, and in order to do so, I can of course, write all of the

139
00:09:45,440 --> 00:09:51,790
code manually or I can just go to settings and then have a new plugin.

140
00:09:51,860 --> 00:10:00,170
So here on the plugins, let's search for Paul sellable and you will find this Android Pozible coal

141
00:10:00,350 --> 00:10:01,180
generator.

142
00:10:01,730 --> 00:10:02,840
That's the one that I want.

143
00:10:03,710 --> 00:10:11,330
And for it to work, you need to restart the idea, all right, at that point, it should work.

144
00:10:11,340 --> 00:10:20,780
So let's make it past sellable for so long, though, with a capital P, of course I'll pass lable.

145
00:10:21,740 --> 00:10:23,390
And now implement the members.

146
00:10:26,390 --> 00:10:33,580
And also at the pass the level implementation, so you can see it will create all of this stuff here,

147
00:10:33,590 --> 00:10:36,770
constructor pozole restring.

148
00:10:36,770 --> 00:10:37,250
Right.

149
00:10:37,250 --> 00:10:40,840
Passell described then also this companion object creator.

150
00:10:41,210 --> 00:10:47,360
So this is automatically generated now by the help of the plugin that we just installed.

151
00:10:48,570 --> 00:10:52,980
Now, at this point, it's complaining because Passell.

152
00:10:55,150 --> 00:11:00,760
Our restring is going to return a nullable, so we need to add all of those exclamation marks.

153
00:11:00,970 --> 00:11:05,750
But once we've done that, you can see by my class already so far.

154
00:11:06,370 --> 00:11:12,850
Now, when we want to describe contents, what we're going to do is we're just going to assign zero

155
00:11:12,850 --> 00:11:13,390
to it.

156
00:11:13,930 --> 00:11:20,380
And to write Postle here, we're just going to add a bunch of right strings.

157
00:11:21,220 --> 00:11:24,430
So write string the ID.

158
00:11:24,670 --> 00:11:29,080
And by the way, I'm just going to make Pozole and not Nullable.

159
00:11:30,280 --> 00:11:34,690
And also I need to add this statement here with that.

160
00:11:35,170 --> 00:11:35,830
And now.

161
00:11:35,860 --> 00:11:36,070
Right.

162
00:11:36,070 --> 00:11:36,910
String is going to work.

163
00:11:36,920 --> 00:11:42,890
So we need to do what's right string for all of the different values that we have.

164
00:11:42,910 --> 00:11:49,060
So here it's going to be right long for the number.

165
00:11:49,930 --> 00:11:51,010
For the phone number, right?

166
00:11:53,610 --> 00:11:54,060
So.

167
00:11:55,310 --> 00:11:56,660
That's add mobile here.

168
00:11:58,280 --> 00:12:03,890
This one was the idea, and we had the name, we had the email and we had the image.

169
00:12:04,740 --> 00:12:07,580
Then finally we had the same token.

170
00:12:08,910 --> 00:12:09,500
OK, so.

171
00:12:10,750 --> 00:12:17,420
When we write into a parcel, what we're going to do is we write all of our variables that we have here.

172
00:12:17,980 --> 00:12:24,010
OK, so at this point, this class is going to be ready and we can go on because the video is already

173
00:12:24,010 --> 00:12:29,420
going to be so long because we need to still add quite some stuff in the first class or we need to create

174
00:12:29,440 --> 00:12:30,750
a first class and so forth.

175
00:12:31,000 --> 00:12:37,840
I would say let's make a quick break here and then finish this part of the exercise or part of the code

176
00:12:38,050 --> 00:12:44,380
in the next video where we're going to finally be able to add data to our database in the fire store

177
00:12:44,380 --> 00:12:44,920
database.

178
00:12:44,920 --> 00:12:45,730
So see you there.

