RaviKoradiya / LiveAdapter

Auto updating RecyclerView Adapter for LiveData
52 stars 5 forks source link

Can we use it without databinding ? #1

Open ahmadmssm opened 3 years ago

RaviKoradiya commented 3 years ago

@ahmadmssm I will try to add it in the next version and release it soon.

ahmadmssm commented 3 years ago

Thanks, I will wait for this feature.

RaviKoradiya commented 3 years ago

@ahmadmssm try version 1.3.4-alpha for implementation without data-binding.

    val dummyList = listOf<Any>(1, "Test Item 2", 4.5, 7, 5.8, "Dummy Item 3")

    LiveAdapter(dummyList)
            .map<Int>(R.layout.item_rv) {
                onBind {
                    it.binding.getViewById<TextView>(R.id.text_item_label)?.text = "Int Item ${it.binding.data}"
                }
            }
            .map<Double>(R.layout.item_rv) {
                onBind {
                    it.binding.getViewById<TextView>(R.id.text_item_label)?.text = "Float Item ${it.binding.data}"
                }
            }
            .map<String>(R.layout.item_rv) {
                onBind {
                    it.binding.getViewById<TextView>(R.id.text_item_label)?.text = it.binding.data
                }
            }
            .into(findViewById(R.id.rv_dummy))

If you are using kotlin, Don't forget to add apply plugin: 'kotlin-kapt' at the top section and kapt 'com.android.databinding:compiler:GRADLE_PLUGIN_VERSION' in dependencies block of the module's build.gradle file.

RaviKoradiya commented 3 years ago

@ahmadmssm let me know if you face any issues with it. I will move this version to stable and close this issue after a week from now.