1
00:00:00,710 --> 00:00:05,540
Welcome back and this video, we are going to actually create the board in the database, and that is

2
00:00:05,540 --> 00:00:12,890
something that you can do yourself already because you have seen how to create a user and also how to

3
00:00:12,890 --> 00:00:13,640
update them.

4
00:00:13,850 --> 00:00:18,230
So now you have to make a connection between the two and.

5
00:00:19,160 --> 00:00:22,910
Use that knowledge in order to create the boat, so it's going to be very similar.

6
00:00:23,420 --> 00:00:25,820
We already have the image of the board.

7
00:00:26,150 --> 00:00:27,650
We have the name of the user.

8
00:00:28,490 --> 00:00:29,740
We have the name of the board.

9
00:00:30,080 --> 00:00:34,070
So name of the board created by is the name of the user.

10
00:00:34,340 --> 00:00:37,780
And then assign to for now will only be the user.

11
00:00:37,790 --> 00:00:40,040
So later on we will of course adjust that.

12
00:00:40,040 --> 00:00:45,410
But for now it's going to be enough if we just have a user who created the board as being assigned to.

13
00:00:47,010 --> 00:00:52,590
The rest will pretty much be the same as signing up a user, but not just signing him up, but actually

14
00:00:52,590 --> 00:00:53,370
updating him.

15
00:00:53,380 --> 00:00:58,950
So I think you can learn more from the update class rather than the creation class.

16
00:00:58,950 --> 00:01:05,160
So the more my profile activity, I think here you can learn a lot more about what we need to do regarding,

17
00:01:05,160 --> 00:01:07,160
for example, uploading a user image.

18
00:01:07,440 --> 00:01:13,230
We're going to do a very similar thing to upload a board image and also.

19
00:01:14,370 --> 00:01:19,080
When updating something, well, I think let's just get started.

20
00:01:19,230 --> 00:01:22,470
You can, of course, try to build all of that yourself.

21
00:01:23,940 --> 00:01:32,040
So let's go over to to create board activity and start by creating a new variable, which will be private

22
00:01:32,040 --> 00:01:32,490
bar

23
00:01:35,790 --> 00:01:43,000
and board image, you, Yoro, which will be a string that will be empty for now.

24
00:01:43,410 --> 00:01:47,990
So we have the selected image URL, but we also need to know the board image URL.

25
00:01:48,010 --> 00:01:53,820
So if there is a your URL for the image already, we need to know that because we of course want to

26
00:01:53,820 --> 00:01:58,800
have a board image, but we just want to use a new board image.

27
00:01:58,800 --> 00:02:03,030
If there is not one selected here in the selected image, file your URL.

28
00:02:03,930 --> 00:02:04,360
All right.

29
00:02:04,560 --> 00:02:06,330
So that's that number then.

30
00:02:06,360 --> 00:02:10,340
We need to go ahead and create a function which actually creates the board.

31
00:02:10,350 --> 00:02:16,950
So private fun, create board.

32
00:02:19,410 --> 00:02:28,380
And here we just go ahead and for now, as I said, I signed the current user to the assigned user array

33
00:02:28,380 --> 00:02:28,650
list.

34
00:02:28,650 --> 00:02:36,300
So assigned users array list is an array list of strings.

35
00:02:36,820 --> 00:02:38,970
So it's what we need in the.

36
00:02:40,200 --> 00:02:42,480
Board here, so this assigned to.

37
00:02:43,740 --> 00:02:53,610
And I'm just going to assign the current user so assigned users a relist thought ad and here get current

38
00:02:54,300 --> 00:02:55,650
user ID.

39
00:02:59,750 --> 00:03:04,640
Now, for this, of course, to work, this has to be an array list, even if it's an empty one.

40
00:03:05,680 --> 00:03:07,840
OK, so that is how we create the board.

41
00:03:08,290 --> 00:03:15,130
Step number one, step number two is we prepared the board information so the board object.

42
00:03:15,970 --> 00:03:19,350
So we create a new board object, which will be of type board.

43
00:03:20,230 --> 00:03:23,170
And here we need to, first of all, get the board name.

44
00:03:23,410 --> 00:03:31,270
And as we are in the create board activity, we will get it from, of course, our activity create board.

45
00:03:31,870 --> 00:03:40,390
So here we have this added text which says board name as the hint, and that's the one we get the data

46
00:03:40,390 --> 00:03:40,660
from.

