Skip to content

Team-SOFTsk/ObservableAdapter

Repository files navigation

ObservableCollection

RecyclerView Adapter for RxJava, separates list's model from Android framework dependencies

Download Maven Central

Introduction

Supports RxJava2 and automatic adapter notify dispatching (via DiffUtils comparison)

Usage

First, import the library via gradle dependency

compile 'sk.teamsoft:observablecollection:{latest_version}'

Check Sample app for both simple and advanced use-cases.

Simple case

  1. Create source (here, Data is the model class)
val source = SimpleAdapterSource<Data>(emptyList(), R.layout.view_data)
  1. Create Adapter and set to RecyclerView
recyclerView.adapter = ObservableAdapter(source)
  1. Prepare View
<sk.teamsoft.observableadapterdemo.simple.DataView ...>
    <TextView android:id="@+id/data" .../>
</sk.teamsoft.observableadapterdemo.simple.DataView>
class DataView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr), BindableView<Data> {

    private val label: TextView by lazy { findViewById(R.id.data) }
    private val detail: TextView by lazy { findViewById(R.id.data_detail) }

    override val observableEvent: Observable<Any>?
        get() = RxView.clicks(this)

    override fun bindTo(item: Data) {
        label.text = item.label
        detail.text = item.detail
    }
}
  1. Set data
source.data = listOf(data1, data2, data3)

Advanced use case

Take a look at Advanced demo

Contact

Team-SOFT s.r.o.
dusan@teamsoft.sk

About

RecyclerView Adapter for RxJava, separates collection model from Android framework dependencies

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages