Skip to content

A sample app to show images from Flickr api using LRU cache and without using any external library.

Notifications You must be signed in to change notification settings

amanbindlish/Piczilla

Repository files navigation

Piczilla

A simple app to fetch images from Flickr Api and use LRU cache without using any external library.

App Screens

App features

  • App shows random images from Flickr Api.
  • App has single full screen imageView to show images.
  • App has two buttons (next & previous) to navigate through images.
  • App uses cache strategy which means if an image has been fetched from url then it will be stored and served from cache.
  • App follows MVP (Model View Presenter) pattern.
  • No external library used for networking or image caching.
  • HttpUrlConnection with AsyncTask used for api calling and LRU cache used for effective loading and caching.
  • App supports landscape and portrait modes.

Api used

Below Flickr api is used to fetch images urls: https://api.flickr.com/services/rest/?method=<photos_method>&api_key=<api_key>&format=json&nojsoncallback=1&safe_search=1&tags=kitten&per_page=10&page=1

where, photos_method = flickr.photos.search api_key = 3e7cc266ae2b0e0d78e279ce8e361736 Please register at https://www.flickr.com/services/api/ in case the given api key does not work.

Build image url from response object (farm, server, id, secret are present in response object)

https://farm${this.farm}.staticflickr.com/${this.server}/${this.id}_${this.secret}_q.jpg

App structure

App follows below structure:

  • model
    • Package contains POJO class for photo from api response.
  • presenter
    • Package contains presenter class for view and asyncTasks for fetching image urls and bitmaps.
    • DownloadImageTask: AsyncTask for downloading bitmap from given url. Also saves downloaded bitmap into cache.
    • FetchImageUrlsTask: AsyncTask for fetching images urls from Flickr api in chunks of 10 images per hit. Also parses json response.
    • ImagesPresenter: Presenter class containing logic to fetch image urls and check cache if any bitmap is available else download bitmap from url.
  • utils
    • Package contains utility class and generic cache class.
    • ImagesCache: Common LRU cache defined class. Any changes related to cache can be done here.
    • Utility: Utility class where HttpUrlConnection is defined for fetch images and download bitmaps.
  • view
    • Package contains UI classes which needs to be shown on app.
    • MainActivity: Single activity which contains a fragment.
    • MainFragment: Fragment class which contains ImageView and two buttons which will be shown to the user.