47
00:03:40,690 --> 00:03:42,910
So from that one, we get the name of the board.

48
00:03:43,360 --> 00:03:45,820
So let's go ahead and use that.

49
00:03:48,050 --> 00:03:57,960
And our create board function, so here it bought name, the text to string will be our port name,

50
00:03:58,660 --> 00:04:05,860
then we need to pass in the image so and board image URL and then the user username.

51
00:04:07,680 --> 00:04:16,290
And then assigned users a realist, OK, so the username is going to be the current user, so when creating

52
00:04:16,290 --> 00:04:21,269
a new board, the user who is creating the board is, of course, the one who is the creator of the

53
00:04:21,269 --> 00:04:21,560
board.

54
00:04:21,570 --> 00:04:24,300
So created by will be the current user.

55
00:04:25,290 --> 00:04:25,710
All right.

56
00:04:27,360 --> 00:04:34,350
So now we can do the actual creation of the board and firestorm, so Firestorm not create board, and

57
00:04:34,350 --> 00:04:36,990
here we need to Brackett's create board here.

58
00:04:37,000 --> 00:04:38,510
We needed to parse the activity.

59
00:04:38,520 --> 00:04:40,830
So it's going to be this and we need to present the board.

60
00:04:40,840 --> 00:04:42,090
So it's going to be the board.

61
00:04:42,480 --> 00:04:47,670
So you can see this create board function, just prepares everything to then pass it to this create

62
00:04:47,670 --> 00:04:55,050
board function inside of our Firestar class, which does the actual firebase stuff, which does the

63
00:04:55,050 --> 00:04:59,490
actual creation of the collection and then storing it in the cloud.

64
00:05:01,940 --> 00:05:09,740
Now, we also, of course, need a function to upload an image because we want to upload the image to

65
00:05:09,740 --> 00:05:11,030
the storage as well.

66
00:05:11,510 --> 00:05:13,630
OK, so let's create a function for it.

67
00:05:13,640 --> 00:05:17,330
Private fund upload, board image.

68
00:05:19,130 --> 00:05:23,780
And here we show the progress dialogue, first of all.

69
00:05:24,060 --> 00:05:26,440
And I'm going to use the resources here.

70
00:05:26,810 --> 00:05:30,950
So the ones that we've prepared, it's going to be resources.

71
00:05:30,950 --> 00:05:32,060
Get string our string.

72
00:05:32,060 --> 00:05:32,660
Please wait.

73
00:05:33,110 --> 00:05:33,490
All right.

74
00:05:33,500 --> 00:05:36,860
So as we've done before, then we need to.

75
00:05:37,790 --> 00:05:43,550
Reference to storage reference, so we can pretty much get that from the update.

76
00:05:44,600 --> 00:05:47,390
Function here, where we update the image.

77
00:05:50,000 --> 00:05:51,650
So upload user image.

78
00:05:53,130 --> 00:05:55,710
So you can see it's pretty much the same code that we need.

79
00:05:56,850 --> 00:06:05,130
So what we can do is actually copy that and make adjustments to it, so create board activity here.

80
00:06:07,460 --> 00:06:08,000
Let's check.

81
00:06:09,000 --> 00:06:16,200
First of all, we need to Staats reference for the instance here, and it's not the user image, but

82
00:06:16,200 --> 00:06:22,540
it's the board underscore image and here bought on this image is how I'm going to call it.

83
00:06:22,560 --> 00:06:24,330
So this is the name of the image.

84
00:06:24,330 --> 00:06:24,650
Right.

85
00:06:25,230 --> 00:06:28,530
And that file extension will be this.

86
00:06:28,530 --> 00:06:29,280
And here.

87
00:06:30,260 --> 00:06:33,590
We have called it a selected image of war, your.

88
00:06:34,100 --> 00:06:38,680
Let's see, it's this one here at the very top of the same name.

89
00:06:39,140 --> 00:06:39,980
So that is good.

90
00:06:40,220 --> 00:06:41,800
We used the same name in both cases.

91
00:06:41,810 --> 00:06:44,120
This makes our copy and pasting a lot easier.

92
00:06:44,120 --> 00:06:47,450
Now, then we have to put the file.

93
00:06:48,110 --> 00:06:52,970
And it's this file that we have in the URAI, which we have selected on the phone.

94
00:06:52,970 --> 00:06:53,160
Right.

95
00:06:53,180 --> 00:06:58,480
The user has selected an image and then we want to put that file onto our storage.

