An async remote resource downloading library with sample pin board application using Android Jetpack written in Kotlin. ** Read the Wiki to know more about the project.**
- Android
- Kotlin
- Jetpack
- MVVM
- Repository Pattern
- LiveData
- Coroutine
- Retrofit
- Navigation Component
- Paging Library
- Android Data Binding
- Androidx Testing
- Mockito
- Download Bitmap
- Download Json and serialize to kotlin data object
- Abstraction for supporting future data types
- Cache Data in LruCache
- If data is present in the cache then return from cache otherwise fetch from remote service and add to cache
- Uses 1/8 of the total allocated memory for caching and evicts less frequent item when cache reaches its limit
- Local Unit Test with 100% test coverage
The root build.gradle
should look like
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
and in the app module build.gradle
add following
dependencies {
implementation 'com.github.Roaim:KotlinPinBoard:v2.5'
}
To download bitmap image :
fun downloadAndDisplayBitmap(lifecycleOwner: LifecycleOwner, imageView: ImageView?, url : String) {
val bitmapPinDownloader = BitmapPinDownloader()
bitmapPinDownloader.download(url).observe(lifecycleOwner, Observer {
imageView?.setImageBitmap(it)
})
}
To download json :
fun downloadJson(lifecycleOwner: LifecycleOwner, url: String) {
JsonPinDownloader().download(url)
.observe(lifecycleOwner, Observer { jsonElement ->
// process jsonElement
...
// or convert it to pojo
val poJo = jsonElement?.toPoJo<Unit>(PojoModel::class.java)
...
})
}
- Uses PinDownloader library module to load json and bitmap files
- Display images in Gallery by RecyclerView and PagedListAdapter
- Load more data when scrolling to the end of the list
- Upon clicking on an item navigate to full image screen with the help of Navigation Component
- Efficiently decoding Bitmap by following Official documentation
- Make
PinDownloader<T>
return a sealed class objectPin<T>
containingLoading
,Success
,Failure
data classes instead of returning justT
- Publish the library to Jitpack.io/Bintray
- LocalUnitTests, IntegrationTests and UITests