0

I'm creating this app for Android and I need the app runs on offline environment. At some point the user will be online and sync his data with the server to download changes and it should still using the app after that when he will be offline. On situation is this: the user log in and the app check with Internet that the account really exists, if the account exist it will download user data like information and profile picture. The communication between the app and the server is created with Retrofit, so the server returns a JSON like this:

{
  "data":{
  "username": "John Doe",
  "avatar": {
    "original" : "http://url/to/picture.jpg",
    "p35x35" : "http://url/to/picture.jpg" }
   }
}

and I convert that JSON to Object and store it on a database. (Please don't worry if you see any mistake on the JSON, I wrote it myself). The situation is with the pictures, they come as Internet URL but I need to store it local, I can't save URL links on the database. I don't know which is the best way I should do that. I've consider many ways but I don't like them, I don't know if they're fine and I'm not sure which is the best way for this:

1 - Using Picasso for cache handling, I don't like this option because cache can be deleted and I believe Picasso is more oriented to online apps that maybe are offline sometimes but most of time are online.

2 - Download every picture to a local folder, rename it with his SHA1 or MD5 and set that name to the database as the "original" and "p35x35" fields.

3 - Store the pictures locally with the same path as they're on Internet, ex- "storage/emulated/.application/.images/url/to/picture.jpg"

Ramin
  • 78
  • 1
  • 10

2 Answers2

0

I think Picasso, Glide or similar libraries are the way to go. Of course, cache can be deleted (either manually by the user or by the system if running out of resources).

Alternatively, you can implement your own cache for it, leveraging the existing infrastructure and just implementing the minimal caching code logic. See this question for more information.

Xavier Rubio Jansana
  • 6,388
  • 1
  • 27
  • 50
0

You can use hash of pictures in json data to check with your local hash if the data is new/updated And for store the pictures it's pretty standard in most famous apps to use folder in your application local folder and specify a folder for each object and store path and hash in database and its pretty efficient for using Internet. Also for creating folder you can use category of your objects and set id for name of the file if there's a lot of files.

Alireza Sharifi
  • 1,127
  • 1
  • 9
  • 18
  • thanks, that's a nice idea, I'd choose to download the picture from remote and calculate the md5 of the url and save the file with that name, if picture changes url will change so the md5 will be different – Ramin Aug 17 '17 at 16:18