Slush

A simple and easy adapter for RecyclerView. You don't have to make adapters and view holders anymore. Slush will help you.
Alternatives To Slush
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Binding Collection Adapter1,7134332 years ago15March 08, 202031apache-2.0Java
Easy way to bind collections to listviews and recyclerviews with the new Android Data Binding framework
Databinding Samples1,617
3 months ago29apache-2.0Kotlin
Mvvm_hacker_news887
6 years ago6Java
Android MVVM experiment project using the official Data Binding library
Reactive381
6 years ago12JavaScript
Tiny reactive template engine
Items258
4 years agoapache-2.0Kotlin
Generate data-view-binding adapters of android recycler view.
Databindingadapter248
7 years ago6apache-2.0Java
Super simple RecyclerView adapter using Data Binding Technology.
Lazyloadingviews202
6 years agoapache-2.0Java
Loading effect for the child views in Adapter View before binding data from service.
Lastpageradapter181
6 years ago2Kotlin
Don't write a ViewPager Adapter! Hook up your ViewPager to your data model using Android Data Binding Framework. With Kotlin support!
Easyadapter147
a year ago4Java
Recyclerview adapter library- Create adapter in just 3 lines of code
Bindingjs122
6 years ago15mpl-2.0JavaScript
Separable, Reactive, Model-Agnostic View Data Binding for JavaScript
Alternatives To Slush
Select To Compare


Alternative Project Comparisons
Readme


한국어

Download Android CI

No more boilerplate adapters and view holders.
Slush will make using RecyclerView easy and fast.

The goal of this project is to make RecyclerView, which is not very complicated, possible with Slush.

Features

  • [x] ItemClickListener
  • [x] DataBinding
  • [x] DiffCallback
  • [x] ObservableArrayList
  • [x] LiveData
  • [ ] MultiType Adapter
  • [ ] (Divider)ItemDecoration
  • [ ] Swipe option

Setup

Add a dependency below at your build.gradle(app)

dependencies {
    implementation 'in.seunghyun:slush:1.2.2'
}

Basic Usage

You can use all the features with a single class called Slush.

Basically, you have to write some codes below. (Here, Replace the SimpleItem part into your item class to use.)

Slush.SingleType<SimpleItem>()
    .setItemLayout(R.layout.simple_binding_item) // Set item layout
    .setLayoutManager(LinearLayoutManager(this)) // Set LayoutManager (No need to write if already exists)
    .onBind { view, item ->
        view.itemName.text = item.name
    }
    .into(recyclerView)

Initialize views in item layout in onBind. (Similar to onBindViewHolder of RecyclerView Adapter)

ItemListEditor

ItemListEditor is an interface that allows you to edit the item list.

val result = Slush.SingleType<SimpleItem>()
    // Omit intermediate code
    .into(recyclerView)
val itemListEditor = result.itemListEditor

The available methods are listed here.

DataBinding

Slush supports data binding.

You should change onBind part to onBindData to use data binding.

.onBindData<SimpleItemBinding> { binding, item ->
    binding.item = item
}

And put your generated binding class into SimpleItemBinding part.

LiveData, ObservableList

If you use LiveData or ObservableList, you don't need to use ItemListEditor because slush will automatically observe the list and update RecyclerView.

LiveData

val itemsLiveData = MutableLiveData<List<SimpleItem>>()

Slush.SingleType<SimpleItem>()
    // Omit intermediate code
    .setItems(itemsLiveData, lifecycleOwner)
    .into(recyclerView)

Full code

Furthermore

BasicDiffCallback is applied by default when using LiveData.
If you don't want to use DiffCallback, you can put false as the third argument of setItems

.setItems(itemsLiveData, lifecycleOwner, false)

ObservableList

val observableItems = ObservableArrayList<SimpleItem>()

Slush.SingleType<SimpleItem>()
    // Omit intermediate code
    .setItems(observableItems)
    .into(recyclerView)

Full code

Furthermore

Slush does not remove the observer automatically.
So you can use ObserveController to remove the observer.

val result = Slush.SingleType<SimpleItem>()
    // Omit intermediate code
    .setItems(observableItems)
    .into(recyclerView)

val observeController = ObserveController(result)
observeController.stopObserving()

Options

You can apply these options selectively.

setItems

.setItems(items)

Set an initial item list.

onItemClick

.onItemClick { clickedView, position ->
    Log.d(TAG, "Clicked: $position")
}

Set a listener to be executed when item is clicked.

setDiffCallback

.setDiffCallback(BasicDiffCallback())

Set a DiffCallback to be used when you call changeAll in ItemListEditor
By default, calling changeAll replaces all data in the list, but if you set DiffCallback, only the modified part is changed, so animation occurs.
You can also use custom DiffCallback by inheriting SlushDiffCallback.

Samples

You can also see the sample codes here.

License

MIT License

Copyright (c) 2020 SeungHyun

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
Popular Adapter Projects
Popular Bindings Projects
Popular Libraries Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Kotlin
Bindings
Adapter
Kotlin Android
Observer
Livedata
Databinding