All Projects → RaviKoradiya → LiveAdapter

RaviKoradiya / LiveAdapter

Licence: other
Auto updating RecyclerView Adapter for LiveData

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to LiveAdapter

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 (+5756%)
Mutual labels:  recyclerview-adapter, viewholder
livedata-recyclerview-sample
No description or website provided.
Stars: ✭ 76 (+52%)
Mutual labels:  recyclerview-adapter, livedata
LifecycleCells
An Android library that provides a Lifecycle to any ViewHolder through the implementation of the LifecycleOwner interface, allowing it to interact with a Lifecycle-Aware Component.
Stars: ✭ 19 (-62%)
Mutual labels:  viewholder, livedata
Fastadapter
The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
Stars: ✭ 3,512 (+6924%)
Mutual labels:  recyclerview-adapter, viewholder
Flexibleadapter
Fast and versatile Adapter for RecyclerView which regroups several features into one library to considerably improve the user experience :-)
Stars: ✭ 3,482 (+6864%)
Mutual labels:  viewholder, livedata
Elements
⚒ Modular components for RecyclerView development enforcing clean, reusable and testable code, with built-in support for paging and complex hierarchies of data.
Stars: ✭ 75 (+50%)
Mutual labels:  recyclerview-adapter, livedata
recyclerview-adapters
Multiple item adapters for RecyclerView (inspired by Merge Adapter)
Stars: ✭ 24 (-52%)
Mutual labels:  recyclerview-adapter
Restaurants
Restaurants sample app built with the new architecture components (LiveData, Room, ViewModel) and Dagger 2
Stars: ✭ 47 (-6%)
Mutual labels:  livedata
StateFlow-MVVM-MVI-demo
Using StateFlow as LiveData | StateFlow instead of LiveData | LiveData to StateFlow | StateFlow MVVM | StateFlow sample | StateFlow demo
Stars: ✭ 144 (+188%)
Mutual labels:  livedata
E-commerceRetailerFYP
Android E-commerce Platform. Allow retailer to post product, manage order, chat and view report
Stars: ✭ 31 (-38%)
Mutual labels:  recyclerview-adapter
LifecycleMvp
No description or website provided.
Stars: ✭ 20 (-60%)
Mutual labels:  livedata
Admobadapter
It wraps your Adapter to display Admob native ads and banners in a ListView/RecyclerView data set. It based on the Yahoo fetchr project https://github.com/yahoo/fetchr
Stars: ✭ 224 (+348%)
Mutual labels:  recyclerview-adapter
uMe
Online Chatting Application (Android) || Messaging App || Firebase
Stars: ✭ 138 (+176%)
Mutual labels:  recyclerview-adapter
MultiTypeAdapter
RecyclerView通用多类型适配器MultiTypeAdapter,以布局文件为单位更细粒度的条目复用。
Stars: ✭ 18 (-64%)
Mutual labels:  recyclerview-adapter
BaseToolsLibrary
Android通用适配器和常用的工具类
Stars: ✭ 24 (-52%)
Mutual labels:  recyclerview-adapter
recyclerview-expandable
RecyclerView implementation of traex's ExpandableLayout
Stars: ✭ 70 (+40%)
Mutual labels:  recyclerview-adapter
Adapterdelegates
"Favor composition over inheritance" for RecyclerView Adapters
Stars: ✭ 2,735 (+5370%)
Mutual labels:  recyclerview-adapter
NSE-Stock-Scanner
National Stock Exchange (NSE), India based Stock screener program. Supports Live Data, Swing / Momentum Trading, Intraday Trading, Connect to online brokers as Zerodha Kite, Risk Management, Emotion Control, Screening, Strategies, Backtesting, Automatic Stock Downloading after closing, live free day trading data and much more
Stars: ✭ 78 (+56%)
Mutual labels:  livedata
Modular2Recycler
Modular²Recycler is a RecyclerView.Adapter that is modular squared.
Stars: ✭ 72 (+44%)
Mutual labels:  recyclerview-adapter
LiveData
Android Architecture Component - LiveData example
Stars: ✭ 18 (-64%)
Mutual labels:  livedata

LiveAdapter

JitPack Android Arsenal License

