From d003b586dcf12fbea2cec88d0879e02e75b0063f Mon Sep 17 00:00:00 2001 From: Adrian Kuta Date: Tue, 28 Jan 2020 18:17:55 +0100 Subject: [PATCH] Update README.md --- README.md | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ad59074..f4436f0 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,100 @@ [![License](https://img.shields.io/github/license/AdrianKuta/Expandable-RecyclerView?style=plastic)](https://github.com/AdrianKuta/Expandable-RecyclerView/blob/master/LICENSE) [![CircleCI](https://img.shields.io/circleci/build/github/AdrianKuta/Expandable-RecyclerView/master?label=CircleCI&style=plastic&logo=circleci)](https://circleci.com/gh/AdrianKuta/Expandable-RecyclerView) - +With this adapter you can add expand feature to regular RecyclerView. +All objects are store in [Tree (Data structure)](https://github.com/AdrianKuta/Tree-Data-Structure), so adapter can create multilevel expandable groups. +Under the hood, the tree is flattened to simple list, so from RecyclerView's point of view it can operate as usual. + + + -This RecyclerViewAdapter use Tree(Data Structure) to keep all objects. ## Download implementation "com.github.adriankuta:expandable-recyclerView:$latest_versions" - +## Usage +To use expandable adapter we just have to expand our Adapter class with `ExpandableRecyclerViewAdapter` +Where `T` is data type on which adapter will operate, `VH` is ViewHolder type. + +```kotlin +class ExpandableAdapter: ExpandableRecyclerViewAdapter() { + + + override fun getTreeNodes(): ExpandableTreeNode { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun onBindViewHolder( + holder: RecyclerView.ViewHolder, + treeNode: ExpandableTreeNode, + nestLevel: Int + ) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun onCreateViewHolder(parent: ViewGroup, nestLevel: Int): RecyclerView.ViewHolder { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} +``` + +`ExpandableRecyclerViewAdapter` has build-in methods to control expandable groups: +```kotlin +fun toggleGroup(expandableTreeNode: ExpandableTreeNode) + +fun expand(expandableTreeNode: ExpandableTreeNode) + +fun collapse(expandableTreeNode: ExpandableTreeNode) +``` + +Information if group is expanded or not is stored inside `ExpandableTreeNode` class + + +### Creating tree + +There are different ways to create tree. The easiest way is to use extensions methods prepared specially for kotlin: + +```kotlin +val tree = + expandableTree("World") { + child("North America") { + child("USA") + } + child("Europe") { + child("Poland") { + child("Warsaw") + } + child("Germany") + } + child("Asia") { + child("China") + } + } +``` + +But in case when you want create tree at runtime, you can use `ExpandableTreeNode` class to build tree: + +```kotlin +val root = ExpandableTreeNode("World") +val northA = ExpandableTreeNode("North America") +val europe = ExpandableTreeNode("Europe") +val asia = ExpandableTreeNode("Asia") + +root.addChild(northA) +root.addChild(europe) +root.addChild(asia) + +val poland = ExpandableTreeNode("Poland") +europe.addChild(poland) +// etc. +``` + +## Sample + +Full example of this library is available in app module. + +## Contribution + +Project is still during development and improvements. +Issues with BUGs or suggestions are welcome. +Also please feel free to fork library and contribute to project! ;-) \ No newline at end of file