Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork489
The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
License
mikepenz/FastAdapter
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
The FastAdapter is here to simplify creating adapters for RecyclerViews. Don't worry about the adapter anymore. Just write the logic for how your view/item should look like, and you are done.It's blazing fast, minimizing the code you need to write, and is easy to extend.
What's included 🚀 •Setup 🛠️ •Migration Guide 🧬 •Used by •Sample App
- Core module 100% in Kotlin
- Click / Long-Click listeners
- Selection / Multi-Selection (MultiselectSample,CheckBoxSample,RadioButtonSample)
- Expandable items (ExpandableSample,IconGridSample ,AdvancedSample)
- Write less code, get better results
- Highly optimized code
- Simple Drag & Drop (SimpleItemListSample)
- Headers (StickyHeaderSample,AdvancedSample)
- Footers
- Filter (SimpleItemListSample)
- Includes suggestions from the Android Team
- Easily extensible
- Endless Scroll (EndlessScrollSample)
- "Leave-Behind"-Pattern (SwipeListSample)
- Split item view and model (ModelItem,MultiTypeModelItem)
- Chain other Adapters (SimpleItemListSample,StickyHeaderSample)
- Comes with useful Helpers
- ActionModeHelper (MultiselectSample)
- UndoHelper (MultiselectSample)
- FastScroller (external lib) (SimpleItemListSample)
- Paging (via Jetpack paging lib) (PagedActivity)
- More to come...
The library is split up into core, commons, and extensions. The core functions are included in the following dependency.
implementation"com.mikepenz:fastadapter:${latestFastAdapterRelease}"implementation"androidx.appcompat:appcompat:${androidX}"implementation"androidx.recyclerview:recyclerview:${androidX}"
Expandable support is included and can be added via this
implementation"com.mikepenz:fastadapter-extensions-expandable:${latestFastAdapterRelease}"Many helper classes are included in the following dependency.
implementation"com.mikepenz:fastadapter-extensions-binding:${latestFastAdapterRelease}"// view binding helpersimplementation"com.mikepenz:fastadapter-extensions-diff:${latestFastAdapterRelease}"// diff util helpersimplementation"com.mikepenz:fastadapter-extensions-drag:${latestFastAdapterRelease}"// drag supportimplementation"com.mikepenz:fastadapter-extensions-paged:${latestFastAdapterRelease}"// paging supportimplementation"com.mikepenz:fastadapter-extensions-scroll:${latestFastAdapterRelease}"// scroll helpersimplementation"com.mikepenz:fastadapter-extensions-swipe:${latestFastAdapterRelease}"// swipe supportimplementation"com.mikepenz:fastadapter-extensions-ui:${latestFastAdapterRelease}"// pre-defined ui componentsimplementation"com.mikepenz:fastadapter-extensions-utils:${latestFastAdapterRelease}"// needs the `expandable`, `drag` and `scroll` extension.// required for the ui components and the utilsimplementation"com.google.android.material:material:${androidX}"
Just create a class which extends theAbstractItem as shown below. Implement the methods, and your item is ready.
openclassSimpleItem :AbstractItem<SimpleItem.ViewHolder>() {var name:String?=nullvar description:String?=null/** defines the type defining this item. must be unique. preferably an id*/overrideval type:Int get()=R.id.fastadapter_sample_item_id/** defines the layout which will be used for this item in the list*/overrideval layoutRes:Int get()=R.layout.sample_itemoverridefungetViewHolder(v:View):ViewHolder {returnViewHolder(v) }classViewHolder(view:View) : FastAdapter.ViewHolder<SimpleItem>(view) {var name:TextView= view.findViewById(R.id.material_drawer_name)var description:TextView= view.findViewById(R.id.material_drawer_description)overridefunbindView(item:SimpleItem,payloads:List<Any>) { name.text= item.name description.text= item.name }overridefununbindView(item:SimpleItem) { name.text=null description.text=null } }}
classBindingIconItem :AbstractBindingItem<IconItemBinding>() {var name:String?=nulloverrideval type:Int get()=R.id.fastadapter_icon_item_idoverridefunbindView(binding:IconItemBinding,payloads:List<Any>) { binding.name.text= name }overridefuncreateBinding(inflater:LayoutInflater,parent:ViewGroup?):IconItemBinding {returnIconItemBinding.inflate(inflater, parent,false) }}
Use thebinding extension dependency in your application for this.
//create the ItemAdapter holding your Itemsval itemAdapter=ItemAdapter<SimpleItem>()//create the managing FastAdapter, by passing in the itemAdapterval fastAdapter=FastAdapter.with(itemAdapter)//set our adapters to the RecyclerViewrecyclerView.setAdapter(fastAdapter)//set the items to your ItemAdapteritemAdapter.add(ITEMS)
By default theFastAdapter only provides basic functionality, which comes with the abstraction of items asItem andModel.And the general functionality of adding/removing/modifying elements. To enableselections, orexpandables the provided extensions need to be activated.
// Gets (or creates and attaches if not yet existing) the extension from the given `FastAdapter`val selectExtension= fastAdapter.getSelectExtension()// configure as neededselectExtension.isSelectable=trueselectExtension.multiSelect=trueselectExtension.selectOnLongClick=false// see the API of this class for more options.
This requires the
fastadapter-extensions-expandableextension.
// Gets (or creates and attaches if not yet existing) the extension.val expandableExtension= fastAdapter.getExpandableExtension()// configure as neededexpandableExtension.isOnlyOneExpandedItem=true
For further details scroll down to theExpandableItems (under advanced usage) section.
fastAdapter.onClickListener= { view, adapter, item, position->// Handle click herefalse}
// just add an `EventHook` to your `FastAdapter` by implementing either a `ClickEventHook`, `LongClickEventHook`, `TouchEventHook`, `CustomEventHook`fastAdapter.addEventHook(object:ClickEventHook<SimpleImageItem>() {overridefunonBind(viewHolder:RecyclerView.ViewHolder):View? {//return the views on which you want to bind this eventreturnif (viewHolderisSimpleImageItem.ViewHolder) { viewHolder.viewWhichReactsOnClick }else {null} }overridefunonClick(v:View,position:Int,fastAdapter:FastAdapter<SimpleImageItem>,item:SimpleImageItem) {//react on the click event }})
// Call this in onQueryTextSubmit() & onQueryTextChange() when using SearchViewitemAdapter.filter("yourSearchTerm")itemAdapter.itemFilter.filterPredicate= { item:SimpleItem, constraint:CharSequence?-> item.name?.text.toString().contains(constraint.toString(), ignoreCase=true)}
filter() should return true for items to be retained and false for items to be removed.
This requires the
fastadapter-extensions-dragextension.
First, attachItemTouchHelper to RecyclerView.
val dragCallback=SimpleDragCallback()val touchHelper=ItemTouchHelper(dragCallback)touchHelper.attachToRecyclerView(recyclerView)
ImplementItemTouchCallback interface in your Activity, and override theitemTouchOnMove() method.
overridefunitemTouchOnMove(oldPosition:Int,newPosition:Int):Boolean {DragDropUtil.onMove(fastItemAdapter.itemAdapter, oldPosition, newPosition)// change positionreturntrue}
Start by initializing your adapters:
// Header is a model class for your headerval headerAdapter=ItemAdapter<Header>()
Initialize a Model FastAdapter:
val itemAdapter=GenericItemAdapter()
Finally, set the adapter:
val fastAdapter:GenericFastAdapter=FastAdapter.with(headerAdapter, itemAdapter)//the order defines in which order the items will show up// alternative the super type of both item adapters can be used. e.g.:recyclerView.setAdapter(fastAdapter)
Create a FooterAdapter. We need this to display a loading ProgressBar at the end of our list. (Don't forget to pass it intoFastAdapter.with(..))
val footerAdapter=ItemAdapter<ProgressItem>()
Keep in mind that ProgressItem is provided by FastAdapter’s extensions.
recyclerView.addOnScrollListener(object:EndlessRecyclerOnScrollListener(footerAdapter) {overridefunonLoadMore(currentPage:Int) { footerAdapter.clear() footerAdapter.add(ProgressItem())// Load your items here and add it to FastAdapter itemAdapter.add(NEWITEMS) }})
For the complete tutorial and more features such as multi-select and CAB check out thesample app.
- As of v2.5.0 there are no more known requirements to use the
FastAdapterwith Proguard
TheFastAdapter comes with support for expandable items. After adding the dependency set up theExpandable extension via:
val expandableExtension= fastAdapter.getExpandableExtension()
Expandable items have to implement theIExpandable interface, and the sub items theISubItem interface. This allows better support.The sample app provides sample implementations of those. (Those in the sample are kept Model which allows them to be used with different parent / subitems)
As of the way howSubItems and their state are handled it is highly recommended to use theidentifier basedStateManagement. Just addwithPositionBasedStateManagement(false) to yourFastAdapter setup.
A simple item just needs to extend from theAbstractExpandableItem and provide theViewHolder as type.
openclassSimpleSubExpandableItem :AbstractExpandableItem<SimpleSubExpandableItem.ViewHolder>() {/** * BASIC ITEM IMPLEMENTATION*/}
// See theSimpleSubExpandableItem.kt of the sample application for more details.
- RecyclerView Adapter made easy (FastAdapter v2.x)
Mike Penz:
- AboutLibrarieshttps://github.com/mikepenz/AboutLibraries
- Android-Iconicshttps://github.com/mikepenz/Android-Iconics
- ItemAnimatorshttps://github.com/mikepenz/ItemAnimators
- MaterialDrawerhttps://github.com/mikepenz/MaterialDrawer
Mike Penz
Fabian Terhorst
This free, open source software was also made possible by a group of volunteers that put many hours of hard work into it. See theCONTRIBUTORS.md file for details.
A special thanks to the very active contributors who added many improvements to this library.
Copyright 2021 Mike PenzLicensed 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.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.About
The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
