title: FastAdapter flickers after loading from LiveData even though the data stays same
body: <p>For the question I have prepared <a href="https://github.com/afarber/android-questions/tree/master/TopPlayers" rel="nofollow noreferrer">a simple and working example at Github</a>:</p>
  
  <p><a href="https://i.stack.imgur.com/6KpX6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6KpX6.png" alt="app screenshot"></a></p>
  
  <p>My example app downloads a JSON array containing top 30 players in a game using okhttp and stores them into SQLite Room. In the <a href="https://github.com/afarber/android-questions/tree/master/TopPlayers/app/src/main/java/de/afarber/topplayers" rel="nofollow noreferrer">fragment</a> I observe the corresponding <code>LiveData&lt;List&lt;TopEntity&gt;&gt;</code> object and update the FastAdapter instance:</p>
  
  <pre><code>public class TopFragment extends Fragment {
      private final ItemAdapter&lt;TopItem&gt; mItemAdapter = new ItemAdapter&lt;&gt;();
      private final FastAdapter&lt;TopItem&gt; mFastAdapter = FastAdapter.with(mItemAdapter);
  
      private TopViewModel mViewModel;
      private ProgressBar mProgressBar;
      private RecyclerView mRecyclerView;
  
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater,
                               ViewGroup container,
                               Bundle savedInstanceState) {
  
          mViewModel = ViewModelProviders.of(this).get(TopViewModel.class);
          mViewModel.getTops().observe(this, tops -&gt; {
              mItemAdapter.clear();
              for (TopEntity top: tops) {
                  TopItem item = new TopItem(top);
                  mItemAdapter.add(item);
              }
          });
  
          View v = inflater.inflate(R.layout.top_fragment, container, false);
          mProgressBar = v.findViewById(R.id.progressBar);
          mRecyclerView = v.findViewById(R.id.recyclerView);
          mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
          mRecyclerView.setAdapter(mFastAdapter);
  
          fetchJsonData();
  
          return v;
      }
  </code></pre>
  
  <p>My problem is: the recycler view flickers once - every time the data is downloaded. </p>
  
  <p>Even though the top 30 does not change often, i.e. the data stays same.</p>
  
  <p>When I look at the example app in the excellent <a href="https://github.com/mikepenz/FastAdapter" rel="nofollow noreferrer">FastAdapter</a> library by Mr. Penz, I do not see any flickering there.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I've got <a href="https://github.com/mikepenz/FastAdapter/issues/737" rel="nofollow noreferrer">a hint</a> that the flickering is obviously caused by calling <code>mItemAdapter.clear();</code> in the <code>onChanged</code> method and I should use DiffUtil class instead.</p>
  
  <p>So I have added a new class:</p>
  
  <pre><code>public class DiffCallback extends DiffUtil.Callback {
      private final List&lt;TopItem&gt; mOldList;
      private final List&lt;TopItem&gt; mNewList;
  
      public DiffCallback(List&lt;TopItem&gt; oldStudentList, List&lt;TopItem&gt; newStudentList) {
          this.mOldList = oldStudentList;
          this.mNewList = newStudentList;
      }
  
      @Override
      public int getOldListSize() {
          return mOldList.size();
      }
  
      @Override
      public int getNewListSize() {
          return mNewList.size();
      }
  
      @Override
      public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
          TopItem oldItem = mOldList.get(oldItemPosition);
          TopItem newItem = mNewList.get(newItemPosition);
  
          return oldItem.uid == newItem.uid;
      }
  
      @Override
      public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
          TopItem oldItem = mOldList.get(oldItemPosition);
          TopItem newItem = mNewList.get(newItemPosition);
  
          return oldItem.elo == newItem.elo &amp;&amp;
                  oldItem.given.equals(newItem.given) &amp;&amp;
                  //oldItem.photo != null &amp;&amp; oldItem.photo.equals(newItem.photo) &amp;&amp;
                  oldItem.avg_time != null &amp;&amp; oldItem.avg_time.equals(newItem.avg_time) &amp;&amp;
                  oldItem.avg_score == newItem.avg_score;
      }
  
      @Nullable
      @Override
      public Object getChangePayload(int oldItemPosition, int newItemPosition) {
          return super.getChangePayload(oldItemPosition, newItemPosition);
      }
  }
  </code></pre>
  
  <p>And then I am trying to use it in the <code>onChanged</code> method instead of just calling <code>mItemAdapter.clear()</code> but the RecyclerView stays empty even though the <code>tops</code> has elements:</p>
  
  <pre><code>mViewModel = ViewModelProviders.of(this).get(TopViewModel.class);
  mViewModel.getTops().observe(this, tops -&gt; {
      List&lt;TopItem&gt; oldList = mItemAdapter.getAdapterItems();
      List&lt;TopItem&gt; newList = new ArrayList&lt;&gt;();
      for (TopEntity top: tops) {
          TopItem item = new TopItem(top);
          newList.add(item);
      }
  
      DiffCallback diffCallback = new DiffCallback(oldList, newList);
      DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(diffCallback);
  
      mItemAdapter.getAdapterItems().clear();
      mItemAdapter.getAdapterItems().addAll(newList);
      diffResult.dispatchUpdatesTo(mFastAdapter);
  });
  </code></pre>
  
  <p><strong>SHORT SUMMARY OF MY PROBLEM:</strong></p>
  
  <p>My real app uses <code>FastAdapter</code> for several reasons and I am looking for a way to "marry" it with <a href="https://developer.android.com/reference/android/support/v7/util/DiffUtil" rel="nofollow noreferrer">DiffUtil</a> in order to eliminate the one-time flickering when the data is downloaded over HTTPS and updated in Room.</p>