Welcome back.
In this video, we are going to implement a custom progress dialogue, as we have done multiple times
already when something happened in the background and now you already should know when things are happening
in the background, because that's really what we prepared in the last few videos.
So, for example, when we do NQ here, so pretty much when we wait for the callback of the weather
response, that is something where we should potentially display the dialogue.
And then at one point we should hide the dialogue again once it's done downloading or once we have a
response.
Pretty much.
All right.
So please try to implement this yourself, post the video.
And if you don't know how to create a custom progress dialogue, then check out one of the chapters
where we did that, because we have done it already multiple times.
So I think it really makes sense for you to try it yourself.
All right.
So therefore, we are, first of all.
Required to add a new layout, so here.
Right, click new play out resource file, and I will call this one dialogue, custom progress.
All right, and I'm not going to go over everything that we're going to build in here basically is just
going to be what we've done multiple times before, as I said.
So it's going to be a linear layout with a progress bar and a TextView.
But you can already see I'm using dimensions here, so I'm using dimensions for the progress bar size,
its margin that I'm using a string here.
So we are going to add those to our values as well.
So go over to your strings.
And here we will need to add one string, which is just to please white string.
So what I'm going to add here is the following, which will be please wait.
And then this will be.
Three horizontal dots, so a dot, dot, dot, so to speak.
OK, then we can go ahead and add the dimensions so we don't have an example, five, four dimensions
here.
I'm just going to create a Dimond's XML.
And in here, I'm just going to add the four dimensions that we need, so main content, putting progress
dialogue, which I said to ten density pixels, progress, bar size, progress, bar margin and and
progress, bar text size.
And these are the ones that we need in the dialogue, custom progress.
All right.
So that's pretty much it for the customer dialogue.
Now we can create the code for it.
So I'm just going to create a variable here for, first of all, a global variable, which will be our
dialog.
All right.
So here private var and progress dialogue, which will be of type dialogue, nullable.
So I'm going to set that to now.
For now.
And then I need to import dialogue here and now I can go ahead and create the functions for it.
So let's go ahead and create our functions down here.
At the very bottom one will be to show the custom dialogue, so show custom progress, dialogue.
And I think it really doesn't make sense for me to type this because we have typed this so many times
already.
So show custom progress dialogue, which will just set our progress dialogue variable that we just created
to be a dialogue.
Then we set to continue to be our dialogue, custom progress, which is this XML file that we prepared.
So it's going to look like this what you can see here.
All right.
And then we say it should be shot.
Now, of course, after we have edited the show functionality, we also need to add the Hyde functionality.
So I'm going to add another function here, which will be hi, progress dialogue.
So will check if the progress dialogue is not now.
And if that's the case, then I want to dismiss this dialogue and that is a function of dialogue.
All right.
So this myth, of course, is this function in dialogue that Java, which simply closes this progress
dialogue in our case.
Now comes the interesting part, because so far, this really basic stuff at this point, because you
have seen it already multiple times and probably also implemented it multiple times, now we have to
find good spots where we want to, for example, show the progress dialogue and where we want to hide
it.
So showing it will be when we get the weather, location, location, weather details.
So at this point, we want to know the weather for a specific location.
And at this point, we also do something in the background.
Right.
So here we prepare everything.
And then finally, when we unskewed, that's the point where we actually do something in the background.
OK, so here.
Just before that, before we start and queuing or downloading something, that's where I want to show
my.
Constant progress, dialogue.
All right, and then what would be the good points to close it again?
Well, as soon as we get a response here.
So if the response is success, for example, then I want to hide it.
So I'm just going to say, right, progress dialogue, which is my function, the word I just created.
And then another good spot to hide it as well is going to be on failure.
All right.
So here we also want to hide our progress dialogue.
So either when it worked and we have a successful response or when we had a failure and it didn't work.
All right.
And now at this point, we should be able to see our progress dialogue once we start the application.
And we thank you.
Which means we download something.
So that we saw it for a very short amount of time, and that is because we really just don't know something
super small and we have a good connection.
So that is our current environment.
Of course, we could test how it would behave if we have different Internet connections.
OK, so here let's say we have only GPCRs.
So it's 1G or something like that.
I think just to GGP should be 1G.
So if we test that again with this super bad Internet connection, then it could potentially take a
little longer for you to download even this little file, which is just a couple of kilobytes.
Right.
All right, even there, I think the file is just too small, but when it comes to bigger files, then
it's a different story, right?
So here maybe it's also because we have Wi-Fi.
So let's turn that one off.
Let's go to GPS again.
Let's test it once again.
All right, there we are.
So you can see now what a bad Internet connection with GPS, this takes a lot longer.
So it's still disappeared, but it took multiple seconds.
I mean, you should never have the situation where you only have GPS.
I hope you should at least have urged no matter where you are.
But I don't know, maybe in some places it's still the case that the best Internet connection that you
will get is going to be GPS.
Now, let's take a with edge just to see how much quicker it will be.
So let's run it again.
Can see even edgeways brother first.
So you should always have a rather good connection.
OK, so that is something that you should check out as well, just seeing how good your Internet connection
will be and play around with it just to see the influence that it has on your application.
Especially when it comes to downloading something in this case, we're just downloading a couple of
kilobytes, but let's say you're downloading a file, a video file or an image, then this could really
have a huge impact on your app.
All right.
So I'd say let's go to the next video.
You.