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

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:
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?
Here is the blocks code for the getWeb function to get the JSON data:
Please advise, with a block code if applicable.Thank you all.

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.
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".
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...
What is the purpose of that join block? You might want to remove it...

Related

Android FireBase OnDataChange code not being permanant

enter image description here
I get the followingg Toast outputs
CODE IS RUNNING
and
s
So my code is running but my_shop is not being changed?
Your code is working fine, I think you are a bit confused as to how the code above actually works. the onDataChanged method is triggered/called asynchronously ONLY when the data in the database/server changes, hence the toast-'CODE IS RUNNING' is displayed correctly.
But you are checking the my_shop.getShop_name() outside the onDataChanged method, hence by the time the program counter reaches the second toast, the onDataChanged method hasn't been called yet. The shop_name is still the one that you assigned in line 2 which is what is displayed on the Toast! (which is why you think the code isn't running properly even if it is working fine!)
I would suggest you read more about event listeners in general to get a better idea abouut this behaviour! you can read more about the API in the firebase documentation: https://firebase.google.com/docs/database/android/read-and-write

Can i start a new Thread for every character entered in EditText for searching

Good Afternoon, I have a question please have look at this.
I am using Retrofit beta 2 for retrieving data from api. I have an EditText in which I want to search some names from server. I got the output also, but for example consider there are some names:
ABC,XYZ,PQR,STU,ETC. These are the names stored in the server and I am retrieving this names using Retrofit beta2.
When I searched for ABC or abc it will display the results and when I removed the string from the EditText then nothing is displayed.
Till here I Have done.
My question is when I type names fast then the result is something else.
So, can anyone tell me how to avoid this.
Thank You.
The Call object has a couple of utility methods you can use namely isExecuted and cancel to control your request.
http://square.github.io/retrofit/2.x/retrofit/retrofit2/Call.html
I am assuming you are using TextWatcher. Pseudo-code as follows:
public void afterTextChanged (Editable s) {
// Cancel the request first before sending it again; this way you won't have two separate calls
if(call != null && call.isExecuted()) {
call.cancel();
}
// reinitialize call and execute it again
}
Generally speaking, it is ill-advised to listen for immediate input from user to spawn an action: you should rethink your approach; it's better to put a "submit" or button to execute the API call; otherwise you'll be spamming the server with several HTTP requests per input.
Remember the search text e.g. "AB" on the search result. Before displaying the result, check if the currently entered text still matches the text of the search result and only use the result, if it does.
Searched for "AB", current text "ABC" -> don't show the result.
Searched for "ABC", current text "ABC" -> show the result.
Like this it won't even matter in what order the two requests return, it will always display only the correct result.
I think it is not safe to start a new thread for every character
This is How I did in my App:
You can use a Queue to store every string that user input. Every time the edittext changed, a new string will be inserted to the queue
At the same time, you can send the query async by retrofit. but if the retrofit is on its way querying, you do not send immediately, only put the string into the queue. when your callback function is called by retrofit, you can remove all strings from queues except the latest one, then use retrofit to query this newest query.
Too much thread, will affect the performance of any device, because it the overhead involve will consume lot of resource.
starting a new thread for each character is by no means advisable, to answer your question each thread should continually check for a change in characters, when you type fast, it mean tend to skip some result but will eventually display the result of the last string correctly.

How to check if a tinyDB tag has any attributes in App Inventor

I need a little help with an issue in App Inventor 2. The case is that I have a JSON result that is parsed, and then have it stored in a tinyDB tag as a list (storeparseData).
Problem is that, I have this function done as screen initiates, so to have the tinyDB tag populated with that JSON list and then searched for a specific value on user request.
As the app is running and I input a search criteria, I get the following error "The arguments [empty-string] are the wrong number of arguments for GetValue". I suppose that, it finds nothing yet to be stored in the tinyDB tag to search for, cause the JSON data take some time to be fetched and parsed.
Here is what I have done for now for checking if the stored list is in the tinyDB:
Here I check the stored list in tinyDB for an item:
So how can I check if the tinyDB is populated in this tag with the JSON results list, so I can then have it searched? Is this possible in App Inventor 2?
Please someone advise on this issue with a sample code blocks if possible, or a similar tutorial, if there is any. Thank you all in advance for your answers.
This looks very strange... a complicated if then else structure, loads of empty sockets and your comparison if "storeparsedData" = <empty string> always will be false... obviously this does not make sense...
it looks like you are thinking too complicated?
what about this:
As already recommended in my answer to your other question you should learn how to work with lists...
how to work with lists
how to work with list of lists (pdf) by appinventor.org
see also An example of a complex List of Lists
Also doing some more tutorials might help to learn some more basics...
To answer your question "Can you explain why you've chosen to create an empty list there.": if you are working with lists as in the example and you are trying to read a list from TinyDB, then you also have to think about what should happen, if that tag is not available in TinyDB (for example after starting the app the first time). And for lists, in this case an empty list should be returned. Note: the is list empty? block always expects a list. If you set valueIfTagNotThere to an empty string, then you will get a runtime error...
You can use Clock function to delay the time. Firstly, just set the global DelayCountdown to specific number in "when Screen1.Initialize" part. Then, by using "when Clock1.Timer" function, you just need to add another check whether the DelayCountdown is equal to zero before you do another function.

Problems with Listpicker App Inventor

I'm a beginner at App Inventor and I don't know what I'm doing wrong with the listpicker.
I am trying to create and app to reproduce the music I have stored in my server but when i display the listpicker I can't click any of the options and also I can't go back to the first screen. Here I put my code:
Image 1
Image 2
I tried to remove the line that says call listpicker.open but it only made appear a totally black screen.
The result of the code I just posted is exactly what I spect a list with the name and the link of the 2 songs I already upload to my server but when I click them it didn't do anything.
Thanks for your help.
The Web component works asynchronously, which means, it takes a little bit, until the result is available. The result you will get in the Web.GotText event.
Therefore it does not make sense to call the updateListpicker procedure in the Listpicker.BeforePicking event, because the result still is not available and you get displayed an empty listpicker. The listpicker will be opened, before you have received the result!
Set the listpicker to visible=false and use a button.click event to call the updateListpicker procedure. Then as you already do it in the Web.GotText event, assign the received list to the listpicker and open it.

How to present parsed JSON in readable format to users?

So I have JSON, I parsed in and it's sitting there. From my code below it looks like I have put everything into an ArrayList but then what? I mean for example I need the "title" of each JSON object to be an onClick on the first page, is that possible?
Essentially my onPostExceute() is empty/not doing much. Eventually I need to separate each object into it's own page via the onlicks I'm mentioning, but I think I can do that by separating the JSONObjects...? guess I'll come to that when I can.
If I want to separate things should I even be using an ArrayList? It's just what I used for a server test I ran with different code.
Would really appreciate some help. Basically stuck at the last hurdle is how I perceive it. Maybe I'm wrong though. The logs see that the JSON is showing up as one big chunk.
Edit: Removed my code, this is more of a theory question. ListView being the best thing to go with.
yes you can make spearate arraylist for them..and can store them in diferent listviews...on google click you can open new listview showing id and link for google ..and same you can do for microsoft and your other trem.And using onItemClick is a gud option,you can easily get the index of item clicked//

Categories

Resources