Skip to content

AmosKorir/empty-recyclerview-indicator

Repository files navigation

Empty-recyclerView-indicator

Codacy Badge

Show no content indicator for RecyclerView,

This is a reactive model that observes the recyclerView adapter items. It show "no content " when the number of items within the recyclerView is zero. During loading process, it shows a progressBar with loading status. It is not a customView 😄

image

How to use

How to use.

Installation

implementation 'com.nocontent.emptyrecyclerindicator:RecyclerViewEmptyIndicator:1.0'

Creation of an Instance

Create an instance of the EmptyViewIndicator within the application class.

class MyApplication : Application() {

private lateinit var emptyViewIndicator: EmptyViewIndicator
override fun onCreate() {
  super.onCreate()
  emptyViewIndicator = EmptyViewIndicator.instance()!!
}

fun getEmptyIndicator(): RecyclerViewIndicator {
  return emptyViewIndicator.build()
}

}

Usage in an activity

  //at the top of activity
 lateinit var emptyRecyclerIndicator: RecyclerViewIndicator

 //anywhere
  emptyRecyclerIndicator = (applicationContext as MyApplication).getEmptyIndicator()

  recyclerView.layoutManager = LinearLayoutManager(this)
  emptyRecyclerIndicator.show(this, recyclerView)

Set RecyclerView Adapter

You need to override a method by registering DataObserver within the adapter as below.

override fun registerAdapterDataObserver(observer: AdapterDataObserver) {
    super.registerAdapterDataObserver(observer)
    val myApplication = context.applicationContext as MyApplication
    myApplication.getEmptyIndicator().recyclerViewState(itemList.size)

  }

Refresh the View

The view need to be refreshed when new data is fetched.

   emptyRecyclerIndicator.refresh()

EmptyRecyclerViewIndicator methods

Most of these methods are optional but essential for view customization.

Methods
Use
setNoDataExplaination(explaination: String) Used to set the message shown when there is no content
setLoadingExplaination(loadingStatus: String) Set the loading message
recyclerViewState(count: Int) Pass the items-count within the recyclerView adapter
refresh() Refresh the indicator state when fetching new data for the recyclerView
setWidth(width: Int) Set the width of the window that will be shown
setHeight(height: Int) Set the height of the window
setCustomLayout(layout: Int) Set the custom layout
show(activity: Activity, recylerView: RecyclerView) Used to attach the emptyViewIndicator to the recyclerView

Releases

No releases published

Packages

No packages published

Languages