Skip to content

Light weight Downloading library which manages its own Memory cache.

Notifications You must be signed in to change notification settings

ImMathanR/Stocker

Repository files navigation

Stocker

stocker-image

Light weight Downloading library which manages its own Memory cache.

Stocker instance

val stocker = Stocker.Builder(applicationContext)
                .build()

Download request

stocker.fetch(ASSET_URL_AS_STRING) {(body, status, error) ->    
  if(status) {
    // Url downloaded
  }
}

To cancel the request

// Stocker fetch will return a Request object. Just pass it onto the Stocker.cancel() method. 
val request = stocker.fetch(ASSET_URL_AS_STRING) {(body, status, error) ->    
  if(status) {
    // Url downloaded
  }
}
stocker.cancel(request) // To cancel the request

Supports Image Binding

Stocker.bind(IMAGE_URL_AS_STRING, imageView)

It will download and render the image asset on the ImageView

Usage

To use Stocker Library goto the Release page and download the aar.

Stocker Advantage

Stocker manages Memory caching by default with the best fit Memory size for your device. If you want to change it you can do it the following way

val stocker = Stocker.Builder(applicationContext)
                .cacheSettings(object: CacheSettings {
                    override fun getCacheStrategy(): CacheStrategy {
                        return CacheStrategy.MEM_CACHE
                    }

                    override fun getMemCacheSize(): Int {
                        return 10 * 1024 // 10MB
                    }
                })
                .build()

No Cache

Stocker can also be configured without any caching

val stocker = Stocker.Builder(applicationContext)
                .cacheSettings(object: CacheSettings {
                    override fun getCacheStrategy(): CacheStrategy {
                        return CacheStrategy.NO_CACHE
                    }
                })
                .build()

TODO

  • Unit Testing
  • Optimizing Image binding
  • Publish to Gradle

Important

You can also read about the Design decisions about the Sample app and Library inside the relevant folders README.