All Projects → aminography → PrimeAdapter

aminography / PrimeAdapter

Licence: Apache-2.0 license
PrimeAdapter makes working with RecyclerView easier.

Programming Languages

kotlin
9241 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to PrimeAdapter

Candyview
Implement any RecyclerView in just 1 Line. CandyView handles everything for you.
Stars: ✭ 15 (-72.22%)
Mutual labels:  adapter, recyclerview, recyclerview-adapter
Tableview
TableView is a powerful Android library for displaying complex data structures and rendering tabular data composed of rows, columns and cells.
Stars: ✭ 2,928 (+5322.22%)
Mutual labels:  adapter, recyclerview, recyclerview-adapter
Poweradapter
Adapter for RecyclerView(only 21KB).RecyclerView万能适配器(仅21KB)
Stars: ✭ 112 (+107.41%)
Mutual labels:  adapter, recyclerview, recyclerview-adapter
Fastadapter
The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
Stars: ✭ 3,512 (+6403.7%)
Mutual labels:  adapter, recyclerview, recyclerview-adapter
MultiTypeAdapter
RecyclerView通用多类型适配器MultiTypeAdapter,以布局文件为单位更细粒度的条目复用。
Stars: ✭ 18 (-66.67%)
Mutual labels:  adapter, recyclerview, recyclerview-adapter
Flagchatadapter
FlagChatAdapter is easy to implement enchanting recycler view adapter. Just extend your adapter with FlagChatAdapter, impliment some methods and voila! You have got the most beautiful looking chat on your phone. Zero boilerplate code, just put your variables in the right direction.
Stars: ✭ 39 (-27.78%)
Mutual labels:  adapter, recyclerview, recyclerview-adapter
Modular2Recycler
Modular²Recycler is a RecyclerView.Adapter that is modular squared.
Stars: ✭ 72 (+33.33%)
Mutual labels:  adapter, recyclerview, recyclerview-adapter
Sherlockadapter
一个万能的封装了RecyclerView.Adapter的功能库。
Stars: ✭ 186 (+244.44%)
Mutual labels:  adapter, recyclerview
Easyadapter
This project demonstrates simple approach for implementation complex lists, based on RecyclerView.
Stars: ✭ 187 (+246.3%)
Mutual labels:  adapter, recyclerview
Commonadapter
一个适用于ListView/GridView/RecyclerView的Adapter库,简化大量重复代码,支持多种布局,可自定义图片加载的实现。
Stars: ✭ 219 (+305.56%)
Mutual labels:  adapter, recyclerview
BaseToolsLibrary
Android通用适配器和常用的工具类
Stars: ✭ 24 (-55.56%)
Mutual labels:  adapter, recyclerview-adapter
Easyadapter
Android 轻量级适配器,简化使用,适应所有的AbsListView、RecyclerView。支持HeaderView与FooterView~
Stars: ✭ 160 (+196.3%)
Mutual labels:  adapter, recyclerview
Recyclerviewadapter
A RecyclerView Adapter that support load more and add headerview
Stars: ✭ 141 (+161.11%)
Mutual labels:  adapter, recyclerview
Multiselectadapter
MultiSelectAdapter可以让你的Adapter快速实现多选和批量操作
Stars: ✭ 195 (+261.11%)
Mutual labels:  adapter, recyclerview
Kotlin Adapter
🔥 RecyclerView,AbsListView适配器, 支持多种视图样式, 支持吸顶、侧滑删除、拖拽效果
Stars: ✭ 132 (+144.44%)
Mutual labels:  adapter, recyclerview
InstantRecyclerView
A library that helps to implement a complex list with RecyclerView.(RecyclerView使用的封装与优化,帮助你快速利用RecyclerView构建复杂列表)
Stars: ✭ 22 (-59.26%)
Mutual labels:  adapter, recyclerview
Sectionedrecyclerviewadapter
An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.
Stars: ✭ 1,659 (+2972.22%)
Mutual labels:  adapter, recyclerview
Dsladapter
🔥 Kotlin时代的Adapter, Dsl 的形式使用 RecyclerView.Adapter, 支持折叠展开, 树结构,悬停,情感图状态切换, 加载更多, 多类型Item,侧滑菜单等
Stars: ✭ 231 (+327.78%)
Mutual labels:  adapter, recyclerview
Recycling
A Library for make an easy and faster RecyclerView without adapter
Stars: ✭ 57 (+5.56%)
Mutual labels:  recyclerview, recyclerview-adapter
oh-my-design-patterns
🎨 Record the articles and code I wrote while learning design patterns
Stars: ✭ 33 (-38.89%)
Mutual labels:  adapter, builder

PrimeAdapter

Android Arsenal API Download

PrimeAdapter makes working with RecyclerView easier by separating required code in a few simple and well-structured classes. It brings simplicity when you have multiple view types in a RecyclerView. By using annotation processing, it generates unique view types automatically to make the code more clear. You can use PrimeAdapter in both Kotlin and Java Android projects as the sample apps are written.

Custom Divider Draggability Expandability
Example Example Example

Download

Add the following lines to your build.gradle file:

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
  
repositories {
    jcenter()
}
  
