ObservableAdapter
ObservableAdapter copied to clipboard
RecyclerView Adapter for RxJava, separates collection model from Android framework dependencies
ObservableCollection
RecyclerView Adapter for RxJava, separates list's model from Android framework dependencies
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
- Create source (here,
Datais the model class)
val source = SimpleAdapterSource<Data>(emptyList(), R.layout.view_data)
- Create Adapter and set to RecyclerView
recyclerView.adapter = ObservableAdapter(source)
- 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
}
}
- Set data
source.data = listOf(data1, data2, data3)
Advanced use case
Take a look at Advanced demo
Contact
Team-SOFT s.r.o.
[email protected]