Paginated list refresh with maintaining scroll position - android

I'm wondering how it can be handled.
I have a paginated list that needs to be refreshed pretty frequently. If I go to details of an item, and then back, I'd like to have current data but not lose everything I fetched previously (for example, if I fetched 3 pages I don't want to refresh only the first one). I think that is a common case, but I'm not sure how other people solve it.
My propositions:
Always refresh no matter what and ignore scroll position.
Request changes that happened between the last update and the current time from the backend.
Don't refresh anything, just inform the user that the list may not be up to date, and give the user button for refreshing if they want.
Send push from the backend every time something changes and handle it in the app.

What I suggest for your problem is either of the 2 solutions -
Refresh the screen but before refreshing take a note of the scroll item user was viewing previously, and then refresh the list and scroll to the item if found in the list else just scroll to the top and show a message "List has been refreshed".
Request changes that happened between the last update and the current time from the backend and then update the list accordingly same as the first solution.
The second approach is much improved and optimised if your backend permits that.
Happy to help,
Thanks & Happy Coding

Related

RecyclerView item inserted with item updated is skipping inserted animation

I have a basic RecyclerView setup on a chat-like app and I have hit an issue with the item animations.
The project is making use of Room with Paging 3 and DiffUtils for the RecyclerView adapter, so this is all automated, but the core of the problem can be simplified to this:
When I send a new message, that message is added to the RecyclerView
here the adapter is triggering notifyItemInserted or notifyItemRangeInserted which causes the entire message list to shift up softly and the new message fades in after
I scroll the list to the bottom so the new added item becomes visible
When I receive a read status from the server I update the status of that message
here the adapter is triggering notifyItemChanged or notifyItemRangeChanged which has no default animations on its own, it just updates the item with the new information
All of this is working well on its own, but the problem is when I receive a status update from the server faster than the insert animation has a chance to finish. When that happens the notifyItemChanged or notifyItemRangeChanged kicks in and skips the animation initiated by notifyItemInserted or notifyItemRangeInserted. The list till shifts upwards, but the fade in no longer happens, instead the item is instantly made visible all the while the list is still shifting up, overlaying the item previously occupying that last position causing an ugly visual experience.
I can kinda "cheat" by delaying the step in 2. to engage after the animation is supposedly over, but then it introduces another visual issue if the user sends multiple messages quickly or receives them in the same fashion or in certain cases it just does not show any animation because the new item is loaded outside of the list and only scrolled after the animation time is elapsed, so this is not a solution.
first
second
In this example there are 2 recyclerviews set up with the same adapter slightly changed to make it easier to compare the issue in the same action.
The left recyclerview is not doing any update when an item is inserted, but it is the behavior I expect to display even if I update the item during the item insertion animation.
On the right recyclerview is the actual problem, as you can see new items are showing in full over the old ones before they have a chance to move out of the way.
The first example recording has scroll to bottom with no delay after the item is inserted, the second example has a delay that matches the insertion animation duration.
Reminder: this is just a manual example, the real application in my case is being done automatically via the integration I mentioned above, I am not the one in control of when the notifyItem* calls are made at any point.
How can I make sure the insert animation does not get interrupted even if I am updating the item data in the middle of the animation?
EDIT: I already searched for a solution in the questions posted before, but none are related to this one nor do the similar ones provide a solution to my problem.

Android: how to detect when items are successfully loaded in ListView?

I am using ListView which gets populated by the use of Adapter.
One of its features is also highlighting position on the list for the user with listView.getChildAt(savedViewPosition).setSelected(true).
At the conformation change, I would like to retaing poisiton of the selected item.
However, while I have tried several options, the best so far was to set a delay with .postDelay() and wait for the listView to load.
With this in mind, I would ask if there is any call that would enable me to wait until the items are loaded/visible and then posting the method immediately?
This sounds like something that could be accomplished by overriding notifyDataSetChanged() and selecting the item once the data has been loaded. There may be more to it to fit the exact behavior you want but it should be workable.
See the documentation here.

Update ListView elements every time position change

I have a ListView, in every element of that there is a TextView.
I'm looking for a way to update every TextView in the list every time the user's position changes. I have already implemented the permissionRequest for the Localization Services but I really don't know how to be informed every time the position changes.
I don't share code because I have only a lot of failed attempts.
What is in your opinion the best way to implement this kind of feature?

Android ListView, where new items push the old ones 'down'

My app has a ListView where data is added from the top, automatically (through setData on a Adapter). When data is set, usually most of the data remains the same, and only a few items are added at the top. Typically tens of items exist, and 1-2 items are added at the top every ~10 seconds.
Right now the user experience sucks. It completely re-draws the list with the new data. If a user was reading an item just before data got updated, he will lose his old position and will need to scroll to find it again.
What I would like to see as a more human compatible transition / animation, where the old data gets pushed down, and new items are added at the top. Or - new data pushes old data 'down' - and I can see this animation.
(Something like a 'ticker' - only vertical, and items are on a listview.)
I went through ListViewAnimations, and JazzyListView. They are very nice, but they don't support my requirement.
I hate re-inventing the wheels, so after coming up empty I wanted to make sure there really isn't anything out there.
If a user was reading an item just before data got updated, he will
lose his old position and will need to scroll to find it again.
Before updating the list view remember the position and restore it.
Some thing like this:
private int position;
private void save(){
position = myListView.getFirstVisiblePosition();
}
private void restore(){
myListView.setSelection(position);
}
You should check this, its from Android Developer page:
http://developer.android.com/training/animation/layout.html#activity
You might be able to getFirstVisiblePosition before calling setData, then setSelection after. That will still jump slightly (snapping to the current first visible item), unfortunately I believe you need to subclass ListView to access the pixel scroll value (getScrollY is for the view itself, not for scrolling inside it).
Maybe consider letting the user decide when to reload? For instance, display a list header "3 new items, swipe down to refresh" or some such.

Updating a ViewPager without interrupting the child displayed

I'm building an Android magazine-reader for our campus publication that pulls articles from a web service and displays them in a ViewPager.
To minimize the initial loading time, I want it to pull a relatively small number of articles (say 10) to begin with. Once it has pulled and displayed those articles, I want it to immediately begin downloading/deserializing the next 10 articles while the user is looking through the first set. Likewise, when they reach the 11th article I want it to go ahead and download the next 10, so that the user can continually browse without ever having to wait for more articles to load. This seems easy enough to accomplish using AsyncTasks, but I've hit one small hitch: When the next set of articles is downloaded and added to the ViewPager, it jumps back to displaying the first page.
How can I add views to the end of the ViewPager's dataset without changing the article being displayed to the user?
you will want to use the Endless Adapter created commonsware.
Or you can open the page again after refreshing the content of the ViewPager. Get the article id of the article user is reading. Open the same article after the ViewPager is refreshed.

Categories

Resources