All Projects → iFanie → AccordionRecycler

iFanie / AccordionRecycler

Licence: Apache-2.0 License
Android RecyclerView Adapter with nested items & expand/contract functionality

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to AccordionRecycler

recyclerview-expandable
RecyclerView implementation of traex's ExpandableLayout
Stars: ✭ 70 (+311.76%)
Mutual labels:  recyclerview, recyclerview-adapter, expandable, expandablerecyclerview
Statik
A simple static list information backed by RecyclerView for Android in Kotlin
Stars: ✭ 22 (+29.41%)
Mutual labels:  recyclerview, recyclerview-adapter, recyclerview-multi-type
kandy
Sweet Android libraries written in Kotlin
Stars: ✭ 19 (+11.76%)
Mutual labels:  recyclerview, recyclerview-adapter, recyclerview-multi-type
ExpandableRecyclerView
ExpandableRecyclerView with smoothly animation.
Stars: ✭ 412 (+2323.53%)
Mutual labels:  recyclerview, expandable, expandablerecyclerview
RecyclerELE
Android Library for easy addition of Empty, Loading and Error views in a RecyclerView
Stars: ✭ 27 (+58.82%)
Mutual labels:  recyclerview, recyclerview-adapter, recyclerview-multi-type
Flexibleadapter
Fast and versatile Adapter for RecyclerView which regroups several features into one library to considerably improve the user experience :-)
Stars: ✭ 3,482 (+20382.35%)
Mutual labels:  recyclerview, expandable, collapsable
Poweradapter
Adapter for RecyclerView(only 21KB).RecyclerView万能适配器(仅21KB)
Stars: ✭ 112 (+558.82%)
Mutual labels:  recyclerview, recyclerview-adapter, expandable
LxAdapter
RecyclerView Adapter Library
Stars: ✭ 50 (+194.12%)
Mutual labels:  recyclerview, recyclerview-adapter, recyclerview-multi-type
recyclerview-kotlin
10+ Tutorials on RecyclerView in Kotlin
Stars: ✭ 41 (+141.18%)
Mutual labels:  recyclerview, recyclerview-adapter
RecyclerView
支持下拉刷新,上拉加载,Header,Footer,复杂多种数据结构类型
Stars: ✭ 318 (+1770.59%)
Mutual labels:  recyclerview-adapter, recyclerview-multi-type
SortedListAdapter
The RecyclerView.Adapter that makes your life easy!
Stars: ✭ 48 (+182.35%)
Mutual labels:  recyclerview, recyclerview-adapter
Accordion-Collapse-react-native
React native Accordion/Collapse component, very good to use in toggles & show/hide content
Stars: ✭ 147 (+764.71%)
Mutual labels:  expandable, collapsable
InfiniteScrollRecyclerView
Enables the RecyclerView to Auto scroll for indefinite time.
Stars: ✭ 49 (+188.24%)
Mutual labels:  recyclerview, recyclerview-adapter
slush
This library will no longer be updated 😭
Stars: ✭ 26 (+52.94%)
Mutual labels:  recyclerview, recyclerview-adapter
PrimeAdapter
PrimeAdapter makes working with RecyclerView easier.
Stars: ✭ 54 (+217.65%)
Mutual labels:  recyclerview, recyclerview-adapter
App-Manager-Android
An app manager for Android written in Kotlin. View app related info, launch or uninstall apps.
Stars: ✭ 31 (+82.35%)
Mutual labels:  recyclerview, recyclerview-adapter
RvClickListenerExample
Example showing the implementation of onItemClickListener & getAdapterPosition() in RecyclerView.
Stars: ✭ 22 (+29.41%)
Mutual labels:  recyclerview, recyclerview-adapter
ModularAdapter
The RecyclerView.Adapter that makes your life simple!
Stars: ✭ 14 (-17.65%)
Mutual labels:  recyclerview, recyclerview-adapter
jubako
A small API to help display rich content in a RecyclerView such as a wall of carousels
Stars: ✭ 28 (+64.71%)
Mutual labels:  recyclerview, recyclerview-adapter
CommonRecycler
极度封装RecyclerView里的adapter,holder,让其支持各种点击事件,使用方便
Stars: ✭ 19 (+11.76%)
Mutual labels:  recyclerview, recyclerview-multi-type

AccordionRecycler

License Android Arsenal Bintray

Android RecyclerView Adapter with nested items & expand/contract functionality

With AccordionRecycler you can easily create awesome RecyclerViews, containing infinitely nested items and the ability to expand or collapse any part of the View at will.

