A simple and easy adapter for RecyclerView. You don't have to make adapters and view holders anymore. Slush will help you.

Overview


한국어

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

  • ItemClickListener
  • DataBinding
  • DiffCallback
  • ObservableArrayList
  • 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.
You might also like...
Adapter library for SharedPreferences

EasyPrefs Adapter library for SharedPreferences which reduces boilerplate needed to store simple data, but open enough to not interfere with your own

Make interesting books for your kids, usint text and images from simple.wikipedia.org

Baby Book Builder Baby Book Builder is an Android app and a website for creating books to help your growing child learn. Contributing Donations Baby B

Koin Annotations - help declare Koin definition in a very fast and intuitive way, and generate all underlying Koin DSL for you

The goal of Koin Annotations project is to help declare Koin definition in a very fast and intuitive way, and generate all underlying Koin DSL for you. The goal is to help developer experience to scale and go fast 🚀 , thanks to Kotlin Compilers.

Android Ptrace Inject for all ABIs and all APIs. Help you inject Shared Library on Android.

Android Ptrace Inject 中文可以参考我的注释内容进行理解 我写的注释相对来说比较全面了 How to build Make sure you have CMake and Ninja in your PATH Edit CMakeLists.txt. Set ANDROID_ND

Example mod with Mixin to help you to get started with creating a mod with mixins.

ExampleMixinMod Example mod with Mixin to help you to get started with creating a mod with mixins. For usage of mixins, see here. Also, remember to tu

Android Library to make SharedPreferences usage easier.

KotlinPreferences Kotlin Android Library, that makes preference usage simple and fun. KotlinPreferences now have a brother. With KotlinPreferences, yo

Make a cool intro for your Android app.
Make a cool intro for your Android app.

AppIntro AppIntro is an Android Library that helps you build a cool carousel intro for your App. AppIntro has support for requesting permissions and h

A collection of small utility functions to make it easier to deal with some otherwise nullable APIs on Android.

requireKTX requireKTX is a collection of small utility functions to make it easier to deal with some otherwise nullable APIs on Android, using the sam

Kstr is a set of helpful methods library for Kotlin intended for make the developer life easier.

Kstr is a set of helpful methods library for Kotlin intended for make the developer life easier. Kstr uses the powerful feature of extension func

Releases(1.2.2)
Owner
SeungHyun
하고 싶은게 많은 안드로이드 개발자
SeungHyun
RecyclerView Adapter Library with different models and different layouts as convenient as possible.

RecyclerView Presenter Convenience library to handle different view types with different presenters in a single RecyclerView. How to install repositor

Jan Rabe 86 Dec 26, 2022
Android RecyclerView Adapter with nested items & expand/contract functionality

AccordionRecycler Android RecyclerView Adapter with nested items & expand/contract functionality With AccordionRecycler you can easily create awesome

Fanis Veizis 17 Aug 18, 2022
Don't write a RecyclerView adapter again. Not even a ViewHolder!

LastAdapter Don't write a RecyclerView adapter again. Not even a ViewHolder! Based on Android Data Binding Written in Kotlin No need to write the adap

Miguel Ángel Moreno 781 Dec 19, 2022
🚆 Retrofit adapters for modeling network responses with Kotlin Result, Jetpack Paging3, and Arrow Either.

Retrofit Adapters ?? Retrofit adapters for modeling network responses with Kotlin Result, Jetpack Paging3, and Arrow Either. Sandwich If you're intere

Jaewoong Eum 293 Dec 26, 2022
Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager.

Carousel Recyclerview Create carousel effect in recyclerview with the CarouselRecyclerview in a simple way. Including in your project Gradle Add below

Jack and phantom 514 Jan 8, 2023
👋 A common toolkit (utils) ⚒️ built to help you further reduce Kotlin boilerplate code and improve development efficiency. Do you think 'kotlin-stdlib' or 'android-ktx' is not sweet enough? You need this! 🍭

Toolkit [ ?? Work in progress ⛏ ?? ??️ ?? ] Snapshot version: repositories { maven("https://s01.oss.sonatype.org/content/repositories/snapshots") }

凛 35 Jul 23, 2022
A small DSL to make building a conversation in Bukkit easy.

Konversation Konversation provides a simple builder to construct chains of prompts to be used in the conversation API present in Bukkit. Bukkit only p

Tim Hagemann 2 Dec 4, 2022
ZoomHelper will make any view to be zoomable just like Instagram pinch-to-zoom

ZoomHelper ZoomHelper will make any view to be zoomable just like the Instagram pinch-to-zoom. ?? Installation ZoomHelper is available in the JCenter,

AmirHosseinAghajari 238 Dec 25, 2022
This library is a set of simple wrapper classes that are aimed to help you easily access android device information.

SysInfo Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the device info

Klejvi Kapaj 7 Dec 27, 2022
The Android maps adapter

MapMe MapMe is an Android library for working with Maps. MapMe brings the adapter pattern to Maps, simplifying the management of markers and annotatio

Trade Me 849 Dec 27, 2022