title: MVVM and RecyclerView and LiveData
body: <p>I'm trying to implement a RecyclerView in a fragment using a <a href="https://developer.android.com/topic/libraries/architecture/guide.html" rel="nofollow noreferrer">MVVM approach</a> but I'm facing issues for the <strong>refresh of its content during the first load</strong>, bellow are the steps I'm following :</p>
  
  <ol>
  <li>I create the RecyclerView</li>
  <li><p>Set a custom adapter on it </p>
  
  <pre><code> recyclerView.setAdapter(adapter);
  </code></pre></li>
  <li><p>Subscribe to notifications on my model (persistance layer done with <a href="https://developer.android.com/topic/libraries/architecture/room.html" rel="nofollow noreferrer">Room</a>)</p>
  
  <pre><code> viewModel.getVideosForCategoryId(category.getId()).observe(this,
   videos -&gt; {
       if (videos.size() &gt; 0) {
           long catId = videos.get(0).getIdCategory();
          if (videosListAdapters.containsKey(catId)) {
              videosListAdapters.get(catId).updateList(videos);
          }
       }
  });
  </code></pre></li>
  <li><p>Update the RecyclerView via AsyncListDiffer as shown <a href="https://developer.android.com/reference/android/support/v7/recyclerview/extensions/AsyncListDiffer.html" rel="nofollow noreferrer">here</a> </p>
  
  <pre><code>public void updateList(List&lt;Video&gt; newList) {
      differ.submitList(newList);
  }
  </code></pre></li>
  </ol>
  
  <p>However, when the Observer is called for the first time, <strong>the data is there</strong> <code>videos.size() &gt; 0</code> and passed to the RecyclerView via <code>updateList(videos)</code> but the recycler view doesn't refresh itself and the callbacks from <code>AsyncListDiffer</code> are not called :</p>
  
  <pre><code>        @Override
          public boolean areItemsTheSame(
              @NonNull Video oldUser, @NonNull Video newUser) {
              // User properties may have changed if reloaded from the DB, but ID is fixed
              return oldUser.getIdVideo() == newUser.getIdVideo();
          }
  
          @Override
          public boolean areContentsTheSame(
              @NonNull Video oldUser, @NonNull Video newUser) {
              // NOTE: if you use equals, your object must properly override Object#equals()
              // Incorrectly returning false here will result in too many animations.
              return oldUser.equals(newUser);
          }
  </code></pre>
  
  <p>Thanks for your help</p>