Search code examples
androidjsonprogressdialogapp-inventortinydb

Proper way of using ResultNotifier.ShowProgressDialog in App Inventor 2?


Expanding the functionality of an under development app, I need to show to the user a progress notification dialog. Problem is, I cannot get it done right. Furthermore, I cannot dismiss this notifier properly. Have tried with a clock and a variable set to e.g. "5000ms" and then to "0", without any lack.

What I need to achieve is the following functionality:

a. Check if the tag "storeparsedData" is in a TinyDB, populated with the fetched JSON data. I have this done, following @Taifun advice in my relative question.

b. If the tag is not there (empty list), do a getWeb.gotText block to get the JSON data (this is done with procedure "getWebData". This functions right, but takes a while about 1'35'' or more, so need to show something to the user.

c. While fetching JSON data form web, need to show a "ShowProgressDialog" notifier to the user, so I can cope with the smartphone being seemingly freeze.

d. If the tag "storeparseData" is populated with fetched JSON data, dismiss the notifier.

Have tried the following coding, without relevant success:

enter image description here

Can someone help me out, to achieve this functionality in this app? A blocks code or something to follow and learn, will be awesome. Thank you all in advance for your answers.

[Edit1]

After @Taifun suggestions, the functionality in question seems to be working, but there is a problem."ShowProgressDialog" block never fires, neither on device or companion. Also where should block "DismissProgressDialog" be attached to disable notifier upon JSON data received?

Here is the reviewed blocks code, for checking stored tags in TinyDB. "ShowProgressDialog" never fires as it should. Are there any suggestion for this issue?

enter image description here

Here is the blocks code for the getWeb function to get the JSON data:

enter image description here

Please advise, with a block code if applicable.Thank you all.


Solution

    1. Your progressNotifier.AfterChoosing event never will fire, because that event only fires after choosing something from a Notifier.ShowChooseDialog block, but not for Notifier.ShowMessageDialog blocks. Therefore use a Notifier.ShowChooseDialog block instead and set the second button in that block to empty string.

    enter image description here

    1. Your while loop will freeeze your app, as you already realized... You do not need the Clock.Timer event at all to check if your data is there.

    Just do it like this: after having received your data in the Web.GotText event and having stored the data in TinyDB, then dismiss the progress dialog and display the message "Database is ready".

    enter image description here

    Update: Instead of storing your list n times inside the for each in list loop, you should store it only once after the for each in list loop is finished... Same for the DismissProgressDialog and ShowAlert block...

    enter image description here

    What is the purpose of that join block? You might want to remove it...