An android library for quick setup of RecyclerView

Overview

SmartRecyclerView for Android

An android library to quickly setup RecyclerView(List) with SwipeRefreshLayout Support, written entirely in Kotlin.

Works with Android YourActionName Actions Status

Supported Platforms


Works on Android 5.0+ (API level 21+) and on Java 8+.

Let's do it quickly!


The simplest way to start

allprojects {
     repositories {
	maven { url 'https://jitpack.io' }
     }
}


buildFeatures {
     dataBinding = true
}


dependencies {
     implementation 'com.github.Kunalapk:SmartRecyclerView:TAG'
}

activity_main.xml

">
xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <com.kunalapk.smartrecyclerview.view.SmartRecyclerView
	android:id="@+id/smartRecyclerView"
	android:layout_width="match_parent"
	android:layout_height="match_parent"/>

androidx.constraintlayout.widget.ConstraintLayout>

Using Activity


lateinit var smartRecyclerView:SmartRecyclerView<T>
override fun onCreate(savedInstanceState: Bundle?) {
     super.onCreate(savedInstanceState)
     setContentView(R.layout.activity_main)

     smartRecyclerView = findViewById(R.id.smartRecyclerView)
     smartRecyclerView.apply{
     	initSmartRecyclerView(activity = this,smartRecyclerViewListener = smartRecyclerViewListener,isPaginated = true)
	isEnabled = false // enable/disable SwipeRefreshLayout
	setClickListener(onItemClickListener) // (optional, set clickListener on recyclerview items)
	setViewAttachListener(viewAttachListener) // (optional, set viewAttachListener on recyclerview items)
	setScrollListener(recyclerViewListener) // (optional, set setScrollListener on recyclerview items)
	setShimmerLayout(R.layout.item_loader) // (optional, set shimmer layout while user waits for the data to load)
     }
}

set custom LayoutManager

val linearLayoutManager = LinearLayoutManager(context,RecyclerView.HORIZONTAL,false)
initSmartRecyclerView(activity = this,smartRecyclerViewListener = smartRecyclerViewListener,isPaginated = true, layoutManager = linearLayoutManager)

setAnyObject as extra parameter

val username = "Steve Jobs"
smartRecyclerView.apply{
    setAnyObject(username)
}

smartRecyclerViewListener

private val smartRecyclerViewListener:SmartRecyclerViewListener<T> = object:SmartRecyclerViewListener<T>{

        override fun getItemViewType(model: T): Int {
            return 0 //return viewType from model
        }

        override fun getViewLayout(viewType: Int): Int {
            return R.layout.item_file // on the basis of viewType return the layout you want for the recyclerview item.
        }

        override fun setListSize(size: Int) {
	    //this method will be called whenever smartRecyclerView undergoes any operation.
        }

        override fun onRefresh() {
            //do something on refresh....
            smartRecyclerView.isRefreshing = false
            Toast.makeText(baseContext,"OnRefresh Called",Toast.LENGTH_LONG).show()
        }

        override fun onLoadNext() {
	    // onLoadNext() will be called if isPaginated = true and user scrolls to bottom or the smartRecyclerView.
            Toast.makeText(baseContext,"OnLoadNext",Toast.LENGTH_LONG).show()
        }
	
	
	//DiffUtils Callback functions
	
	override fun areContentsTheSame(newItem: T, oldItem: T): Boolean {
            return newItem.distance==oldItem.distance
        }

        override fun areItemsTheSame(newItem: T, oldItem: T): Boolean {
            return newItem.uuid==oldItem.uuid
        }

    }

item_file.xml example

">
xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto">
    <data>
        <variable
            name="model"
            type="com.kunalapk.demo.ModelData" />

        <variable
            name="position"
            type="Integer" />

        <variable
            name="clicklistener"
            type="com.kunalapk.smartrecyclerview.listener.OnItemClickListener" />
	    
    	<variable
	    name="anyobject"
	    type="String"/> 
    data>

    <androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="400dp"
        android:clickable="true"
        android:id="@+id/clRoot"
        android:onClick="@{() -> clicklistener.onItemClick(model)}"
	>

	<TextView
	    android:id="@+id/tvNumber"
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:text="@{position + ` - ` + model.name}"
	    app:layout_constraintTop_toTopOf="parent"
	    app:layout_constraintStart_toStartOf="parent"
	    app:layout_constraintEnd_toEndOf="parent"
	    app:layout_constraintBottom_toBottomOf="parent"/>

    androidx.constraintlayout.widget.ConstraintLayout>
layout>

addItems to SmartRecyclerView

private fun addMultipleItems(list: MutableList<Model>){
    smartRecyclerView.addItems(list)
}

private fun addSingleItem(model : Model){
    smartRecyclerView.addItem(model)
}

addItemsWithDiffUtil to SmartRecyclerView

private fun addMultipleItemsWithDiffUtil(list: MutableList<Model>){
    smartRecyclerView.addItemsWithDiffUtil(list)
}

