dimanche 22 février 2015

Online/Offline Image Management Strategy

I am working on an app that will get data and images from the webservice and store it in device for offline usage. At the same time the application will have some data stored in sqlite db and some images as the default data.


Here is the flow of app:



  • When the application opens it will grab the data from Sqlite Db and image paths of images stored in device and display them.

  • Beside that if there is internet connection, data and images from webservice will be consumed and copied to the Sqlite DB(data) and to the device(images) to be later accessed offline


Here is the question:



What is the best strategy to do that (note that i want also to prevent images shown in gallery of the device. They will be able to be accesed only from the app)?




  • Should i store default images firstly in Assets Folder and copy them to the external directory on the first oppening. And for offline usage of the images from the webservice, download and save them to the same directory?

  • Should i store local images in drawables and downloaded images in external directory of the device?

  • Should i store all images in SqliteDb as binary data (which i dont prefer because of performance)


Also take in consideration that i want to store multiple images for different device sizes. So on the first opening i check the device from which drawable folder (xxhdpi, xhdpi, hdpi, mdpi) it takes the images like so:



DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
switch(metrics.densityDpi){
case DisplayMetrics.DENSITY_MEDIUM:
break;
case DisplayMetrics.DENSITY_HIGH:
break;
case DisplayMetrics.DENSITY_XHIGH:
break;
case DisplayMetrics.DENSITY_XXHIGH:
break;
}


store to what folder it goes on SharedPreferencesso when i download images from the service, it will go to the specific folder with specfic image sizes of webservice and grap them



What is the best and easy strategy to manage images in this case?



[note: I dont want to use google extension files as the data and images can be udated frequently]


Aucun commentaire:

Enregistrer un commentaire