New updates view often shows incorrect info
A lot of feedback has come in about the Updates view (and the updates badge) and how under certain circumstances it does not display the correct info.
Relevant issues include: #990 (closed), #976 (closed), #975 (closed), #1020 (closed), #1011, #1001 (closed). Thank you to everyone who helped report these.
There are also a collection of crash reports about this view too. Any crash report which includes java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder
is probably related to this view.
This is a complex view, because:
- It gets its data from two sources:
- The list of apps currently in the process of being installed/updated, stored in Java memory.
- The list of apps to update from the database.
- There are two different processes responsible for updating the list items:
- The updates view itself, which listens to broadcasts from the installer/downloader and responds accordingly by moving items around in the list.
- The app list items, which themselves listen to broadcasts in order to:
- Update their download progress
- Ensure the buttons they display are correct (i.e. "Download", "Cancel download", "Update", "Install", "Run")
The view also tries to be as helpful as possible with regards to taking the user to the right part of the screen when they perform an action. For example, when tapping an individual app to download (after expanding "Show apps"), it will then smooth scroll the list to the top of the list, where that apps download progress is shown.
In order to make this smooth scrolling work, the adapter needs to keep track of when an individual item is added/removed and direct the recycler view to scroll to the relevant position. This causes bugs, because it is difficult to keep track of all the items in the adapter, and figure out where an item is removed from/added to. The quick and dirty solution is to always tell the recycler view "The entire adapter changed, please destroy your view and completely reconstruct it", however this means that the usability drops because we can't correctly scroll the user to the relevant location when they perform an action.
I'd like to maintain the current behaviour, but make it less buggy. If upon a brief investigation, it seems too difficult, then I will revert to the blunt "the entire adapter changed" approach and see if that fixes a lot of these bugs.