1
00:00:00,450 --> 00:00:06,660
Welcome back and this video, we are going to add the functionality to select an image for our board

2
00:00:06,990 --> 00:00:10,260
and then it should replace the image.

3
00:00:11,470 --> 00:00:16,930
In our report itself, as you can see here, so you can try to build this yourself, you have seen how

4
00:00:16,930 --> 00:00:18,490
to do that with the profile image.

5
00:00:18,490 --> 00:00:20,220
It's pretty much the same functionality.

6
00:00:20,500 --> 00:00:26,130
And what I'm going to do is I'm going to put some function to the constants class.

7
00:00:26,500 --> 00:00:32,650
So instead of having everything in mind, my profile activity, I'm going to use those two functions

8
00:00:32,650 --> 00:00:38,110
and put them at the constant rate that I can reduce them in both my classes, in the board class and

9
00:00:38,110 --> 00:00:40,000
also into my profile activity class.

10
00:00:40,540 --> 00:00:43,000
All right, so good luck with trying Trinder.

11
00:00:44,160 --> 00:00:45,780
OK, so let's get started.

12
00:00:46,170 --> 00:00:55,640
I'm going to put those two functions into my constant qty, going to need the activity here.

13
00:00:56,670 --> 00:01:00,940
So in which activity do I need to start the activity for result?

14
00:01:01,560 --> 00:01:04,870
The same goes for our CAD file extension.

15
00:01:05,730 --> 00:01:09,440
So here, activity, activity.

16
00:01:09,930 --> 00:01:16,280
So the thing is, when we want to get the content or the content resolver or start an activity, for

17
00:01:16,290 --> 00:01:19,330
example, we always need to know from which activity we should do that.

18
00:01:19,890 --> 00:01:22,380
So that's why we need to add those.

19
00:01:22,740 --> 00:01:24,160
And these are the two functions.

20
00:01:24,180 --> 00:01:33,000
So this to show image chooser and file extension that we can get out of our my profile activity and

21
00:01:33,000 --> 00:01:37,920
use in both of our mopac, my profile activity, as well as in our create board activity.

22
00:01:40,400 --> 00:01:46,610
So in here and what I also need to change is that it's not my profile activity in which I want to have

23
00:01:46,610 --> 00:01:51,560
the pig image request code, but I want to have it inside of my conscience itself.

24
00:01:52,100 --> 00:01:59,630
OK, so let's go over to my profile activity and take the two constants from our object here from our

25
00:01:59,630 --> 00:02:00,710
companion objects.

26
00:02:00,710 --> 00:02:07,520
Get rid of this companion object and put it inside of our constants directly here.

27
00:02:08,000 --> 00:02:11,960
And by the way, we need to get rid of private so that we can use it in other classes as well.

28
00:02:12,770 --> 00:02:20,660
OK, so now we can go ahead to our my profile activity and used it to functions from the constants.

29
00:02:20,810 --> 00:02:25,220
So constants that show in chooser.

30
00:02:26,690 --> 00:02:30,730
And I need to pass on this because show image user now needs an activity.

31
00:02:31,020 --> 00:02:36,950
And by the way, I'm doing this really just to reduce the duplicate code as much as possible.

32
00:02:37,220 --> 00:02:42,650
OK, so if you were wondering why I'm even doing this, OK, so then read storage permission code is

33
00:02:42,650 --> 00:02:44,360
in constants as well then.

34
00:02:44,360 --> 00:02:45,550
I have another error here.

35
00:02:45,650 --> 00:02:49,280
Same story constants that read permission code than here.

36
00:02:49,280 --> 00:02:55,100
Constants that show image user needs the activity as well.

37
00:02:57,040 --> 00:03:04,570
As well as this part concerns image request codes and then finally going down here, get a file extension

38
00:03:04,960 --> 00:03:08,530
is also in the constants class, don't get far extension.

39
00:03:08,800 --> 00:03:16,060
And there will also need to pass this as the activity that will be used and get file extension, because

40
00:03:16,060 --> 00:03:18,100
you can see it needs activity to.

41
00:03:19,100 --> 00:03:28,910
Get the content resolver, so now the thing is now our functions are prepared so that we can very easily

