Dev Recycler View Adapter

abstract class DevRecyclerViewAdapter<Data>(onClickListener: (data: Data) -> Unit? = null, onLongClickListener: (data: Data) -> Unit? = null) : RecyclerView.Adapter<DevItemViewHolder<Data>>

Adapter for RecyclerView

Author

Jimly A.

Since

31-May-20.

Parameters

onClickListener

action when item clicked

onLongClickListener

action when item clicked for long, nullable

Data

object data to be implemented

Constructors

Link copied to clipboard
fun <Data> DevRecyclerViewAdapter(onClickListener: (data: Data) -> Unit? = null, onLongClickListener: (data: Data) -> Unit? = null)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun add(item: Data?)

Method to add item to list data

Link copied to clipboard
fun addAll(items: List<Data>?)

Method to add list of item to list data

Link copied to clipboard
fun addAt(item: Data?, position: Int)

Method to add item to list data at certain position

Link copied to clipboard
fun addOrUpdate(item: Data)

Method to add data if not exist, and update if it exist

Link copied to clipboard
fun addOrUpdateAll(items: List<Data>?)

Method to add or update list of items to list data

Link copied to clipboard
fun addOrUpdateToFirst(items: List<Data>?)

Method to add or update list of items to start of list data

Link copied to clipboard
fun addToFirst(item: Data?)

Method to add a single item to the start of list data

fun addToFirst(items: List<Data>?)

Method to add list of item to start of list data

Link copied to clipboard
fun clear()

Method to remove all item from list data

Link copied to clipboard
fun finishLoadMore()

Method to finish load more, and remove callback.. Define it in empty state observer

Link copied to clipboard
open override fun getItemCount(): Int

Method to define how many item displayed in RecyclerView

Link copied to clipboard
fun getLayoutInflater(viewGroup: ViewGroup): LayoutInflater

Method to get LayoutInflater

Link copied to clipboard
fun getLoadMoreListener(): OnLoadMoreListener?

Method to get loadMoreListener

Link copied to clipboard
fun hideLoadMoreLoading()

Method to hide loading in recyclerview

Link copied to clipboard
open override fun onBindViewHolder(holder: DevItemViewHolder<Data>, position: Int)
Link copied to clipboard
abstract override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DevItemViewHolder<Data>

Method to declare View Holder, if you use more than one ViewType, declare desired View Holder based on ViewType in this method

Link copied to clipboard
fun remove(item: Data?)

Method to remove defined item from list data

Link copied to clipboard
fun removeAt(position: Int)

Method to remove item at defined position

Link copied to clipboard
fun resetEndlessScroll()

Method to reset state and adding loadMore listener

Link copied to clipboard
fun setEndlessScroll(rc: RecyclerView)

Method to set listener for recyclerView Call this method after assigning loadMoreListener

Link copied to clipboard
fun setLoadMoreListener(listener: OnLoadMoreListener)

After inherit Activity or Fragment with onLoadMoreListener, call this method first to set listener

Link copied to clipboard
fun showLoadMoreError()

Method to show error textView Define it in error state observer

Link copied to clipboard
fun showLoadMoreLoading()

Show loadMore Layout, call it in observer loadMore

Properties

Link copied to clipboard
var isLoading: Boolean = true

Is recyclerview is loading?

Link copied to clipboard
val listData: ArrayList<Data>

list of Data used in adapter, for filtering purposes please declare another list in initialized adapter

Link copied to clipboard
var loadMoreLimit: Int = 10

Limit of item to load

Link copied to clipboard
var loadMoreSkip: Int = 0

amount of item to skip

Sources

Link copied to clipboard