N
N
Nicholas Unknown2020-11-12 15:28:43
Android
Nicholas Unknown, 2020-11-12 15:28:43

Why doesn't DiffUtils work correctly?

Implemented pagination following the example:
https://m.habr.com/ru/post/431212/comments/

After loading the first portion of the data, it transfers to the last item in the recycle.
After such a "transfer", since this is the end of the recycle, the second portion is immediately loaded, but after the second portion there are no such "transfers".

An example of my adapter and the adapter from the example:
https://pastebin.com/wByWJY2t

If you run the code from the example, it behaves like this on the first run:
5fad2828ded5c145744084.png

Everything is correct and there are no scrolls to the bottom after the first portion of data.

If you run my top code on the first run, we get the following result:
5fad288a25f9d825221989.png

As you can see, for some reason the sequence goes in reverse order.
Since the zero element will be at the very bottom, the position of the recycle is also at the bottom ... I did

all sorts of bad manipulations with DiffUtils and this influenced the behavior of the recycle.
But I didn't manage to get the application to work properly...

Briefly how it works:

1. When the application is launched for the first time, a repository is created.
2. Activity starts the whole pagination process.
3. The repository must give the data.
3.1. He looks into the local database - it's empty
3.2. Sends a request to the server and receives data
3.3. Writes data to a local database
3.4. Data from the database goes to List pagination and is displayed on the screen.

Further, at the second launch, the situation is similar:
1. When the application is launched, a repository is created.
2. Activity starts the whole pagination process.
3. The repository must give the data.
3.1. He looks into the local database - there is data
3.2. The data from the database is paginated and goes to the pagination List and displayed on the screen as you scroll.
3.3. When the data in the database runs out - a request to the server for a new portion
3.4. Writes the received data to the local database
3.5. Data from the database goes to List pagination and is displayed on the screen.

etc.

Help advice. How to overcome this disease.
I can't find any fundamental differences between the example code and mine..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas Unknown, 2020-11-12
@OMGcoder

The decision turned out to be rather stupid.
Diffutils worked correctly.
After reading a ton of literature came to this: This
5fad7cfeba441681377879.png
helped:
https://issuetracker.google.com/issues/123834703

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question