title: Using LiveData with Data Binding
body: <p>With the stabilization of Android Architecture Components I started updating all my basic <code>ViewModel</code>s to the new implementation of<a href="https://developer.android.com/topic/libraries/architecture/viewmodel.html" rel="noreferrer"><code>ViewModel</code></a>. In my understanding, the usage of <a href="https://developer.android.com/topic/libraries/architecture/livedata.html" rel="noreferrer"><code>LiveData</code></a> is recommended to hold the <code>Model</code> class since it handles the lifecycle better.</p>
  
  <p>I like using <code>Data Binding</code> because it makes the code clearer in Java/Kotlin side and it is not needed to "watch" the value changes to update the UI. However the layout using <code>Data Binding</code> only watch data changes if the <code>Model</code> (or the ViewModel) extends <a href="https://developer.android.com/reference/android/databinding/BaseObservable.html" rel="noreferrer"><code>BaseObservable</code></a> and <code>LiveData</code> does not. I understand the one of the main objectives of <code>LiveData</code> is to be observed and updates the UI programmatically but for simple updates, <code>Data Binding</code> is very useful.</p>
  
  <p>This issue was already reported (<a href="https://github.com/googlesamples/android-architecture-components/issues/34#issuecomment-305991529" rel="noreferrer">GitHub</a> and <a href="https://stackoverflow.com/questions/44077566/how-to-combine-architecture-components-with-data-binding-on-android#comment82259306_44178060">Stack Overflow</a>) and first was said that the version 1.0 would have it and now is said that this feature is in development.</p>
  
  <p>In order to use both <code>LiveData</code> and <code>Data Binding</code>, I created a very simple implementation of class that extends <code>BaseObservable</code>:</p>
  
  <pre><code>import android.arch.lifecycle.LiveData
  import android.arch.lifecycle.MutableLiveData
  import android.databinding.BaseObservable
  
  class ObservableMutableLiveData&lt;T&gt;() : BaseObservable() {
  
      private var data: MutableLiveData&lt;T&gt; = MutableLiveData()
  
      constructor(data: T) : this() {
          this.data.value = data
      }
  
      public fun set(value: T) {
          if (value != data.value) {
              data.value = value
              notifyChange()
          }
      }
  
      public fun get(): T? {
          return data.value
      }
  
      public fun getObservable(): LiveData&lt;T&gt; {
          return data
      }
  }
  </code></pre>
  
  <p>So basically my <code>ObservableMutableLiveData</code> is a copy of <a href="https://android.googlesource.com/platform/frameworks/data-binding/+/c9a5d6f140f732ca0ff279a4b1ee315072e1c422/library/src/main/java/android/databinding/ObservableField.java" rel="noreferrer"><code>ObservableField</code></a> using <code>LiveData</code> to store the model and with this implementation, the layout updates after every model update.</p>
  
  <p>The questions are:</p>
  
  <ul>
  <li>Is this a bad implementation of <code>LiveData</code>? Does this wrapper "breaks" the functionalities of <code>LiveData</code>, such as be lifecycle-aware?</li>
  <li>In my understanding, <code>LiveData</code> is the new <code>ObservableField</code>. Is this correct?</li>
  </ul>