LICENSE

Copyright 2021 Kunal Pasricha

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.
You might also like...
Android library defining adapter classes of RecyclerView to manage multiple view types
Android library defining adapter classes of RecyclerView to manage multiple view types

RecyclerView-MultipleViewTypeAdapter RecyclerView adapter classes for managing multiple view types Release Note [Release Note] (https://github.com/yqr

Android library for RecyclerView to manage order of items and multiple view types.
Android library for RecyclerView to manage order of items and multiple view types.

recyclerview-binder Android Library for RecyclerView to manage order of items and multiple view types. Features Insert any items to wherever you want

Android Library to provide swipe, click and other functionality to RecyclerView

RecyclerViewEnhanced Android Library to provide swipe, click and other functionality to RecyclerView Usage Add this to your build.gradle file dependen

Epoxy is an Android library for building complex screens in a RecyclerView

Epoxy Epoxy is an Android library for building complex screens in a RecyclerView. Models are automatically generated from custom views or databinding

RecyclerView extension library which provides advanced features. (ex. Google's Inbox app like swiping, Play Music app like drag and drop sorting)
RecyclerView extension library which provides advanced features. (ex. Google's Inbox app like swiping, Play Music app like drag and drop sorting)

Advanced RecyclerView This RecyclerView extension library provides Google's Inbox app like swiping, Play Music app like drag-and-drop sorting and expa

An efficient TabLayout library implemented with RecyclerView.
An efficient TabLayout library implemented with RecyclerView.

RecyclerTabLayout An efficient TabLayout library implemented with RecyclerView. Features Efficient when having many tabs Easy setup with ViewPager (sa

the library is a loop RecyclerView(expression), can show some effects when display
the library is a loop RecyclerView(expression), can show some effects when display

CircleRecyclerView the library is a loop RecyclerView, can show some effects when display screenshot CircularViewMode ScaleXViewMode & ScaleYViewMode

Elegant design and convenient to use RecyclerView adapter library based on Kotlin DSL.
Elegant design and convenient to use RecyclerView adapter library based on Kotlin DSL.

xAdapter: Kotlin DSL 风格的 Adapter 封装 1、简介 该项目是 KotlinDSL 风格的 Adapter 框架封装,用来简化 Adapter 调用,思想是采用工厂和构建者方式获取 Adapter 避免代码中定义大量的 Adapter 类。该项目在 BRVAH 的 Ada

A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.
A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.

UltimateRecyclerView Master branch: Dev branch: Project website:https://github.com/cymcsg/UltimateRecyclerView Description UltimateRecyclerView is a R

Releases(1.93)
Owner
Kunal Pasricha
Google Certified Associate Android Developer
Kunal Pasricha
TikTok-RecyclerView - This is a demo app built using 'Koin' a new dependency injection framework for Android along with RecyclerView and ExoPlayer2.

TikTok-RecyclerView Demo About This is a demo app built using 'Koin' a new dependency injection framework for Android along with RecyclerView and ExoP

Baljeet Singh 19 Dec 28, 2022
A RecyclerView that implements pullrefresh and loadingmore featrues.you can use it like a standard RecyclerView

XRecyclerView a RecyclerView that implements pullrefresh , loadingmore and header featrues.you can use it like a standard RecyclerView. you don't need

XRecyclerView 5.3k Dec 26, 2022
A RecyclerView that implements pullrefresh and loadingmore featrues.you can use it like a standard RecyclerView

XRecyclerView a RecyclerView that implements pullrefresh , loadingmore and header featrues.you can use it like a standard RecyclerView. you don't need

XRecyclerView 5.3k Dec 26, 2022
Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager.

Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager.

Jack and phantom 504 Dec 25, 2022
RecyclerView : SleepQualityTracker with RecyclerView app

RecyclerView - SleepQualityTracker with RecyclerView app SleepQualityTracker with RecyclerView This app builds on the SleepQualityTracker developed pr

Kevin 2 May 14, 2022
Pagination-RecyclerView - Simple and easy way to Paginating a RecyclerView

Pagination-RecyclerView Simple and easy way to Paginating a RecyclerView Android

Rakshit Nawani 0 Jan 3, 2022
An Android Animation library which easily add itemanimator to RecyclerView items.

RecyclerView Animators RecyclerView Animators is an Android library that allows developers to easily create RecyclerView with animations. Please feel

Daichi Furiya 11.2k Jan 8, 2023
Android library providing simple way to control divider items (ItemDecoration) of RecyclerView

RecyclerView-FlexibleDivider Android library providing simple way to control divider items of RecyclerView Release Note [Release Note] (https://github

Yoshihito Ikeda 2.4k Dec 18, 2022
Android Library to provide swipe, click and other functionality to RecyclerView

RecyclerViewEnhanced Android Library to provide swipe, click and other functionality to RecyclerView Usage Add this to your build.gradle file dependen

Nikhil Panju 1k Dec 29, 2022