‫Hello, my friends, and welcome back.
‫In this video, we will set the functionality for saving the Journal.
‫So here in the binding dot apply I will use the save button.
‫Dot set on Click Listener.
‫And in this setting click listener, I need to call the method Save journal.
‫And of course I will create it here.
‫Create function.
‫I want from you to concentrate with me in order to get things more and more simple and easy to understand.
‫So this saved journal function will do the job of getting all the data from here.
‫The image, the text views, the edit text and click.
‫When the user click on it, the save button.
‫It will execute and save all of this stuff in the journal Storage for Firebase Storage and.
‫We will check for the validity of the user action.
‫Let's start with string title.
‫Var title is of type string equal title dot get or binding.
‫Dot.
‫Title.
‫Dot text dot to string dot trim.
‫Again.
‫Var thoughts type string equal to binding dot.
‫Thoughts or post.
‫Description et dot text dot to string dot trim.
‫Now let's set the progress bar visible.
‫So binding dot progress bar dot visibility equal to view dot visible.
‫Let's show the progress bar to the user when saving the journal.
‫Now if.
‫The text utils.
‫Is empty for the title.
‫And for.
‫The image you and the image you are.
‫I.
‫They are not null.
‫We can go and save things.
‫Otherwise we can't go and save anything on the firebase.
‫If there is an empty edit text here, edit text here, empty or empty image.
‫So please guys check this text utils dot is empty thoughts and if there is.
‫No image, you or I equal to null.
‫Then we go and proceed.
‫So the three things, the three conditions must be true in order to go and save the data on the firebase.
‫Now.
‫Saving the path of the images in storage here.
‫Saving.
‫The path.
‫Of images in storage.
‫From where we are going to use this storage journal.
‫Underscore images underscore our image dot PNG.
‫So what we are doing here, we're going to save the images in the firebase storage.
‫So we use authentication, we use Firebase Firestore for getting the data and saving the title and thoughts
‫and we are going to use the storage in order to allow the user to upload images and display them here.
‫So for that I will create Val storage.
‫A reference.
‫Storage reference or file path, I will name it as file path.
‫It's of type storage reference equal to storage reference dot child.
‫What is the child its journal underscore images you can see this is the folder and we need to create
‫a child also.
‫My underscore images or my image underscore and the timestamp for this.
‫So time stamp.
‫Dot now.
‫And make sure when using the timestamp to import that of fire base and not the Java.
‫Okay.
‫So timestamp dot now.
‫Okay.
‫This is the.
‫The the algorithm behind saving our images.
‫Inside the Journal images folder, you can see this child and our image, my image plus the time stamp
‫dot now dot get seconds.
‫Okay.
‫Now let me upload the image here.
‫Uploading the images.
‫File path.
‫Dot put file.
‫And here I will pass the image.
‫I dot add on success listener and here I will override on success.
‫And you can see that it is upload task dot upload or task snapshot.
‫Okay, so we'll get the data from it.
‫Dot get download URL.
‫Dot add Onsuccess listener.
‫Again, I need to go to here another success listener.
‫And now the it is you or I.
‫I will start with a string image.
‫Uri.
‫A var image.
‫Uri.
‫Its type is of string equal to Uri.
‫Dot to string or it here.
‫Dot to string.
‫Then creating.
‫The object of.
‫John.