https://github.com/txtasad/piczillamvvm
A simple MVVM Android app to fetch images from Flickr Api and use LiveData and LRU cache without using any external library.
https://github.com/txtasad/piczillamvvm
android cache-storage flickr-api livedata-viewmodel lru-cache mvvm mvvm-android mvvm-sample viewmodel
Last synced: 9 months ago
JSON representation
A simple MVVM Android app to fetch images from Flickr Api and use LiveData and LRU cache without using any external library.
- Host: GitHub
- URL: https://github.com/txtasad/piczillamvvm
- Owner: txtasad
- Created: 2020-05-16T01:04:22.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-16T01:11:40.000Z (about 6 years ago)
- Last Synced: 2025-03-30T18:43:46.485Z (over 1 year ago)
- Topics: android, cache-storage, flickr-api, livedata-viewmodel, lru-cache, mvvm, mvvm-android, mvvm-sample, viewmodel
- Language: Java
- Homepage:
- Size: 600 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PiczillaMVVM
A simple MVVM app to fetch images from Flickr Api and use LiveData and 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 MVVM (Model View ViewModel) 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=&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.
* viewmodel
* ImagesViewModel: ViewModel containing logic to fetch image urls and check cache if any bitmap is available else download bitmap from url.
* repository
* Package contains class for fetching data repository of images list(JSON) and image i.e 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.
* 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.