Skip to content

Flexible data binding library implemented with Java. Contains Android bindings and Kotlin extensions.

Notifications You must be signed in to change notification settings

codeerow/Databinding

Repository files navigation

Databinding

Data binding interfaces with implementations for Android Java and Kotlin. No code generation. You can easily extend it but your own!

Latest version:

Now available:

View

  • visibility
  • enabled
  • click

TextView

  • text

Recycler view

  • items

Seekbar

  • progress (int)

Toolbar

  • nav button click

Installation

Gradle is the only supported build configuration.

Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

Step 2. Add the dependency

dependencies {
        implementation "com.github.codeerow.databinding:core:2.0.1-beta"
        implementation "com.github.codeerow.databinding:androidx-core:2.0.1-beta" // androidx-core-ktx for Kotlin
        implementation "com.github.codeerow.databinding:androidx-recyclerview:2.0.1-beta" // androidx-recyclerview-ktx for Kotlin
}

Usage

ViewModel:

    val name = MutableLiveData<String>()
    val email = MutableLiveData<String>()
    val title = MutableLiveData<String>()
    val description = MutableLiveData<String>()

LifecycleOwner (e.g. Fragment):

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        dataBinding {
            with(inputName) {
                text(viewModel.name, twoWay = true)
            }
            with(inputEmail) {
                text(viewModel.email, twoWay = true)
            }
            with(inputTitle) {
                text(viewModel.title, twoWay = true)
            }
            with(inputDescription) {
                text(viewModel.description, twoWay = true)
            }
        }
    }