I am new to android. In my android app, I showing the products list. Now I can sync all the products with a single API call. In slow networks, the app getting broken with the timeout error. I want to sync the products by chunks of data and I want to show a loader also. How can I achieve this?
Thanks in advance.
You're looking for something called Pagination. You can get a specific list/chunk of products from your API with a specified 'page' parameter. The 'page' parameter usually starts off with a value of 0 (page=0), then when the user scrolls to the bottom of the list, you increment the 'page' parameter and get the next chunk of data (page=1), So on as the user scrolls to the bottom of the list.
To show a lading to let the user know of data being loaded from the API, simply use a progress bar that can be shown whenever the API call is in progress and hidden when the API call is finished.
Related
What's the correct logic for updating a view on user event ?
Let's say :
In an app who didn't use cache (Room for example).
A list of object is displayed in a recyclerview. User touch the cross to delete an element.
What to do ?
Case 1 : Send a request to the server for deleting this element and on 200 response, updating the recyclerview (So delete locally the element in list after request). Which can lead to a slow experience depends on the internet connection quality.
Case 2 : Delete locally the element, notify the recyclerview and after that sending the request (So it's completely transparent for the user). In few cases the response can fail (timeout, etc.) so it's necessary to reinsert the element in the list and notify again the recyclerview.
As a young developer, I don't know which way to choose. I have a preference for the second case because the negative side is rarer but I am not sure of myself.
Thank's for your answer.
How to create offline first RecyclerView in Android so the users still can see the list when they don't have any internet connection?
I already know how to get parse JSON and populate it in RecyclerView, the problem is, users still can't access it when offline. And if I use cache using SQLite, how to update only the latest data from the server?
for example, I already got 3 data from server and populate it in RecyclerView like this:
Data 3
Data 2
Data 1
After that, there is an update from the server so there are 4 data from the server. I only want to add the 4th data without load from the 1st. And its going to be like:
Data 4 --> only add this to the RecyclerView without reload past data
Data 3
Data 2
Data 1
Regards,
Elmer
I have done something similar in this project:
https://github.com/isaacurbina/MyMovies/blob/master/app/src/main/java/com/mobileappsco/training/mymovies/Fragments/ResultsFragment.java
Basically, I use an AsyncTask to load data as the user scrolls down, loading more content (kind of like 9GAG or Pinterest do) managing a "page" counter.
Then, as I receive the data, I join it to the List object using list.addAll(results), being results another ArrayList<> of the same kind.
Then you can use adapter.notifyDataSetChanged() on your RecyclerViewAdapter and it will add them super fast, or you can use an animation to show them being added slowly.
I hope it helps, kind regards!
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...
I have made an app where it opens up an online api(?) database. I used the ListView widget where each entry (name of something) clicks onto a new activity. I would like to know how to go about extracting data from the database and putting it in my app for example; if I were to get reviews about a shampoo showing on the page and also a picture of the shampoo etc.
Sorry if I make no sense.
It would have helped if you post some of your code.
According to what I understood is that you want to download data from server and show it into your list view.
What you can do is you can hit API in Asynctask. Put each item data like text, image URL etc into one bean class (setter getter) and add that bean into your list attached to your adapter.
Then you can call notifyDataSetChanged() on your adapter.
I have got ListFragment in my application.
And I got 2 possible situations:
When data is loading (from internet or database)
When data count is zero
So, what is the best way to show that to user?
I have tryed to use #android:id/empty but it is showing in both of situations. I can not control its behavior.
My suggestion would be:
1. Spinning progressbar while the data is loading
2. a short toast stating "No data" or something meaningful if the list is empty.