dependencies {
    implementation 'com.aminography:primeadapter:1.0.14'
    compileOnly 'com.aminography:primeadapter-annotation:1.0.14'
    kapt 'com.aminography:primeadapter-processor:1.0.14'
}
  • If you write code in Java, you should also add kotlin dependency too:
dependencies {
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.50'
}

How to use PrimeAdapter?

You should create both data holder and view holder classes for each type of view that you want to show in RecyclerView.


1. It's necessary to add @DataHolder annotation above all data holder classes which inherits from PrimeDataHolder:

@DataHolder
data class ActorDataHolder(
        val name: String
) : PrimeDataHolder()

2. Each view holder class should inherit from PrimeViewHolder and specify related data holder as a type parameter like following:

class ActorViewHolder(
        delegate: PrimeDelegate
) : PrimeViewHolder<ActorDataHolder>(delegate, R.layout.list_item) {
  
    override fun bindDataToView(dataHolder: ActorDataHolder) {
        with(itemView) {
            nameTextView.text = dataHolder.name
        }
    }
}

3. Your custom adapter class must inherit from PrimeAdapter that decides to make view holder instance based on data holder type. Follow this pattern:

class ActorAdapter : PrimeAdapter() {
  
    override fun makeViewHolder(dataHolderClass: Class<*>?): PrimeViewHolder<*>? {
        return when (dataHolderClass) {
            ActorDataHolder::class.java -> ActorViewHolder(this)
            else -> null
        }
    }
}

4. Finally, you can instantiate your custom adapter using PrimeAdapter builder mechanism.

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
      
    val adapter = PrimeAdapter.with(recyclerView)
                    .setLayoutManager(LinearLayoutManager(activity))
                    .set()
                    .build(ActorAdapter::class.java)
      
    val dataList = mutableListOf<PrimeDataHolder>()
    dataList.add(ActorDataHolder("Tom Hanks"))
    dataList.add(ActorDataHolder("Morgan Freeman"))
    dataList.add(ActorDataHolder("Robert De Niro"))
    adapter.replaceDataList(dataList)
}

Extra Features

Handling Item Clicks

PrimeAdapter helps you handle RecyclerView items click events, simply by setItemClickListener() with an OnRecyclerViewItemClickListener argument when you're building an adapter instance or later:

val onRecyclerViewItemClickListener = object: OnRecyclerViewItemClickListener{
    override fun onItemClick(primeDataHolder: PrimeDataHolder) {
        // do something
    }
    override fun onItemLongClick(primeDataHolder: PrimeDataHolder) {
        // do something
    }
}

// In builder pattern:
val adapter = PrimeAdapter.with(recyclerView)
                ...
                .setItemClickListener(onRecyclerViewItemClickListener)
                ...
                .build(ActorAdapter::class.java)
                
// or after adapter instantiation:
adapter.setItemClickListener(onRecyclerViewItemClickListener)

Draggability

PrimeAdapter helps you make the RecyclerView items draggable. It would be activated/deactivated by calling setDraggable(true)/setDraggable(false) on a builder or an adapter instance. Optionally, you can get notified about item movements by calling setItemDragListener() and passing an OnRecyclerViewItemDragListener instance to it.

adapter.setDraggable(true)
adapter.setItemDragListener(object: OnRecyclerViewItemDragListener{
    override fun onItemMoved(fromPosition: Int, toPosition: Int) {
        // do something
    }
})

It is necessary to introduce a view as handle of dragging in view holders which are going to be draggable:

class ActorViewHolder(
        delegate: PrimeDelegate
) : PrimeViewHolder<ActorDataHolder>(delegate, R.layout.list_item) {
  
    init {
        setDragHandle(itemView)
    }
    ...
}

Expandability

Another feature of PrimeAdapter is making the implementation of RecyclerView items expansion easier. Calling the setExpandable(true)/setExpandable(false) on a builder or on adapter instance changes its activation.

adapter.setExpandable(true)

To see how to implement it, please check the related example code.


Custom Skippable Divider

Showing custom divider lines is a good feature that PrimeAdapter provides. Calling the setDivider() on a builder or on adapter instance leads to show default divider line between items. It's possible to pass it a custom Drawable instance or simply a color to change the divider looking. Also we can set inset for divider drawables in pixels.

//----- default divider:
adapter.setDivider()
  
//----- divider with custom drawable:
adapter.setDivider(ContextCompat.getDrawable(context, R.drawable.divider))
  
//----- divider with custom color:
adapter.setDivider(Color.RED)
  
//----- divider with custom color and custom inset:
adapter.setDivider(Color.RED, insetLeft = 16, insetRight = 16)
  
//----- deactivate dividers:
adapter.setDivider(null)

By default dividers are shown for all items except the last one. It's easy to skip some items divider by setting hasDivider property to false on their data holder instances.

adapter.getItem(position).hasDivider = false
adapter.notifyDataSetChanged()

ProGuard

If you want to create a release version of your app, you need to include the following lines in the app level proguard file:

-keep class com.aminography.primeadapter.ViewTypeManager { *; }
-keepclassmembers class ** {
    @com.aminography.primeadapter.annotation.DataHolder *;
}

License

Copyright 2018 Mohammad Amin Hassani.

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].