LiveAdapter

Don't write a RecyclerView adapter again. Not even a ViewHolder!

  • Based on Android Data Binding
  • Written in Kotlin
  • Supports LiveData
  • No need to write the adapter
  • No need to write the ViewHolders
  • No need to modify your model classes
  • No need to notify the adapter when data set changes
  • Supports multiple item view types
  • Optional Callbacks/Listeners
  • Very fast — no reflection
  • Super easy API
  • Minimum Android SDK: 19

Setup

Gradle

Add it in your root build.gradle at the end of repositories:

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

Add the dependency to module build.gradle

// apply plugin: 'kotlin-kapt' // this line only for Kotlin projects

android {
    ...
    dataBinding.enabled true 
}

dependencies {
    implementation 'com.github.RaviKoradiya:LiveAdapter:1.3.4'
    // kapt 'com.android.databinding:compiler:GRADLE_PLUGIN_VERSION' // this line only for Kotlin projects
}

Usage

Create your item layouts with <layout> as root:

<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>
        <variable name="item" type="com.github.RaviKoradiya.LiveAdapter.item.Header"/>
    </data>
    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@{item.text}"/>
        
</layout>

It is important for all the item types to have the same variable name, in this case "item". This name is passed to the adapter builder as BR.variableName, in this case BR.item:

ObservableList or simple List
// Java
new LiveAdapter(listOfItems, BR.item)
           .map(Header.class, R.layout.item_header)
           .map(Point.class, R.layout.item_point)
           .into(recyclerView);
// Kotlin
LiveAdapter(listOfItems, BR.item)
           .map<Header>(R.layout.item_header)
           .map<Point>(R.layout.item_point)
           .into(recyclerView)

The list of items can be an ObservableList or LiveData<List> if you want to get the adapter automatically updated when its content changes, or a simple List if you don't need to use this feature.

LiveData<List<*>>
// Kotlin sample
LiveAdapter(
            data = liveListOfItems,
            lifecycleOwner = this@MainActivity,
            variable = BR.item )
           .map<Header, ItemHeaderBinding>(R.layout.item_header) {
               areContentsTheSame { old: Header, new: Header ->
                   return@areContentsTheSame old.text == new.text
               }
               areItemSame { old: Header, new: Header ->
                   return@areContentsTheSame old.text == new.text
               }
           }
           .map<Point, ItemPointBinding>(R.layout.item_point) {
               areContentsTheSame { old: Point, new: Point ->
                   return@areContentsTheSame old.id == new.id
               }
               areItemSame { old: Header, new: Header ->
                   return@areContentsTheSame old.text == new.text
               }
           }
           .into(recyclerview)

I suggest to implement DiffUtil ItemCallback while using LiveData.

NoDataCallback

A callback to manage "no data text or image view" visiblity.

// Kotlin sample
LiveAdapter(listOfItems, BR.item)
           .map<Header> ...
           .onNoData { noData ->
               textNoDataFound.visibility =
                   if (noData)
                       View.VISIBLE
                   else
                       View.GONE
           }
           ...
           .into(recyclerView)

LayoutHandler

The LayoutHandler interface allows you to use different layouts based on more complex criteria. Its one single method receives the item and the position and returns the layout resource id.

// Java sample
new LiveAdapter(listOfItems, BR.item)
           .handler(handler)
           .into(recyclerView);

private LayoutHandler handler = new LayoutHandler() {
    @Override public int getItemLayout(@NotNull Object item, int position) {
        if (item instanceof Header) {
            return (position == 0) ? R.layout.item_header_first : R.layout.item_header;
        } else {
            return R.layout.item_point;
        }
    }
};
// Kotlin sample
LiveAdapter(listOfItems, BR.item).layout { item, position ->
    when (item) {
        is Header -> if (position == 0) R.layout.item_header_first else R.layout.item_header
        else -> R.layout.item_point 
    }
}.into(recyclerView)

Acknowledgments

Thanks to Miguel Ángel Moreno for this library.

Author

Ravi Koradiya

I'm open to new challenging work - Hire me!

Email Upwork LinkedIn Facebook Twitter

License

Copyright 2020 Ravi Koradiya

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