Giter VIP home page Giter VIP logo

empty-recyclerview-indicator's Introduction

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

empty-recyclerview-indicator's People

Contributors

amoskorir avatar

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.