You can get various cursors which have different position mapping from original cursor
with MappingCursorLoader and MappingCursorLoader.Layer.
Let's say your database has data {3, 6, 9, 12, 15, 18},
MappingCursorLoader basically returns the same as CursorLoader.
MappingCursorLoaderwith noLayer--> {3, 6, 9, 12, 15, 18}
You can change the position mapping of the original cursor.
MappingCursorLoaderwithReverse Layer--> {18, 15, 12, 9, 6, 3}
You can filter out of the original cursor.
MappingCursorLoaderwithOdd-Filter Layer--> {3, 9, 15}
You can use a sequence of layers.
MappingCursorLoaderwithReverse LayerandOdd-Filter Layer--> {15, 9, 3}
You can add group header to the original cursor.
MappingCursorLoaderwithEvery-10-Separator Layer--> {'010 Group', 3, 6, 9, '1120 Group', 12, 15, 18}
-
A layer modifies the position mapping in
Layer.onMapping(). This is run in worker thread and deliver the result to main thread just likeCursorLoader. -
Layers can be added or removed with
MappingCursorLoader.setLayers()/clearLayers()/addLayer()/removeLayer(). First added layer is calculated first and the last added layer's mapping is the final result. -
Each layer has its mapping result(=cache) so it can be reused later unless the original cursor or layer order is changed.
-
Like
ExpandableListView, you can add groups between cursor rows byMappingCursorLoader.Layer.addGroup(). This should be called inMappingCursorLoader.Layer.onMapping(). -
Like
ExpandableListView, you can expand and collapse groups byMappingCursorLoader.expandGroup()/collapseGroup()/expandAllGroup(). (I think this is specially useful becauseExpandableListViewcannot be used withCursorLoader.) -
To see the cursor is group or original cursor data,
MappingCursorLoader.getRowType()is provided. It returnsMappingCursorLoader.ROW_TYPE_CHILD/ROW_TYPE_GROUP_EXPANDED/ROW_TYPE_GROUP_COLLAPSED. If it is group type, you can get group specific data in the cursor column likecursor.getString(MappingCursorLoader.GROUP_CURSOR_COLUMN_KEY): group identifier,cursor.getInt(MappingCursorLoader.GROUP_CURSOR_COLUMN_SIZE): group size -
To use SectionIndexer for groups,
MappingCursorLoader.getGroupKeys()andMappingCursorLoader.getGroupHeaderPosition()are also provided.
I provide some basic layers for example. You can make your own layer or extend these layers. Please run the TestActivity to see what these layers do.
- FilterLayer
- SortLayer
- SeparatorLayer
- ConditionalGroupsLayer
- Android Support Package (android-support-v4.jar)
Because of
android.support.v4.content.CursorLoader
- v0.1.0 : Initial Release
https://github.com/EaseTheWorld/MappingCursorLoader
Made by EaseTheWorld