title: RecyclerView, DiffUtil and weird animation
body: <p>I have a chat app working with websockets.
  Via websocket I receive message, which I save into db, messages table, and update <code>last message id</code> in conversation table. Now, both saves will notify cursor. So I call <code>updateDate</code> twice. They will run sequentially, in correct order and on correct threads. Yet, I guess, the animations are overlapping and making weird effect visible in <a href="https://youtu.be/on8EabRQgew" rel="nofollow noreferrer">youtube video attached</a> (visible from message "i"). Can anybody pinpoint my problem or give me solution?</p>
  
  <p>I am using rxjava for threading and dequeue for stacking updates, while always getting only last update from dequeue. Inspiration from vlc <a href="https://geoffreymetais.github.io/code/diffutil-threading/" rel="nofollow noreferrer">here</a></p>
  
  <p>RecyclerView is stacking from end and if user is scrolled to bottom, then animation scroll to bottom is run when new message comes.</p>
  
  <p><strong>Fragment</strong></p>
  
  <pre><code>adapter = ChatMessageAdapter()
  recycler.apply {
      adapter = this@ChatDetailFragment.adapter
      layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false).apply { stackFromEnd = true }
  }
  </code></pre>
  
  <p><strong>ChatMessageAdapter</strong></p>
  
  <pre><code>private val pendingUpdates: ArrayDeque&lt;Single&lt;Pair&lt;MutableList&lt;ChatItemHolder&gt;, DiffUtil.DiffResult&gt;&gt;&gt; = ArrayDeque()
  
  @MainThread
  fun updateData(msgs: MutableList&lt;ChatMessage&gt;, onDone: () -&gt; Unit) {
      pendingUpdates.add(
          internalUpdate(msgs)
              .subscribeOn(Schedulers.computation())
              .observeOn(AndroidSchedulers.mainThread())
              .doOnSuccess {
                  items.clear()
                  items.addAll(it.first)
                  it.second.dispatchUpdatesTo(this@ChatMessageAdapter)
                  onDone()
              }
      )
      if (pendingUpdates.size == 1) pendingUpdates.peek().subscribe(Consumer {processQueue()})
  }
  
  private fun internalUpdate(msgs: MutableList&lt;ChatMessage&gt;) = Single.create&lt;Pair&lt;MutableList&lt;ChatItemHolder&gt;, DiffUtil.DiffResult&gt;&gt; {
      val newItems = temp(msgs) // transforming function from ChatMessage[] to ChatItemHolder[]
      val result = DiffUtil.calculateDiff(DiffUtilCallback(newItems, items), true)
      it.onSuccess(Pair(newItems, result))
  }
  
  @MainThread
  private fun processQueue() {
      pendingUpdates.remove()
      if (!pendingUpdates.isEmpty()) {
          if (pendingUpdates.size &gt; 1) {
              val last = pendingUpdates.peekLast()
              pendingUpdates.clear()
              pendingUpdates.add(last)
          }
          pendingUpdates.peek().subscribe(Consumer { processQueue() })
      }
  }
  </code></pre>
  
  <p>Thank you!</p>