The problem
I would like to make a progress bar like in this image:
The desired behavior is:
- When user clicks the button, the dark gray progress bar appears and starts to get incremented at a constant pace. I want to be able to determine how long it will take for it to completely fill (like 2 seconds).
- If the request arrives BEFORE the progress bar has reached 100%, the progress bar should go straight to 100% (not within a frame, but it should grow very quickly, like it happens in the windows file explorer, when it's loading something and finished when the progress bar is not at the end yet).
- If the request doesn't arrive before the bar reaches 100%, let it reach 100%. If at 100% (i.e. past 2 seconds) the request has not arrived yet, a timeout happens (I will make a snackbar appear; don't worry about this, I know how to do it, it's just for clarification).
What I found so far
I found this article that sort of exemplifies what I want. Are there any issues with that approach? Also, that example does not show how to customize the progress bar (in my case, i want it with gray color at the top of a view with curved corners). But what I would mostly like to know is if the approach from that link is a good one.
My guesses
My main concerns are about the "quick filling" that happens when the request has arrived but the progress bar is not at 100% yet (which I presume will be the majority of the cases; it's very unlikely that the request arrives precisely at 100%).
Taking what is said in the link, I was thinking that, when the request arrives, the method doSomeTasks
should return the progress bar status + 1 within a small interval. So, in example, if it's at 55, it would return 56, 57, 58...Until 100 and the returns would have a interval of, say, 0.5 second between them. This way, I think I could simulate the progress bar quickly growing to 100%.
Any help is greatly appreciated, thanks!