96
00:06:58,520 --> 00:07:02,150
So the firebase storage and then we have an add on success listener.

97
00:07:02,420 --> 00:07:08,020
We take it to task, snapshot from it, and then we know where the image will be stored.

98
00:07:08,030 --> 00:07:12,490
So, Firebase, let's call this one board image.

99
00:07:12,490 --> 00:07:14,570
Your URL will just be there.

100
00:07:14,570 --> 00:07:21,230
And actually that's a long name to longline for tag board material is fine.

101
00:07:21,380 --> 00:07:23,960
Tusk's snapshot will give us to download your URL.

102
00:07:24,830 --> 00:07:35,810
Then we can take that and store it in our M bought image euro, and then instead of updating the user

103
00:07:35,810 --> 00:07:38,090
profile data, we can create the board.

104
00:07:38,600 --> 00:07:41,630
So create what is called and create board.

105
00:07:41,630 --> 00:07:46,280
By the way, this function, which then calls the first class create board.

106
00:07:47,720 --> 00:07:53,030
OK, so uploading a board image, we also create the board, of course.

107
00:07:54,710 --> 00:07:58,860
So then I don't feel your listener will forget an exception.

108
00:07:58,880 --> 00:08:04,720
Well, here we're just going to say make text this exception message and highlight progress dialogue.

109
00:08:04,730 --> 00:08:06,490
So it's pretty much the same code.

110
00:08:07,430 --> 00:08:09,070
There are only some minor changes.

111
00:08:09,080 --> 00:08:10,880
Of course, we need to change the.

112
00:08:12,080 --> 00:08:13,520
Function that we want to call here.

113
00:08:15,860 --> 00:08:23,570
Now, at this point, we can add an unclick event when the user clicks create board, so when the user

114
00:08:23,570 --> 00:08:26,250
press the button and then click create.

115
00:08:27,080 --> 00:08:30,920
OK, so it's inside this create board activity because that's the activity name.

116
00:08:30,920 --> 00:08:31,180
Right.

117
00:08:31,490 --> 00:08:35,990
And then we have the Ivy board image where we select an image that's good.

118
00:08:36,020 --> 00:08:43,440
So this is pretty much the preparation and now we can go ahead and create the actual board.

119
00:08:43,640 --> 00:08:51,980
So button create what's the name of the button and we add an on click listener here in which we first

120
00:08:51,980 --> 00:08:57,170
of all, check if the selected image is null or not.

121
00:08:57,350 --> 00:09:08,720
So if selected image file your eye is not null, then we want to upload the board image and inside of

122
00:09:08,720 --> 00:09:10,640
upload image we also create the board.

123
00:09:10,640 --> 00:09:10,970
Right.

124
00:09:11,660 --> 00:09:20,590
And then else we want to show the progress dialog, social progress, dialogue.

125
00:09:22,010 --> 00:09:25,090
And here we are also going to say, please wait.

126
00:09:26,060 --> 00:09:29,170
And of course we want to create the board here.

127
00:09:29,660 --> 00:09:31,870
So create board.

128
00:09:33,200 --> 00:09:35,510
OK, so inside of the upload board image.

129
00:09:35,630 --> 00:09:36,710
Also create the board.

130
00:09:36,710 --> 00:09:36,950
Right.

131
00:09:36,960 --> 00:09:41,220
We also call create board, but only if uploading the image was successful.

132
00:09:41,630 --> 00:09:47,750
So basically we're saying, OK, let's select an image and then we enter a board name.

133
00:09:48,120 --> 00:09:55,280
And if that was successful, we create then the board and when we click create only then we do the actual

134
00:09:55,280 --> 00:09:57,620
uploading and storing everything right.

135
00:09:57,650 --> 00:09:59,880
So once we select it, it's just there.

136
00:09:59,880 --> 00:10:00,100
Right.

137
00:10:00,110 --> 00:10:04,280
It's just inside of our selected image file.

138
00:10:04,280 --> 00:10:05,950
You are just going to be there.

139
00:10:06,230 --> 00:10:11,630
And of course, it will be displayed inside of our UI element itself, right inside of this image for

140
00:10:11,630 --> 00:10:11,780
you.

141
00:10:12,310 --> 00:10:18,560
But then the upload process happens once we click the create button, and that's pretty much it.

142
00:10:18,560 --> 00:10:22,850
If we don't have selected an image or didn't select an image and we could recreate, it's still going

