Git Product home page Git Product logo

downzlibrary's Introduction

DownZ

| View release history

DownZ is an HTTP library that boosts networking in Android apps and makes it significantly easier and faster.

downz logo

DownZ offers the following benefits:

  • Handles HTTP requests.
  • Transparent memory response caching of JSON and Images with support for request prioritization.
  • Cancel a request of image upload or download at any given time.
  • Images in memory cache are auto removed if not used for a long time.
  • Ease of customization, for example, cancel request and clear cache.
  • Strong requisition that makes it easy to effectively manage UI with data being fetched asynchronously from the network.

DownZ excels at handling HTTP requests.It comes with built-in support for images, JSON and Xml. By providing built-in support for the features you require, DownZ frees you from writing tons of code and finally allows you to concentrate on the logic that is specific to your app.


Download

You can use Gradle

Step 1. Add the JitPack repository to your build file , Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

dependencies {
        compile 'com.github.100rabhkr:DownZLibrary:1.1'
}

Or Maven:

Step 1. Add the JitPack repository to your build file

<repositories>
	<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
	</repository>
</repositories>

Step 2. Add the dependency

<dependency>
    <groupId>com.github.100rabhkr</groupId>
    <artifactId>DownZLibrary</artifactId>
    <version>1.1</version>
</dependency>

Or Sbt:

Step 1. Add the JitPack repository to your build file Add it in your build.sbt at the end of resolvers:

	resolvers += "jitpack" at "https://jitpack.io"

Step 2. Add the dependency

	libraryDependencies += "com.github.100rabhkr" % "DownZLibrary" % "1.1"

Snapshots from Sample App


Download Sample App

All the source code can be downloaded from Github's Release page

You can also download the sample app from here

How do I use DownZ?

Make Standard Request

…
 DownZ
            .from(mContext) //context 
            .load(DownZ.Method.GET, “http://yoururl.com”)
            .asBitmap() 	//asJsonArray() or asJsonObject() or asXml() can be used depending on need
            .setCallback(new HttpListener<Bitmap>() {
                @Override
                public void onRequest() {

                    //On Beginning of request

                }

                @Override
                public void onResponse(Bitmap data) {

                    if(data != null){

                        // do something

                    }
                }

                @Override
                public void onError() {

                    //do something when there is an error

                }

                @Override
                public void onCancel() {

                    //do something when request cancelled

                }
            });

Pass Header or Request Parameters (Optional)

    ...
DownZ
            .from(MainActivity.this)
            .load(DownZ.Method.GET,mUrl)
            .setHeaderParameter("key","value")
            .setRequestParameter("key1","value1")
            .setRequestParameter("key2","value2")
            .asBitmap()
            .setCallback(new HttpListener<Bitmap>() {
                @Override
                public void onRequest() {

                }

                @Override
                public void onResponse(Bitmap bitmap) {
                    if(bitmap != null){

                        //do something
                    }
                }

                @Override
                public void onError() {

                }

                @Override
                public void onCancel() {

                }
            });

Enable Cache

...
public class SomeActivity extends AppCompatActivity {
    ...
    CacheManager<JSONArray> cacheManager; // we can use JSONObject, Bitmap as generic type
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        cacheManager=new CacheManager<>(40*1024*1024); // 40mb
    }

public void OnRequestMade(View v){
        DownZ
            .from(this)
            .load(DownZ.Method.GET, "http://www.url.com")
            .asJsonArray()
            .setCacheManager(cacheManager)
            .setCallback(new HttpListener<JSONArray>() {
                @Override
                public void onRequest() {
                    //fired when request begins
                }

                @Override
                public void onResponse(JSONArray data) {
                    if(data!=null){
                        // do some stuff here
                    }
                }

                @Override
                public void onError() {

                }

                @Override
                public void onCancel() {

                }
            });
}
}

Load Image into ImageView

...
public class SomeActivity extends AppCompatActivity {
    ...
    CacheManager<Bitmap> cacheManager; 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        cacheManager=new CacheManager<>(40*1024*1024); // 40mb
        imageview = (ImageView) findViewById(R.id.image_profile);
        imageview.setDrawingCacheEnabled(true); //can be used if Image has to be shared afterwards
        imageview.buildDrawingCache();
        ...
        
    }
//event to make request
public void btnLoadImageClicked(View v){
    DownZ
            .from(this)
            .load(DownZ.Method.GET, "http://www.url.com/image.jpg")
            .asBitmap()
            .setCacheManager(cacheManager)
            .setCallback(new HttpListener<Bitmap>() {
                @Override
                public void onRequest() {
                    //fired when request begin


 }

                @Override
                public void onResponse(Bitmap data) {
                    if(data!=null){
                        // do some stuff here
                        imageview.setImageBitmap(data);
                    }
                }

                @Override
                public void onError() {

                }

                @Override
                public void onCancel() {

                }
            });
}

}

Removing from Cache

 ...
 public class SomeActivity extends AppCompatActivity {
    ...
    CacheManager<Bitmap> cacheManager; 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        String mUrl = "http://yoururl.com/image.png";
        cacheManager=new CacheManager<>(40*1024*1024); // 40mb
        imageview = (ImageView) findViewById(R.id.image_profile);
        imageview.setDrawingCacheEnabled(true); //can be used if Image has to be shared afterwards
        imageview.buildDrawingCache();
        ...
        
    }
//event to clear item from cache
public void btntoClearCache(View v){

       cacheManager.removeDataFromCache(mUrl);
}
}

Getting Help

To report a specific problem or feature request in DownZ, you can open a new issue on Github. For questions, suggestions, or even to say 'hi', just drop an email at [email protected]

Contributing

If you like DownZ, please contribute by writing at [email protected]. Your help and support would make DownZ even better. Before submitting pull requests, contributors must sign Google's individual contributor license agreement.

Author

Saurabh Kumar - @100rabhkr on GitHub, @NotSaurabhKumar on Twitter

License

MIT See the LICENSE file for details.

Disclaimer

This is not an official Google product.

downzlibrary's People

Contributors

100rabhkr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

downzlibrary's Issues

How to know why request didn't work?

It would be really helpful if you could give some error code to specify why the request did not succeed.

@Override
onError(ErrorCode internalCode, StatusCode httpCode) { // at least one or a string
  
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.