How to make Paging library work with reverse recyclerview? : <p>How to use the latest paging with endless reverse recyclerview for the purpose of chat?</p>

<p>I have linear layout with reverse layout true:</p>

<pre><code>LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setReverseLayout(true);
layoutManager.setStackFromEnd(true);
</code></pre>

<p>and inside scroll listener : </p>

<pre><code>@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    int visibleItemCount = layoutManager.getChildCount();
    int totalItemCount = layoutManager.getItemCount();
    int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();

    if (!isLoading &amp;&amp; !isLastPage) {
        if ((visibleItemCount + firstVisibleItemPosition) &gt;= totalItemCount
                &amp;&amp; firstVisibleItemPosition &gt;= 0
                &amp;&amp; totalItemCount &gt;= PAGE_SIZE) {
            loadMoreItems();
        }
    }
}
</code></pre>

<p>The query for fetching messages:</p>

<pre><code>SELECT * FROM Message WHERE chatId = :chatId ORDER BY dbId ASC
</code></pre>

<p>Used for the room like below;</p>

<pre><code>@Query("SELECT * FROM Message WHERE chatId = :chatId ORDER BY dbId ASC")
DataSource.Factory&lt;Integer,Message&gt; fetchAll(String chatId);
</code></pre>

<p>The problem is that if I use ASC in the query, the list is automatically scrolling and fetching other messages. if used DESC, then message list is not coming in order.</p>

<p>Can anyone please help?</p>
