P
P
penexe2015-12-09 14:52:31
Android
penexe, 2015-12-09 14:52:31

RecycleView endless and swipe to refresh in terms of database and remote api?

I am new to android development, please help me understand how the algorithm should work when loading data from api and storing the latest data in the database.
I am writing an application - a news feed for my website. The scheme of work should be the same as in VK.
Porridge in the head does not pass.
1) Let's say the application has already been launched once and received a list of the last 10 news.
2) When you re-enter (after killing the activity), you need to load new news and add it to the old ones.
Do I understand correctly that in this case it is necessary to execute an api request with the condition where timestamp > last_insert_timestamp ?
It may turn out that there will be a lot of data for a month of downtime, then I can return the answer too much news in api, and in the application I clear the table in the database, and I take only the last 10 news from api. Am I thinking right?
3) After some time (application is running), I do with swipe to refresh. As I understand it, you need to do the same as in paragraph 2.
4) Now let's say we exited the application. And they went in again. There was no new news in api.
How many news should be loaded into the RecycleView from the database? all that have been uploaded before? or only 10, and then load as you scroll?
Under what events will it be necessary to clean the table in the database? after all, this way it can grow up to 1000 news, but let's say 30 maximum?
5) When scrolling, the loading condition should be where timestamp < last_viewed_timestampthose last shown on the screen and if such data is in the database, then show them first, and at the next scroll already take from the api?
6) Is it true that always for entities that are currently shown in different parts of the application, there must be data in the database, if any?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aol-nnov, 2015-12-09
@aol-nnov

I would start with usability.
for a swipe, that refresh must first be screwed to the beginning of the list. how are you going to do it with infinite scrolling?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question