42
00:03:28,910 --> 00:03:30,330
copy them and reduce them.

43
00:03:30,350 --> 00:03:38,270
So, for example, I want to copy the objectivity result and on the on request permission result, those

44
00:03:38,270 --> 00:03:38,660
two.

45
00:03:39,020 --> 00:03:41,240
And I want to copy them into my.

46
00:03:42,270 --> 00:03:46,210
Create board activity, so let's put them in here as well.

47
00:03:50,780 --> 00:03:58,070
And now I need to make some changes, of course, so it's not this at the other activity, but it's

48
00:03:58,070 --> 00:04:05,390
just this as well as selected image file, your eye is a variable that we need to create still.

49
00:04:06,080 --> 00:04:14,200
So let's go ahead and create a private, far selected URAI, which is going to be a nullable, which

50
00:04:14,240 --> 00:04:15,140
is just going to be now.

51
00:04:16,910 --> 00:04:17,390
For now.

52
00:04:19,380 --> 00:04:19,920
And then.

53
00:04:21,329 --> 00:04:24,810
When we look at the code, no more errors.

54
00:04:24,840 --> 00:04:28,330
All right, so then we, of course, need to start the activity.

55
00:04:28,350 --> 00:04:29,890
And when do we start the activity?

56
00:04:29,910 --> 00:04:36,090
Well, once we click on the image, so it's very similar to what we have done in our mind profile activity

57
00:04:36,390 --> 00:04:46,250
where when we click on the image, which is this one, I've profile user image, we do all of this code.

58
00:04:46,260 --> 00:04:52,210
So we basically can copy this code from here and put that into our create board activity.

59
00:04:53,040 --> 00:04:59,220
So here in Uncreate, we can now put this code because we are checking for permission.

60
00:04:59,220 --> 00:05:06,600
Then we are opening show image user and then we are using restarts, permission codes in order to request

61
00:05:06,600 --> 00:05:08,330
the permission if we don't have it and so forth.

62
00:05:09,060 --> 00:05:16,070
And of course, we only want to execute this code here once we click on the board image.

63
00:05:16,650 --> 00:05:19,620
So set on Click Listener.

64
00:05:22,190 --> 00:05:22,760
And.

65
00:05:23,790 --> 00:05:26,970
What we want to do is all of that once we click on the image.

66
00:05:29,250 --> 00:05:35,760
And then, of course, when we get to activity result, we need to be careful with Glide, so now we

67
00:05:36,030 --> 00:05:37,960
want to use a different placeholder.

68
00:05:38,100 --> 00:05:39,540
So here we're going to use.

69
00:05:39,540 --> 00:05:40,410
I see.

70
00:05:41,660 --> 00:05:50,420
Board place placeholder, this one here, as well as we want to put it into, I've bought image, this

71
00:05:50,420 --> 00:05:50,870
one here.

72
00:05:52,330 --> 00:05:58,330
OK, so that's the thing when you copy and paste, you have to be careful with the minor changes that

73
00:05:58,540 --> 00:06:00,760
still occur or need to be edited.

74
00:06:02,020 --> 00:06:05,980
So at this point, we should be able to test this.

75
00:06:08,440 --> 00:06:10,510
All right, so that we are.

76
00:06:11,840 --> 00:06:15,980
Let's create a new board, let's select an image.

77
00:06:17,800 --> 00:06:19,090
The one from the camera.

78
00:06:20,200 --> 00:06:22,420
And that we are OK.

79
00:06:22,690 --> 00:06:28,030
So that is it, because we used the same functionality as we used for the profile image.

80
00:06:28,060 --> 00:06:30,560
Of course, we're not permanently storing it for now.

81
00:06:30,580 --> 00:06:33,340
We're just getting it and displaying it in here.

82
00:06:33,610 --> 00:06:38,140
But when we press to create button, of course, nothing will happen, but that's what we will implement

83
00:06:38,140 --> 00:06:39,190
in the next video.

84
00:06:39,820 --> 00:06:40,290
All right.

85
00:06:40,510 --> 00:06:45,490
So I hope you managed to get most of this done by yourself and see you in the next one.

