Refactoring grid algorithm
The current interface between GridLayoutManager and StaggeredGrid is
too complicated: GridLayoutManager updates rows min/max edge and Grid
is responsible for fill items according to row min/max edge.
This CL moved most of the grid code into Grid class family and make
interface between GridLayoutManager and Grid much simpler.
GridLayoutManager no longer updates row min/max.
Refactoring made it possible to write efficient Grid class for single
row or non staggered grid. A base Grid class is abstracted out.
StaggeredGrid implemented it using a complicated data strurcture (a
CircularArray) to cache stagger layout result. A single row Grid will
cost less memory allocations: a TODO in the near future.
fastRelayout() was rewriten slightly differently, it will relayout
(using detachFromParent and attachToParent) next children once detects
child size change, previously we push children away on the same row
which might cause a bad alignment at end.
Regular layout now starts with detachAndScrapAttachedViews(), this
is lighter than removeAndRecycleAllViews() which may lose some views
due to cache limit.
Prepend/append during scroll now also detects if child size changed,
then invalidate cached staggered result before/after the child.
Improvement during adapter notifyChange or structure change, now we
no longer discard grid information in a non-fast relayout case. We
still keeps the same cached staggered result, until we really find
size of a child has changed then we invalidate part of the cache.
Tested with BrowseFragment/HorizontalGridTestActivity/
VerticalGridActivity/BrowseAnimationActivity and with rtl=true/false.
Issue: 18946733
Change-Id: Ia0cfa34ad8d09c124dbffe51680a89f177bfef31
6 files changed