0

I'm facing the following problem:

I have a web service of a social network that allows to query a user uploaded videos. The web service signature is:

getUserVideos(String username, int quantity, int offset)

I need to create a gallery with the videos. So basically I request [quantity=10,offset=0] then [quantity=10,offset=10], using a ViewPger for the gallery.

At this point, with the gallery working (and in the position 15 for this example). We need to save the state if the user leaves the app, i.e. pressing the home button. Later, when the user return to the app after some hours, the getUserVideos service may return different data (i.e. if the given username has uploaded new videos in the meanwhile).

I see two different behaviors but find both wrong.

  • Save the list of videos when leaving the app and restore it when the user comes back, since there is new data in the server and the client data is old, the client offsets and the server offsets will not match, returning repeated videos or never returning others.
  • Requery to the server keeping the index in the gallery but updating the content (that is return to the video number 15). This will cause that the user returns to see a different video that the one he was seeing before leaving.

What are the common approaches for this kind of problems?

Addev
  • 31,819
  • 51
  • 183
  • 302
  • Both of your approach is good but you may cache that video alone and reload the new video if he clicks the video – Sheychan Sep 01 '15 at 07:03
  • do you have any id or unique identifier for videos you are getting from the webservice – Pramod Yadav Sep 01 '15 at 07:04
  • Yes, the videos have unique id, but I can't change the web service – Addev Sep 01 '15 at 07:34
  • I'd say stay on the same video when the user returns but give a visual indication that there is new content. Then you can load the new data with a button or pull to refresh. So if the user was on video 3 and there are 10 new videos, the user will be on video 13 (the same) when he returns. That's what I would do. – miva2 Sep 01 '15 at 09:05

1 Answers1

0

Cause you don't know user have video or not,you must request to server from zero.but when you get data check it with your fetched data and remove duplicate and insert new data to top of your adapter (i don't know if you have adapter or something else).

Mojtaba Asgari
  • 1,242
  • 1
  • 13
  • 24