Welcome back and this video, we are going to add the functionality to select an image for our board
and then it should replace the image.
In our report itself, as you can see here, so you can try to build this yourself, you have seen how
to do that with the profile image.
It's pretty much the same functionality.
And what I'm going to do is I'm going to put some function to the constants class.
So instead of having everything in mind, my profile activity, I'm going to use those two functions
and put them at the constant rate that I can reduce them in both my classes, in the board class and
also into my profile activity class.
All right, so good luck with trying Trinder.
OK, so let's get started.
I'm going to put those two functions into my constant qty, going to need the activity here.
So in which activity do I need to start the activity for result?
The same goes for our CAD file extension.
So here, activity, activity.
So the thing is, when we want to get the content or the content resolver or start an activity, for
example, we always need to know from which activity we should do that.
So that's why we need to add those.
And these are the two functions.
So this to show image chooser and file extension that we can get out of our my profile activity and
use in both of our mopac, my profile activity, as well as in our create board activity.
So in here and what I also need to change is that it's not my profile activity in which I want to have
the pig image request code, but I want to have it inside of my conscience itself.
OK, so let's go over to my profile activity and take the two constants from our object here from our
companion objects.
Get rid of this companion object and put it inside of our constants directly here.
And by the way, we need to get rid of private so that we can use it in other classes as well.
OK, so now we can go ahead to our my profile activity and used it to functions from the constants.
So constants that show in chooser.
And I need to pass on this because show image user now needs an activity.
And by the way, I'm doing this really just to reduce the duplicate code as much as possible.
OK, so if you were wondering why I'm even doing this, OK, so then read storage permission code is
in constants as well then.
I have another error here.
Same story constants that read permission code than here.
Constants that show image user needs the activity as well.
As well as this part concerns image request codes and then finally going down here, get a file extension
is also in the constants class, don't get far extension.
And there will also need to pass this as the activity that will be used and get file extension, because
you can see it needs activity to.
Get the content resolver, so now the thing is now our functions are prepared so that we can very easily
copy them and reduce them.
So, for example, I want to copy the objectivity result and on the on request permission result, those
two.
And I want to copy them into my.
Create board activity, so let's put them in here as well.
And now I need to make some changes, of course, so it's not this at the other activity, but it's
just this as well as selected image file, your eye is a variable that we need to create still.
So let's go ahead and create a private, far selected URAI, which is going to be a nullable, which
is just going to be now.
For now.
And then.
When we look at the code, no more errors.
All right, so then we, of course, need to start the activity.
And when do we start the activity?
Well, once we click on the image, so it's very similar to what we have done in our mind profile activity
where when we click on the image, which is this one, I've profile user image, we do all of this code.
So we basically can copy this code from here and put that into our create board activity.
So here in Uncreate, we can now put this code because we are checking for permission.
Then we are opening show image user and then we are using restarts, permission codes in order to request
the permission if we don't have it and so forth.
And of course, we only want to execute this code here once we click on the board image.
So set on Click Listener.
And.
What we want to do is all of that once we click on the image.
And then, of course, when we get to activity result, we need to be careful with Glide, so now we
want to use a different placeholder.
So here we're going to use.
I see.
Board place placeholder, this one here, as well as we want to put it into, I've bought image, this
one here.
OK, so that's the thing when you copy and paste, you have to be careful with the minor changes that
still occur or need to be edited.
So at this point, we should be able to test this.
All right, so that we are.
Let's create a new board, let's select an image.
The one from the camera.
And that we are OK.
So that is it, because we used the same functionality as we used for the profile image.
Of course, we're not permanently storing it for now.
We're just getting it and displaying it in here.
But when we press to create button, of course, nothing will happen, but that's what we will implement
in the next video.
All right.
So I hope you managed to get most of this done by yourself and see you in the next one.