Demo GIF

Installation

implementation 'com.izikode.izilib:accordionrecycler:0.5'

Usage

Have your Model Classes implement the AccordionRecyclerData interface.

  • The Adapter needs a way to get the ViewType, Primary data and the Enclosed (child) data, if existing. You use the above interface to provide those.
  • Fill the diamond operator with the type the model provides.
  • Optionally, you can use a base class as a reference for your different data sub-classes and also your ViewHolders. In the provided demo, and examples below, ColorData is the base class and it provided itself.
abstract class ColorData : AccordionRecyclerData<ColorData>

data class RedData(

        var arrayOfPink: Array<PinkData> = arrayOf()

) : ColorData(RedViewHolder.VIEW_TYPE) {

    override val mainData: ColorData?
            get() = this

    override val enclosedDataArray: Array<out AccordionRecyclerData<out ColorData?>>?
            get() = arrayOfPink

}

data class GrayData( ... ) : ColorData() { ... }
data class PinkData( ... ) : ColorData() { ... }
data class WhiteData( ... ) : ColorData() { ... }

Have your ViewHolders extend the AccordionRecyclerViewHolder abstract class.

  • Provide the ViewHolder constructor with the parent ViewGroup and the layout to be inflated.
  • Fill the diamond operator with the type of Model being handled.
  • Again, optionally, create a base ViewHolder as a reference.
abstract class ColorViewHolder<Data>( ... ) : AccordionRecyclerViewHolder<Data> where Data : ColorData

class RedViewHolder(parent: ViewGroup) : ColorViewHolder<RedData>(parent, R.layout.view_holder_red) {

    override var data: RedData? = null
    
    companion object {
        const val VIEW_TYPE = 2
    }

}

class GrayViewHolder( ... ) : ColorViewHolder<GrayData>
class PinkViewHolder( ... ) : ColorViewHolder<GrayData>
class WhiteViewHolder( ... ) : ColorViewHolder<RedData>

Create an Adapter that extends the AccordionRecyclerAdapter abstract class.

  • Override the buildViewHolder function to provide new ViewHolder instances.
  • Override the updateViewHolder function to update each item being recycled. The AccordionRecyclerItemDetails parameter contains information about the current item and all enclosing (parent) items, when existing. This allows for unlimited visual combinations for all view types.
  • Expand/Collapse is accomplished with:
    • removeItem to remove an item and all it's child items, if existing.
    • removeEnclosedItems to remove the child items only.
    • addItems to add all items and their child items, if existing.
    • addEnclosedItems to add all items as child items to another.
  • Optionally, you can modify how each item is handled when it is iterated and added into the recycler data. You do that by overriding the processForAdditionalItems function. You can use this feature to handle edge case. One such case is shown in the demo, in which whenever a Pink item does not have any child White items, a new item is added, showing the text 'Nothing to see here'.
class MainAccordionAdapter : AccordionRecyclerAdapter<ColorViewHolder<out ColorData>, ColorData>() {

    override fun buildViewHolder(parent: ViewGroup, viewType: Int): ColorViewHolder<out ColorData> =
            when(viewType) {

                RedViewHolder.VIEW_TYPE -> RedViewHolder(parent)
                PinkViewHolder.VIEW_TYPE -> PinkViewHolder(parent)
                WhiteViewHolder.VIEW_TYPE -> WhiteViewHolder(parent)

                else -> GrayViewHolder(parent)

            }

    override fun updateViewHolder(position: Int, viewHolder: ColorViewHolder<out ColorData>, data: ColorData?, 
                details: AccordionRecyclerItemDetails) {
                
            when (viewHolder) {

                is RedViewHolder -> viewHolder.apply { ... }
                is PinkViewHolder -> viewHolder.apply { ... }
                is WhiteViewHolder -> viewHolder.apply { ... }

                else -> (viewHolder as GrayViewHolder).apply { ... }

            }
        }
        
    override fun processForAdditionalItems(position: Int, item: AccordionRecyclerData<out ColorData?>?)
            : Array<out AccordionRecyclerData<out ColorData?>?> = item?.let {

                    if (it is PinkData && it.enclosedDataArray.isNullOrEmpty()) {
                        arrayOf(
                            it,
                            EmptyPinkViewHolder.EmptyPinkData()
                        )
                    } else {
                        super.processForAdditionalItems(position, item)
                    }

                } ?: super.processForAdditionalItems(position, item)

}

For a full example, see the sample app.

Licence

Copyright 2018 Fanis Veizis

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].