143
00:10:22,850 --> 00:10:27,320
to create a new board, but it's just going to use the default image that is there.

144
00:10:31,120 --> 00:10:33,850
Or to be more precise, it's just going to use an empty string here.

145
00:10:34,040 --> 00:10:35,790
It's not even going to be the default image.

146
00:10:37,620 --> 00:10:40,110
OK, at this point, we can test it.

147
00:10:41,660 --> 00:10:43,100
All right, so there we are.

148
00:10:43,350 --> 00:10:45,050
Let's go out and create a board.

149
00:10:46,040 --> 00:10:50,090
Let's first create the board without image board.

150
00:10:52,520 --> 00:10:54,860
Without image create.

151
00:10:56,020 --> 00:10:59,050
Please wait, were created successfully.

152
00:10:59,230 --> 00:11:00,570
Now let's go ahead and check it out.

153
00:11:02,230 --> 00:11:08,440
So let's refresh this page here and see if we now have a new collection here so we should have a new

154
00:11:08,440 --> 00:11:09,010
collection.

155
00:11:13,260 --> 00:11:19,600
And we can see there it is, it says Bortz, now let's see, you can see we get a unique, weird, no

156
00:11:19,600 --> 00:11:25,570
such a random value here for our board because we didn't add any name for it specifically.

157
00:11:25,980 --> 00:11:32,480
And then inside of this board, you can see it's assigned to and this number y Cucu HMG.

158
00:11:32,580 --> 00:11:35,940
Let's look at that y Cucu HMG.

159
00:11:35,940 --> 00:11:43,680
So it's the user ID that we have as a scientist to it is created by the user name, which is Holmer,

160
00:11:44,190 --> 00:11:49,310
and then the image is an empty string here, so we don't have an image for it.

161
00:11:49,710 --> 00:11:52,380
So we will just use the default image.

162
00:11:52,380 --> 00:11:52,650
Right.

163
00:11:53,040 --> 00:11:56,040
And we have the name here, Port Without Image.

164
00:11:56,220 --> 00:11:58,380
That's the name of the board itself.

165
00:11:59,160 --> 00:12:05,070
You could of course, argue that created by Homer is a risky one because it just takes the user name

166
00:12:05,070 --> 00:12:05,970
of the current user.

167
00:12:05,970 --> 00:12:11,810
It's not taking the actual user name from the assigned to value.

168
00:12:11,820 --> 00:12:16,550
So we would then have to, of course, read the assigned to value.

169
00:12:16,560 --> 00:12:23,370
So read this number or this value here and then read the name from that one because the name could change

170
00:12:23,370 --> 00:12:23,940
any time.

171
00:12:23,940 --> 00:12:24,260
Right.

172
00:12:24,690 --> 00:12:26,730
But that's going to be fine for now.

173
00:12:27,420 --> 00:12:30,330
But overall, you can see the board is created and that works.

174
00:12:30,360 --> 00:12:34,140
Now let's go out and create an image or create a board with an image.

175
00:12:35,620 --> 00:12:39,190
So let's click the create button and select an image here.

176
00:12:40,360 --> 00:12:45,610
All right, so I'm going to use an image from here, select this photo.

177
00:12:46,240 --> 00:12:49,840
Give it the name bought with image.

178
00:12:50,110 --> 00:12:52,960
So I'm going to call it stupid name, but still good enough.

179
00:12:53,650 --> 00:12:56,350
And now let's see if this new board was created.

180
00:12:56,350 --> 00:12:59,540
We see or created successfully and it's there.

181
00:13:00,100 --> 00:13:00,520
All right.

182
00:13:00,520 --> 00:13:01,580
So there it is.

183
00:13:01,840 --> 00:13:03,850
We also have this image here.

184
00:13:04,000 --> 00:13:07,290
So let's get this whole image and put it in there.

185
00:13:08,620 --> 00:13:11,160
And we can see the images there as well.

186
00:13:13,270 --> 00:13:15,830
OK, so now you can see how you can create boards.

187
00:13:15,850 --> 00:13:19,010
I hope you manage to get some of this done by yourself.

188
00:13:19,030 --> 00:13:25,750
It was a lot of copy and pasting or reusing what we have done before, but it's still good practice

189
00:13:25,750 --> 00:13:26,810
to just try it yourself.

190
00:13:27,250 --> 00:13:27,670
All right.

191
00:13:27,670 --> 00:13:29,770
So thanks a lot and see you in the next video.

